TemplateManager example


        parent::setUp();

        $this->profiler = $this->createMock(Profiler::class);
        $twigEnvironment = $this->mockTwigEnvironment();
        $templates = [
            'data_collector.foo' => ['foo', '@Foo/Collector/foo.html.twig'],
            'data_collector.bar' => ['bar', '@Foo/Collector/bar.html.twig'],
            'data_collector.baz' => ['baz', '@Foo/Collector/baz.html.twig'],
        ];

        $this->templateManager = new TemplateManager($this->profiler, $twigEnvironment$templates);
    }

    public function testGetNameOfInvalidTemplate()
    {
        $this->expectException(NotFoundHttpException::class);
        $this->templateManager->getName(new Profile('token'), 'notexistingpanel');
    }

    /** * if template exists in both profile and profiler then its name should be returned. */
    


        return $this->renderWithCspNonces($request, '@WebProfiler/Profiler/open.html.twig', [
            'file_info' => new \SplFileInfo($filename),
            'file' => $file,
            'line' => $line,
        ]);
    }

    protected function getTemplateManager(): TemplateManager
    {
        return $this->templateManager ??= new TemplateManager($this->profiler, $this->twig, $this->templates);
    }

    private function denyAccessIfProfilerDisabled(): void
    {
        if (null === $this->profiler) {
            throw new NotFoundHttpException('The profiler must be enabled.');
        }

        $this->profiler->disable();
    }

    
Home | Imprint | This part of the site doesn't use cookies.