loaders = spl_autoload_functions(); if (!is_array($this->loaders)) { // spl_autoload_functions does not return empty array when no // autoloaders registered... $this->loaders = array(); } Zend_Loader_Autoloader::resetInstance(); $this->autoloader = Zend_Loader_Autoloader::getInstance(); $this->application = new Zend_Application('testing'); } public function tearDown() { // Restore original autoloaders $loaders = spl_autoload_functions(); foreach ($loaders as $loader) { spl_autoload_unregister($loader); } foreach ($this->loaders as $loader) { spl_autoload_register($loader); } } public function testConstructorShouldPopulateApplication() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $this->assertSame($this->application, $bootstrap->getApplication()); } public function testConstructorShouldPopulateOptionsFromApplicationObject() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $options = array( 'foo' => 'bar', 'bar' => 'baz', ); $this->application->setOptions($options); $bootstrap = new ZfAppBootstrap($this->application); $this->assertSame($options, $bootstrap->getOptions()); } public function testConstructorShouldAllowPassingAnotherBootstrapObject() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap1 = new ZfAppBootstrap($this->application); $bootstrap2 = new ZfAppBootstrap($bootstrap1); $this->assertSame($bootstrap1, $bootstrap2->getApplication()); } /** * @expectedException Zend_Application_Bootstrap_Exception */ public function testConstructorShouldRaiseExceptionForInvalidApplicationArgument() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap(new stdClass); } public function testSettingOptionsShouldProxyToInternalSetters() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $options = array( 'arbitrary' => 'foo', ); $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->setOptions($options); $this->assertEquals('foo', $bootstrap->getArbitrary()); } public function testPluginPathsOptionKeyShouldAddPrefixPathsToPluginLoader() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->setOptions(array( 'pluginPaths' => array( 'Foo' => 'foo/bar/path/', ), )); $loader = $bootstrap->getPluginLoader(); $paths = $loader->getPaths('Foo'); $this->assertTrue(is_array($paths)); } public function testResourcesOptionKeyShouldRegisterBootstrapPluginResources() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->setOptions(array( 'resources' => array( 'view' => array( 'basePath' => dirname(__FILE__) . '/../_files/views/scripts', ), ), )); $this->assertTrue($bootstrap->hasPluginResource('view')); } public function testHasOptionShouldReturnFalseWhenOptionUnavailable() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $this->assertFalse($bootstrap->hasOption('foo')); } public function testHasOptionShouldReturnTrueWhenOptionPresent() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->setOptions(array('foo' => 'bar')); $this->assertTrue($bootstrap->hasOption('foo')); } public function testGetOptionShouldReturnNullWhenOptionUnavailable() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $this->assertNull($bootstrap->getOption('foo')); } public function testGetOptionShouldReturnOptionValue() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->setOptions(array('foo' => 'bar')); $this->assertEquals('bar', $bootstrap->getOption('foo')); } public function testInternalIntializersShouldBeRegisteredAsClassResources() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $test = $bootstrap->getClassResources(); $resources = array('foo' => '_initFoo', 'bar' => '_initBar', 'barbaz' => '_initBarbaz'); $this->assertEquals($resources, $test); } public function testInternalInitializersShouldRegisterResourceNames() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $test = $bootstrap->getClassResourceNames(); $resources = array('foo', 'bar', 'barbaz'); $this->assertEquals($resources, $test); } /** * @expectedException Zend_Application_Bootstrap_Exception */ public function testRegisterPluginResourceShouldThrowExceptionForInvalidResourceType() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->registerPluginResource(array()); } public function testShouldAllowRegisteringConcretePluginResources() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $resource = new Zend_Application_Resource_View(); $bootstrap->registerPluginResource($resource); $test = $bootstrap->getPluginResource('view'); $this->assertSame($resource, $test); } public function testRegisteringSecondPluginResourceOfSameTypeShouldOverwrite() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $resource1 = new Zend_Application_Resource_View(); $resource2 = new Zend_Application_Resource_View(); $bootstrap->registerPluginResource($resource1) ->registerPluginResource($resource2); $test = $bootstrap->getPluginResource('view'); $this->assertSame($resource2, $test); } public function testShouldAllowRegisteringPluginResourceUsingNameOnly() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->registerPluginResource('view'); $test = $bootstrap->getPluginResource('view'); $this->assertEquals('Zend_Application_Resource_View', get_class($test)); } public function testShouldAllowUnregisteringPluginResourcesUsingConcreteInstance() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $resource = new Zend_Application_Resource_View(); $bootstrap->registerPluginResource($resource); $bootstrap->unregisterPluginResource($resource); $this->assertFalse($bootstrap->hasPluginResource('view')); } /** * @expectedException Zend_Application_Bootstrap_Exception */ public function testAttemptingToUnregisterPluginResourcesUsingInvalidResourceTypeShouldThrowException() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->registerPluginResource('view'); $bootstrap->unregisterPluginResource(array()); } public function testShouldAllowUnregisteringPluginResourcesByName() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->registerPluginResource('view'); $bootstrap->unregisterPluginResource('view'); $this->assertFalse($bootstrap->hasPluginResource('view')); } public function testRetrievingNonExistentPluginResourceShouldReturnNull() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $this->assertNull($bootstrap->getPluginResource('view')); } public function testRetrievingPluginResourcesShouldRetrieveConcreteInstances() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->registerPluginResource('view'); $test = $bootstrap->getPluginResources(); foreach ($test as $type => $resource) { $this->assertTrue($resource instanceof Zend_Application_Resource_Resource); } } public function testShouldAllowRetrievingOnlyPluginResourceNames() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->registerPluginResource('view'); $test = $bootstrap->getPluginResourceNames(); $this->assertEquals(array('view'), $test); } public function testShouldAllowSettingAlternativePluginLoaderInstance() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $loader = new Zend_Loader_PluginLoader(); $bootstrap->setPluginLoader($loader); $this->assertSame($loader, $bootstrap->getPluginLoader()); } public function testDefaultPluginLoaderShouldRegisterPrefixPathForResources() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $loader = $bootstrap->getPluginLoader(); $paths = $loader->getPaths('Zend_Application_Resource'); $this->assertFalse(empty($paths)); } public function testEnvironmentShouldMatchApplicationEnvironment() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $this->assertSame($this->application->getEnvironment(), $bootstrap->getEnvironment()); } public function testBootstrappingShouldOnlyExecuteEachInitializerOnce() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->bootstrap('foo'); $bootstrap->bootstrap('foo'); $this->assertEquals(1, $bootstrap->fooExecuted); } public function testBootstrappingShouldFavorInternalResourcesOverPlugins() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources'); $bootstrap->bootstrap('foo'); $this->assertFalse($bootstrap->executedFooResource); } public function testBootstrappingShouldAllowPassingAnArrayOfResources() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->bootstrap(array('foo', 'bar')); $this->assertEquals(1, $bootstrap->fooExecuted); $this->assertEquals(1, $bootstrap->barExecuted); } public function testPassingNoValuesToBootstrapExecutesAllResources() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources'); $bootstrap->registerPluginResource('foobar'); $bootstrap->bootstrap(); $this->assertEquals(1, $bootstrap->fooExecuted); $this->assertEquals(1, $bootstrap->barExecuted); $this->assertTrue($bootstrap->executedFoobarResource); } /** * @expectedException Zend_Application_Bootstrap_Exception */ public function testPassingInvalidResourceArgumentToBootstrapShouldThrowException() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->bootstrap(new stdClass); } /** * @expectedException Zend_Application_Bootstrap_Exception */ public function testPassingUnknownResourceToBootstrapShouldThrowException() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->bootstrap('bazbat'); } public function testCallShouldOverloadToBootstrap() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->bootstrapFoo(); $this->assertEquals(1, $bootstrap->fooExecuted); } /** * @expectedException Zend_Application_Bootstrap_Exception */ public function testCallShouldThrowExceptionForInvalidMethodCall() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->initFoo(); } /** * @expectedException Zend_Application_Bootstrap_Exception */ public function testDependencyTrackingShouldDetectCircularDependencies() { require_once dirname(__FILE__) . '/../_files/BootstrapBaseCircularDependency.php'; $bootstrap = new BootstrapBaseCircularDependency($this->application); $bootstrap->bootstrap(); } public function testContainerShouldBeRegistryInstanceByDefault() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $container = $bootstrap->getContainer(); $this->assertTrue($container instanceof Zend_Registry); } public function testContainerShouldAggregateReturnValuesFromClassResources() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->bootstrap('barbaz'); $container = $bootstrap->getContainer(); $this->assertEquals('Baz', $container->barbaz->baz); } public function testContainerShouldAggregateReturnValuesFromPluginResources() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources'); $bootstrap->registerPluginResource('baz'); $bootstrap->bootstrap('baz'); $container = $bootstrap->getContainer(); $this->assertEquals('Baz', $container->baz->baz); } public function testClassResourcesShouldBeAvailableFollowingBootstrapping() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->bootstrap('barbaz'); $this->assertTrue($bootstrap->hasResource('barbaz')); $resource = $bootstrap->getResource('barbaz'); $this->assertEquals('Baz', $resource->baz); } public function testPluginResourcesShouldBeAvailableFollowingBootstrapping() { require_once dirname(__FILE__) . '/../_files/ZfAppBootstrap.php'; $bootstrap = new ZfAppBootstrap($this->application); $bootstrap->getPluginLoader()->addPrefixPath('Zend_Application_BootstrapTest_Resource', dirname(__FILE__) . '/../_files/resources'); $bootstrap->registerPluginResource('baz'); $bootstrap->bootstrap('baz'); $this->assertTrue($bootstrap->hasResource('baz')); $resource = $bootstrap->getResource('baz'); $this->assertEquals('Baz', $resource->baz); } } if (PHPUnit_MAIN_METHOD == 'Zend_Application_Bootstrap_BootstrapAbstractTest::main') { Zend_Application_Bootstrap_BootstrapAbstractTest::main(); }