AnnotationFileLoaderTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. * @expectedException \InvalidArgumentException
  39. * @expectedExceptionMessage Did you forgot to add the "<?php" start tag at the beginning of the file?
  40. */
  41. public function testLoadFileWithoutStartTag()
  42. {
  43. $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php');
  44. }
  45. /**
  46. * @requires PHP 5.6
  47. */
  48. public function testLoadVariadic()
  49. {
  50. $route = new Route(array('path' => '/path/to/{id}'));
  51. $this->reader->expects($this->once())->method('getClassAnnotation');
  52. $this->reader->expects($this->once())->method('getMethodAnnotations')
  53. ->will($this->returnValue(array($route)));
  54. $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php');
  55. }
  56. public function testSupports()
  57. {
  58. $fixture = __DIR__.'/../Fixtures/annotated.php';
  59. $this->assertTrue($this->loader->supports($fixture), '->supports() returns true if the resource is loadable');
  60. $this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
  61. $this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified');
  62. $this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified');
  63. }
  64. }