base_init_test.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one
  5. * or more contributor license agreements. See the NOTICE file
  6. * distributed with this work for additional information
  7. * regarding copyright ownership. The ASF licenses this file
  8. * to you under the Apache License, Version 2.0 (the
  9. * "License"); you may not use this file except in compliance
  10. * with the License. You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing,
  15. * software distributed under the License is distributed on an
  16. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. * KIND, either express or implied. See the License for the
  18. * specific language governing permissions and limitations
  19. * under the License.
  20. *
  21. * @package Base
  22. * @subpackage Tests
  23. * @version //autogentag//
  24. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  25. */
  26. require_once 'init/base_init_callback.php';
  27. require_once 'init/base_init_class.php';
  28. /**
  29. * @package Base
  30. * @subpackage Tests
  31. */
  32. class ezcBaseInitTest extends ezcTestCase
  33. {
  34. public function setUp()
  35. {
  36. testBaseInitClass::$instance = null;
  37. }
  38. public function testCallbackWithClassThatDoesNotExists()
  39. {
  40. try
  41. {
  42. ezcBaseInit::setCallback( 'testBaseInit', 'classDoesNotExist' );
  43. $this->fail( "Expected exception not thrown." );
  44. }
  45. catch ( ezcBaseInitInvalidCallbackClassException $e )
  46. {
  47. $this->assertEquals( "Class 'classDoesNotExist' does not exist, or does not implement the 'ezcBaseConfigurationInitializer' interface.", $e->getMessage() );
  48. }
  49. }
  50. public function testCallbackWithClassThatDoesNotImplementTheInterface()
  51. {
  52. try
  53. {
  54. ezcBaseInit::setCallback( 'testBaseInit', 'ezcBaseFeatures' );
  55. $this->fail( "Expected exception not thrown." );
  56. }
  57. catch ( ezcBaseInitInvalidCallbackClassException $e )
  58. {
  59. $this->assertEquals( "Class 'ezcBaseFeatures' does not exist, or does not implement the 'ezcBaseConfigurationInitializer' interface.", $e->getMessage() );
  60. }
  61. }
  62. public function testCallback1()
  63. {
  64. $obj = testBaseInitClass::getInstance();
  65. $this->assertEquals( false, $obj->configured );
  66. }
  67. public function testCallback2()
  68. {
  69. ezcBaseInit::setCallback( 'testBaseInit', 'testBaseInitCallback' );
  70. $obj = testBaseInitClass::getInstance();
  71. $this->assertEquals( true, $obj->configured );
  72. }
  73. public function testCallback3()
  74. {
  75. try
  76. {
  77. ezcBaseInit::setCallback( 'testBaseInit', 'testBaseInitCallback' );
  78. $this->fail( "Expected exception not thrown." );
  79. }
  80. catch ( ezcBaseInitCallbackConfiguredException $e )
  81. {
  82. $this->assertEquals( "The 'testBaseInit' is already configured with callback class 'testBaseInitCallback'.", $e->getMessage() );
  83. }
  84. }
  85. public static function suite()
  86. {
  87. return new PHPUnit_Framework_TestSuite("ezcBaseInitTest");
  88. }
  89. }
  90. ?>