AnnotationFileLoaderTest.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Routing\Tests\Loader;
  11. use Symfony\Component\Config\FileLocator;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Routing\Loader\AnnotationFileLoader;
  14. class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
  15. {
  16. protected $loader;
  17. protected $reader;
  18. protected function setUp()
  19. {
  20. parent::setUp();
  21. $this->reader = $this->getReader();
  22. $this->loader = new AnnotationFileLoader(new FileLocator(), $this->getClassLoader($this->reader));
  23. }
  24. public function testLoad()
  25. {
  26. $this->reader->expects($this->once())->method('getClassAnnotation');
  27. $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
  28. }
  29. /**
  30. * @requires PHP 5.4
  31. */
  32. public function testLoadTraitWithClassConstant()
  33. {
  34. $this->reader->expects($this->never())->method('getClassAnnotation');
  35. $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooTrait.php');
  36. }
  37. /**
  38. * @requires PHP 5.6
  39. */
  40. public function testLoadVariadic()
  41. {
  42. $route = new Route(array('path' => '/path/to/{id}'));
  43. $this->reader->expects($this->once())->method('getClassAnnotation');
  44. $this->reader->expects($this->once())->method('getMethodAnnotations')
  45. ->will($this->returnValue(array($route)));
  46. $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php');
  47. }
  48. /**
  49. * @requires PHP 7.0
  50. */
  51. public function testLoadAnonymousClass()
  52. {
  53. $this->reader->expects($this->never())->method('getClassAnnotation');
  54. $this->reader->expects($this->never())->method('getMethodAnnotations');
  55. $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/AnonymousClassInTrait.php');
  56. }
  57. public function testSupports()
  58. {
  59. $fixture = __DIR__.'/../Fixtures/annotated.php';
  60. $this->assertTrue($this->loader->supports($fixture), '->supports() returns true if the resource is loadable');
  61. $this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
  62. $this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified');
  63. $this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified');
  64. }
  65. }