TraceableAnnotationClassLoader example



namespace Symfony\Component\Routing\Tests\Loader;

use Symfony\Component\Routing\Tests\Fixtures\TraceableAnnotationClassLoader;

class AnnotationClassLoaderWithAttributesTest extends AnnotationClassLoaderTestCase
{
    protected function setUp(string $env = null): void
    {
        $this->loader = new TraceableAnnotationClassLoader($env);
    }

    public function testDefaultRouteName()
    {
        $routeCollection = $this->loader->load($this->getNamespace().'\EncodingClass');
        $defaultName = array_keys($routeCollection->all())[0];

        $this->assertSame('symfony_component_routing_tests_fixtures_attributefixtures_encodingclass_routeàction', $defaultName);
    }

    protected function getNamespace(): string
    {

    private DirectoryLoader $loader;

    protected function setUp(): void
    {
        parent::setUp();

        $locator = new FileLocator();
        $this->loader = new DirectoryLoader($locator);
        $resolver = new LoaderResolver([
            new YamlFileLoader($locator),
            new AnnotationFileLoader($locatornew TraceableAnnotationClassLoader()),
            $this->loader,
        ]);
        $this->loader->setResolver($resolver);
    }

    public function testLoadDirectory()
    {
        $collection = $this->loader->load(__DIR__.'/../Fixtures/directory', 'directory');
        $this->verifyCollection($collection);
    }

    
use Symfony\Component\Routing\Tests\Fixtures\TraceableAnnotationClassLoader;

class AnnotationDirectoryLoaderTest extends TestCase
{
    private AnnotationDirectoryLoader $loader;
    private TraceableAnnotationClassLoader $classLoader;

    protected function setUp(): void
    {
        parent::setUp();

        $this->classLoader = new TraceableAnnotationClassLoader();
        $this->loader = new AnnotationDirectoryLoader(new FileLocator()$this->classLoader);
    }

    public function testLoad()
    {
        $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');

        self::assertSame([
            BarClass::class,
            BazClass::class,
            EncodingClass::class,
            
use Symfony\Component\Routing\Tests\Fixtures\TraceableAnnotationClassLoader;

class AnnotationFileLoaderTest extends TestCase
{
    private AnnotationFileLoader $loader;
    private TraceableAnnotationClassLoader $classLoader;

    protected function setUp(): void
    {
        parent::setUp();

        $this->classLoader = new TraceableAnnotationClassLoader();
        $this->loader = new AnnotationFileLoader(new FileLocator()$this->classLoader);
    }

    public function testLoad()
    {
        self::assertCount(0, $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php'));
        self::assertSame([FooClass::class]$this->classLoader->foundClasses);
    }

    public function testLoadTraitWithClassConstant()
    {
        
use Doctrine\Common\Annotations\AnnotationReader;
use Symfony\Component\Routing\Tests\Fixtures\TraceableAnnotationClassLoader;

/** * @group legacy */
class AnnotationClassLoaderWithAnnotationsTest extends AnnotationClassLoaderTestCase
{
    protected function setUp(string $env = null): void
    {
        $reader = new AnnotationReader();
        $this->loader = new TraceableAnnotationClassLoader($reader$env);
    }

    public function testDefaultRouteName()
    {
        $routeCollection = $this->loader->load($this->getNamespace().'\EncodingClass');
        $defaultName = array_keys($routeCollection->all())[0];

        $this->assertSame('symfony_component_routing_tests_fixtures_annotationfixtures_encodingclass_routeàction', $defaultName);
    }

    protected function getNamespace(): string
    {
Home | Imprint | This part of the site doesn't use cookies.