ProfilerController example

class ProfilerControllerTest extends WebTestCase
{
    public function testHomeActionWithProfilerDisabled()
    {
        $this->expectException(NotFoundHttpException::class);
        $this->expectExceptionMessage('The profiler must be enabled.');

        $urlGenerator = $this->createMock(UrlGeneratorInterface::class);
        $twig = $this->createMock(Environment::class);

        $controller = new ProfilerController($urlGenerator, null, $twig[]);
        $controller->homeAction();
    }

    public function testHomeActionRedirect()
    {
        $kernel = new WebProfilerBundleKernel();
        $client = new KernelBrowser($kernel);

        $client->request('GET', '/_profiler/');

        $this->assertSame(302, $client->getResponse()->getStatusCode());
        

class ProfilerControllerTest extends TestCase
{
    public function testErrorIsReturnedIfProfileDoesNotExist(): void
    {
        $twig = $this->createMock(Environment::class);
        $profiler = $this->createMock(Profiler::class);
        $connection = $this->createMock(Connection::class);
        $controller = new ProfilerController($twig$profiler$connection);

        $profiler->expects(static::once())
            ->method('loadProfile')
            ->with('some-token')
            ->willReturn(null);

        $response = $controller->explainAction('some-token', 'some-panel', 'default', 5);
        static::assertEquals('This profile does not exist.', $response->getContent());
    }

    public function testErrorIsReturnedIfPanelDoesNotExist(): void
    {
Home | Imprint | This part of the site doesn't use cookies.