AnnotationClassLoaderTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\Tests\Component\Routing\Loader;
  11. use Symfony\Component\Routing\Loader\AnnotationClassLoader;
  12. require_once __DIR__.'/../Fixtures/AnnotatedClasses/AbstractClass.php';
  13. require_once __DIR__.'/AbstractAnnotationLoaderTest.php';
  14. class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
  15. {
  16. protected $loader;
  17. public function setUp()
  18. {
  19. parent::setUp();
  20. $this->loader = $this->getClassLoader($this->getReader());
  21. }
  22. /**
  23. * @expectedException \InvalidArgumentException
  24. */
  25. public function testLoadMissingClass()
  26. {
  27. $this->loader->load('MissingClass');
  28. }
  29. /**
  30. * @expectedException \InvalidArgumentException
  31. */
  32. public function testLoadAbstractClass()
  33. {
  34. $this->loader->load('Symfony\Tests\Component\Routing\Fixtures\AnnotatedClasses\AbstractClass');
  35. }
  36. /**
  37. * @covers Symfony\Component\Routing\Loader\AnnotationClassLoader::supports
  38. * @dataProvider provideTestSupportsChecksResource
  39. */
  40. public function testSupportsChecksResource($resource, $expectedSupports)
  41. {
  42. $this->assertSame($expectedSupports, $this->loader->supports($resource), '->supports() returns true if the resource is loadable');
  43. }
  44. public function provideTestSupportsChecksResource()
  45. {
  46. return array(
  47. array('class', true),
  48. array('\fully\qualified\class\name', true),
  49. array('namespaced\class\without\leading\slash', true),
  50. array('ÿClassWithLegalSpecialCharacters', true),
  51. array('5', false),
  52. array('foo.foo', false),
  53. array(null, false),
  54. );
  55. }
  56. /**
  57. * @covers Symfony\Component\Routing\Loader\AnnotationClassLoader::supports
  58. */
  59. public function testSupportsChecksTypeIfSpecified()
  60. {
  61. $this->assertTrue($this->loader->supports('class', 'annotation'), '->supports() checks the resource type if specified');
  62. $this->assertFalse($this->loader->supports('class', 'foo'), '->supports() checks the resource type if specified');
  63. }
  64. }