Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AnnotationFileLoaderTest.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. public function testLoadTraitWithClassConstant()
  30. {
  31. $this->reader->expects($this->never())->method('getClassAnnotation');
  32. $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooTrait.php');
  33. }
  34. /**
  35. * @expectedException \InvalidArgumentException
  36. * @expectedExceptionMessage Did you forgot to add the "<?php" start tag at the beginning of the file?
  37. */
  38. public function testLoadFileWithoutStartTag()
  39. {
  40. $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php');
  41. }
  42. public function testLoadVariadic()
  43. {
  44. $route = new Route(['path' => '/path/to/{id}']);
  45. $this->reader->expects($this->once())->method('getClassAnnotation');
  46. $this->reader->expects($this->once())->method('getMethodAnnotations')
  47. ->willReturn([$route]);
  48. $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php');
  49. }
  50. /**
  51. * @requires PHP 7.0
  52. */
  53. public function testLoadAnonymousClass()
  54. {
  55. $this->reader->expects($this->never())->method('getClassAnnotation');
  56. $this->reader->expects($this->never())->method('getMethodAnnotations');
  57. $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/AnonymousClassInTrait.php');
  58. }
  59. public function testLoadAbstractClass()
  60. {
  61. $this->reader->expects($this->never())->method('getClassAnnotation');
  62. $this->reader->expects($this->never())->method('getMethodAnnotations');
  63. $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/AbstractClass.php');
  64. }
  65. public function testSupports()
  66. {
  67. $fixture = __DIR__.'/../Fixtures/annotated.php';
  68. $this->assertTrue($this->loader->supports($fixture), '->supports() returns true if the resource is loadable');
  69. $this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
  70. $this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified');
  71. $this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified');
  72. }
  73. }