setExpectedException('InvalidArgumentException'); $locator = new Zend_File_ClassFileLocator('__foo__'); } public function testConstructorThrowsInvalidArgumentExceptionForNonDirectoryIteratorArgument() { $iterator = new ArrayIterator(array()); $this->setExpectedException('InvalidArgumentException'); $locator = new Zend_File_ClassFileLocator($iterator); } public function testIterationShouldReturnOnlyPhpFiles() { if (version_compare(PHP_VERSION, '5.3', 'lt')) { $this->markTestSkipped('Test can only be run under 5.3 or later'); } $locator = new Zend_File_ClassFileLocator(dirname(__FILE__)); foreach ($locator as $file) { $this->assertRegexp('/\.php$/', $file->getFilename()); } } public function testIterationShouldReturnOnlyPhpFilesContainingClasses() { if (version_compare(PHP_VERSION, '5.3', 'lt')) { $this->markTestSkipped('Test can only be run under 5.3 or later'); } $locator = new Zend_File_ClassFileLocator(dirname(__FILE__)); $found = false; foreach ($locator as $file) { if (preg_match('/locator-should-skip-this\.php$/', $file->getFilename())) { $found = true; } } $this->assertFalse($found, "Found PHP file not containing a class?"); } public function testIterationShouldReturnInterfaces() { if (version_compare(PHP_VERSION, '5.3', 'lt')) { $this->markTestSkipped('Test can only be run under 5.3 or later'); } $locator = new Zend_File_ClassFileLocator(dirname(__FILE__)); $found = false; foreach ($locator as $file) { if (preg_match('/LocatorShouldFindThis\.php$/', $file->getFilename())) { $found = true; } } $this->assertTrue($found, "Locator skipped an interface?"); } public function testIterationShouldInjectNamespaceInFoundItems() { if (version_compare(PHP_VERSION, '5.3', 'lt')) { $this->markTestSkipped('Test can only be run under 5.3 or later'); } $locator = new Zend_File_ClassFileLocator(dirname(__FILE__)); $found = false; foreach ($locator as $file) { $classes = $file->getClasses(); foreach ($classes as $class) { if (strpos($class, '\\', 1)) { $found = true; } } } $this->assertTrue($found); } public function testIterationShouldInjectClassInFoundItems() { if (version_compare(PHP_VERSION, '5.3', 'lt')) { $this->markTestSkipped('Test can only be run under 5.3 or later'); } $locator = new Zend_File_ClassFileLocator(dirname(__FILE__)); $found = false; foreach ($locator as $file) { $classes = $file->getClasses(); foreach ($classes as $class) { $found = true; break; } } $this->assertTrue($found); } public function testIterationShouldFindMultipleClassesInMultipleNamespacesInSinglePhpFile() { if (version_compare(PHP_VERSION, '5.3', 'lt')) { $this->markTestSkipped('Test can only be run under 5.3 or later'); } $locator = new Zend_File_ClassFileLocator(dirname(__FILE__)); $foundFirst = false; $foundSecond = false; $foundThird = false; $foundFourth = false; foreach ($locator as $file) { if (preg_match('/MultipleClassesInMultipleNamespaces\.php$/', $file->getFilename())) { $classes = $file->getClasses(); foreach ($classes as $class) { if ($class === 'ZendTest\File\TestAsset\LocatorShouldFindFirstClass') { $foundFirst = true; } if ($class === 'ZendTest\File\TestAsset\LocatorShouldFindSecondClass') { $foundSecond = true; } if ($class === 'ZendTest\File\TestAsset\SecondTestNamespace\LocatorShouldFindThirdClass') { $foundThird = true; } if ($class === 'ZendTest\File\TestAsset\SecondTestNamespace\LocatorShouldFindFourthClass') { $foundFourth = true; } } } } $this->assertTrue($foundFirst); $this->assertTrue($foundSecond); $this->assertTrue($foundThird); $this->assertTrue($foundFourth); } } if (PHPUnit_MAIN_METHOD == 'Zend_File_ClassFileLocatorTest::main') { Zend_File_ClassFileLocatorTest::main(); }