AnnotationFileLoaderTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\Routing\Loader\AnnotationFileLoader;
  12. use Symfony\Component\Config\FileLocator;
  13. use Symfony\Component\Routing\Annotation\Route;
  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. public function testSupports()
  49. {
  50. $fixture = __DIR__.'/../Fixtures/annotated.php';
  51. $this->assertTrue($this->loader->supports($fixture), '->supports() returns true if the resource is loadable');
  52. $this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
  53. $this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified');
  54. $this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified');
  55. }
  56. }