ClassFileLocatorTest.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_File
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. if (!defined('PHPUnit_MAIN_METHOD')) {
  22. define('PHPUnit_MAIN_METHOD', 'Zend_File_ClassFileLocatorTest::main');
  23. }
  24. require_once 'Zend/File/ClassFileLocator.php';
  25. /**
  26. * Test class for Zend_File_ClassFileLocator
  27. *
  28. * @category Zend
  29. * @package Zend_File
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @group Zend_File
  34. */
  35. class Zend_File_ClassFileLocatorTest extends PHPUnit_Framework_TestCase
  36. {
  37. public function testConstructorThrowsInvalidArgumentExceptionForInvalidStringDirectory()
  38. {
  39. $this->setExpectedException('InvalidArgumentException');
  40. $locator = new Zend_File_ClassFileLocator('__foo__');
  41. }
  42. public function testConstructorThrowsInvalidArgumentExceptionForNonDirectoryIteratorArgument()
  43. {
  44. $iterator = new ArrayIterator(array());
  45. $this->setExpectedException('InvalidArgumentException');
  46. $locator = new Zend_File_ClassFileLocator($iterator);
  47. }
  48. public function testIterationShouldReturnOnlyPhpFiles()
  49. {
  50. $locator = new Zend_File_ClassFileLocator(dirname(__FILE__));
  51. foreach ($locator as $file) {
  52. $this->assertRegexp('/\.php$/', $file->getFilename());
  53. }
  54. }
  55. public function testIterationShouldReturnOnlyPhpFilesContainingClasses()
  56. {
  57. $locator = new Zend_File_ClassFileLocator(dirname(__FILE__));
  58. $found = false;
  59. foreach ($locator as $file) {
  60. if (preg_match('/locator-should-skip-this\.php$/', $file->getFilename())) {
  61. $found = true;
  62. }
  63. }
  64. $this->assertFalse($found, "Found PHP file not containing a class?");
  65. }
  66. public function testIterationShouldReturnInterfaces()
  67. {
  68. $locator = new Zend_File_ClassFileLocator(dirname(__FILE__));
  69. $found = false;
  70. foreach ($locator as $file) {
  71. if (preg_match('/LocatorShouldFindThis\.php$/', $file->getFilename())) {
  72. $found = true;
  73. }
  74. }
  75. $this->assertTrue($found, "Locator skipped an interface?");
  76. }
  77. public function testIterationShouldInjectClassInFoundItems()
  78. {
  79. $locator = new Zend_File_ClassFileLocator(dirname(__FILE__));
  80. $found = false;
  81. foreach ($locator as $file) {
  82. $this->assertTrue(isset($file->classname));
  83. }
  84. }
  85. }
  86. if (PHPUnit_MAIN_METHOD == 'Zend_File_ClassFileLocatorTest::main') {
  87. Zend_File_ClassFileLocatorTest::main();
  88. }