PhpParserTest.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Doctrine\Tests\Common\Annotations;
  3. use Doctrine\Common\Annotations\PhpParser;
  4. require_once __DIR__.'/AnnotationReaderTest.php';
  5. require_once __DIR__.'/Fixtures/NonNamespacedClass.php';
  6. class PhpParserTest extends \PHPUnit_Framework_TestCase
  7. {
  8. public function testParseClassWithMultipleClassesInFile()
  9. {
  10. $class = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\MultipleClassesInFile');
  11. $parser = new PhpParser();
  12. $this->assertEquals(array(
  13. 'route' => 'Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route',
  14. 'secure' => 'Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure',
  15. ), $parser->parseClass($class));
  16. }
  17. public function testParseClassWithMultipleImportsInUseStatement()
  18. {
  19. $class = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\MultipleImportsInUseStatement');
  20. $parser = new PhpParser();
  21. $this->assertEquals(array(
  22. 'route' => 'Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route',
  23. 'secure' => 'Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure',
  24. ), $parser->parseClass($class));
  25. }
  26. public function testParseClassWhenNotUserDefined()
  27. {
  28. $parser = new PhpParser();
  29. $this->assertEquals(array(), $parser->parseClass(new \ReflectionClass('\stdClass')));
  30. }
  31. public function testParseClassWhenClassIsNotNamespaced()
  32. {
  33. $parser = new PhpParser();
  34. $class = new \ReflectionClass('\AnnotationsTestsFixturesNonNamespacedClass');
  35. $this->assertEquals(array(
  36. 'route' => 'Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Route',
  37. 'template' => 'Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Template',
  38. ), $parser->parseClass($class));
  39. }
  40. public function testParseClassWhenClassIsInterface()
  41. {
  42. $parser = new PhpParser();
  43. $class = new \ReflectionClass('Doctrine\Tests\Common\Annotations\Fixtures\TestInterface');
  44. $this->assertEquals(array(
  45. 'secure' => 'Doctrine\Tests\Common\Annotations\Fixtures\Annotation\Secure',
  46. ), $parser->parseClass($class));
  47. }
  48. }