Skip to content

Commit

Permalink
Fixed test issues
Browse files Browse the repository at this point in the history
- Exceptions have moved to a new namespace
- Loaders must call register() to be active
  • Loading branch information
weierophinney committed Apr 28, 2011
1 parent 5bce137 commit bd0b77a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 33 deletions.
4 changes: 3 additions & 1 deletion library/Zend/Loader/ResourceAutoloader.php
Expand Up @@ -132,7 +132,9 @@ public function __call($method, $args)
public function getClassPath($class)
{
if (null !== $this->getNamespace()) {
return $this->getNamespacedClassPath($class);
if (false !== ($path = $this->getNamespacedClassPath($class))) {
return $path;
}
}
return $this->getPrefixedClassPath($class);
}
Expand Down
51 changes: 19 additions & 32 deletions tests/Zend/Loader/ResourceAutoloaderTest.php
Expand Up @@ -20,7 +20,9 @@
*/

namespace ZendTest\Loader;
use Zend\Loader\ResourceAutoloader;

use Zend\Loader\ResourceAutoloader,
Zend\Config\Config;

/**
* @category Zend
Expand Down Expand Up @@ -52,6 +54,7 @@ public function setUp()
'namespace' => 'FooBar',
'basePath' => realpath(__DIR__ . '/_files/ResourceAutoloader'),
));
$this->loader->register();
}

public function tearDown()
Expand All @@ -72,25 +75,25 @@ public function tearDown()

public function testAutoloaderInstantiationShouldRaiseExceptionWithoutNamespace()
{
$this->setExpectedException('\\Zend\\Loader\\InvalidArgumentException');
$this->setExpectedException('Zend\Loader\Exception\InvalidArgumentException');
$loader = new ResourceAutoloader(array('basePath' => __DIR__));
}

public function testAutoloaderInstantiationShouldRaiseExceptionWithoutBasePath()
{
$this->setExpectedException('\\Zend\\Loader\\InvalidArgumentException');
$this->setExpectedException('Zend\Loader\Exception\InvalidArgumentException');
$loader = new ResourceAutoloader(array('namespace' => 'Foo'));
}

public function testAutoloaderInstantiationShouldRaiseExceptionWhenInvalidOptionsTypeProvided()
{
$this->setExpectedException('\\Zend\\Loader\\InvalidArgumentException');
$this->setExpectedException('Zend\Loader\Exception\InvalidArgumentException');
$loader = new ResourceAutoloader('foo');
}

public function testAutoloaderConstructorShouldAcceptZendConfigObject()
{
$config = new \Zend_Config(array('namespace' => 'Foo', 'basePath' => __DIR__));
$config = new Config(array('namespace' => 'Foo', 'basePath' => __DIR__));
$loader = new ResourceAutoloader($config);
}

Expand All @@ -113,13 +116,13 @@ public function testNoResourceTypesShouldBeRegisteredByDefault()

public function testInitialResourceTypeDefinitionShouldRequireNamespace()
{
$this->setExpectedException('\\Zend\\Loader\\MissingResourceNamespaceException');
$this->setExpectedException('Zend\Loader\Exception\MissingResourceNamespaceException');
$this->loader->addResourceType('foo', 'foo');
}

public function testPassingNonStringPathWhenAddingResourceTypeShouldRaiseAnException()
{
$this->setExpectedException('\\Zend\\Loader\\InvalidPathException');
$this->setExpectedException('Zend\Loader\Exception\InvalidPathException');
$this->loader->addResourceType('foo', array('foo'), 'Foo');
}

Expand Down Expand Up @@ -178,13 +181,13 @@ public function testAutoloaderShouldSupportAddingMultipleResourceTypesAtOnceUsin

public function testAddingMultipleResourceTypesShouldRaiseExceptionWhenReceivingNonArrayItem()
{
$this->setExpectedException('\\Zend\\Loader\\InvalidArgumentException', 'expects an array');
$this->setExpectedException('Zend\Loader\Exception\InvalidArgumentException', 'expects an array');
$this->loader->addResourceTypes(array('foo' => 'bar'));
}

public function testAddingMultipleResourceTypesShouldRaiseExceptionWhenMissingResourcePath()
{
$this->setExpectedException('\\Zend\\Loader\\InvalidArgumentException', 'include a paths');
$this->setExpectedException('Zend\Loader\Exception\InvalidArgumentException', 'include a paths');
$this->loader->addResourceTypes(array('model' => array('namespace' => 'Model')));
}

Expand Down Expand Up @@ -250,13 +253,13 @@ public function testSettingDefaultResourceTypeToUndefinedTypeShouldHaveNoEffect(

public function testLoadShouldRaiseExceptionWhenNotTypePassedAndNoDefaultSpecified()
{
$this->setExpectedException('\\Zend\\Loader\\InvalidArgumentException', 'No resource type');
$this->setExpectedException('Zend\Loader\Exception\InvalidArgumentException', 'No resource type');
$this->loader->load('Foo');
}

public function testLoadShouldRaiseExceptionWhenResourceTypeDoesNotExist()
{
$this->setExpectedException('\\Zend\\Loader\\InvalidArgumentException', 'Invalid resource type');
$this->setExpectedException('Zend\Loader\Exception\InvalidArgumentException', 'Invalid resource type');
$this->loader->load('Foo', 'model');
}

Expand All @@ -278,6 +281,7 @@ public function testLoadShouldReturnObjectOfExpectedClassUsingPrefixes()
$loader->addResourceTypes(array(
'model' => array('path' => 'models', 'namespace' => 'Model'),
));
$loader->register();
$object = $loader->load('ZendLoaderAutoloaderResourcePrefixTest', 'model');
$this->assertTrue($object instanceof \FooBar_Model_ZendLoaderAutoloaderResourcePrefixTest);
}
Expand All @@ -302,6 +306,7 @@ public function testAutoloadShouldAllowEmptyNamespacing()
$loader->addResourceTypes(array(
'service' => array('path' => 'services', 'namespace' => 'Service'),
));
$loader->register();
$test = $loader->load('ZendLoaderAutoloaderResourceTest', 'service');
$this->assertTrue($test instanceof \Service\ZendLoaderAutoloaderResourceTest);
}
Expand Down Expand Up @@ -350,19 +355,19 @@ public function testPassingPrefixedClassWithUnmatchedResourceTypeToAutoloadShoul

public function testMethodOverloadingShouldRaiseExceptionForNonGetterMethodCalls()
{
$this->setExpectedException('\\Zend\\Loader\\BadMethodCallException');
$this->setExpectedException('Zend\Loader\Exception\BadMethodCallException');
$this->loader->lalalalala();
}

public function testMethodOverloadingShouldRaiseExceptionWhenRequestedResourceDoesNotExist()
{
$this->setExpectedException('\\Zend\\Loader\\InvalidArgumentException', 'Invalid resource');
$this->setExpectedException('Zend\Loader\Exception\InvalidArgumentException', 'Invalid resource');
$this->loader->getModel('Foo');
}

public function testMethodOverloadingShouldRaiseExceptionWhenNoArgumentPassed()
{
$this->setExpectedException('\\Zend\\Loader\\InvalidArgumentException', 'no resourc');
$this->setExpectedException('Zend\Loader\Exception\InvalidArgumentException', 'no resourc');
$this->loader->addResourceTypes(array(
'model' => array('path' => 'models', 'namespace' => 'Model'),
));
Expand All @@ -378,24 +383,6 @@ public function testMethodOverloadingShouldReturnObjectOfExpectedType()
$this->assertTrue($test instanceof \FooBar\Model\ZendLoaderAutoloaderResourceMethodOverloading);
}

/**
* @group ZF-7473
*/
public function testAutoloaderShouldReceiveNamespaceWithTrailingUnderscore()
{
$this->loader = new ResourceAutoloader(array(
'prefix' => 'FooBar',
'basePath' => realpath(__DIR__ . '/_files/ResourceAutoloader'),
));
$al = Autoloader::getInstance();
$loaders = $al->getPrefixAutoloaders('FooBar');
$this->assertTrue(empty($loaders));
$loaders = $al->getPrefixAutoloaders('FooBar_');
$this->assertFalse(empty($loaders));
$loader = array_shift($loaders);
$this->assertSame($this->loader, $loader);
}

/**
* @group ZF-7501
*/
Expand Down

0 comments on commit bd0b77a

Please sign in to comment.