Repository: symfony/symfony
File: src/Symfony/Component/HttpKernel/Tests/EventListener/CacheAttributeListenerTest.php (PHP)

Code before:
            true,
            true,
        ];

        yield 'closure' => [
            static function (array $arguments, Request $request) {
                return $arguments['test']->getDate() <= new \DateTimeImmutable();
            },
            static function (array $arguments, Request $request) {
                return $arguments['test']->getDate() > new \DateTimeImmutable();
            },
            true,
            true,
            false,
            false,
        ];
    }

    public function testErrorIsThrownWhenIfEvaluatesToNonBool()
    {
        $entity = new TestEntity();

        $request = $this->createRequest(
            new Cache(smaxage: '1 days', public: true, if: static function (array $arguments, Request $request) {
                return 'foo';
            }),
        );

        $listener = new CacheAttributeListener();
        $controllerArgumentsEvent = new ControllerArgumentsEvent($this->getKernel(), static fn (TestEntity $test) => new Response(), [$entity], $request, null);

        $this->expectException(\TypeError::class);
        $this->expectExceptionMessage(\sprintf('The value of the "$if" option of the "%s" attribute must evaluate to a boolean, "string" given.', Cache::class));

        $listener->onKernelControllerArguments($controllerArgumentsEvent);
    }

    private function createRequest(Cache ...$cache): Request
    {
        return new Request([], [], ['_cache' => $cache]);
    }

    private function createEventMock(Request $request, Response $response): ResponseEvent
    {
        return new ResponseEvent($this->getKernel(), $request, HttpKernelInterface::MAIN_REQUEST, $response);
    }

    private function getKernel(): Stub&HttpKernelInterface
    {
        return $this->createStub(HttpKernelInterface::class);
    }

Review comment (performance):
```suggestion
            new Cache(smaxage: '1 days', public: true, if: static function ($arguments, $request) => 'foo'),
```

Code after:
            true,
            true,
        ];

        yield 'closure' => [
            static fn (array $arguments, Request $request) => $arguments['test']->getDate() <= new \DateTimeImmutable(),
            static fn (array $arguments, Request $request) => $arguments['test']->getDate() > new \DateTimeImmutable(),
            true,
            true,
            false,
            false,
        ];
    }

    public function testErrorIsThrownWhenIfEvaluatesToNonBool()
    {
        $entity = new TestEntity();

        $request = $this->createRequest(
            new Cache(smaxage: '1 days', public: true, if: static fn (array $arguments, Request $request) => 'foo'),
        );

        $listener = new CacheAttributeListener();
        $controllerArgumentsEvent = new ControllerArgumentsEvent($this->getKernel(), static fn (TestEntity $test) => new Response(), [$entity], $request, null);

        $this->expectException(\TypeError::class);
        $this->expectExceptionMessage(\sprintf('The value of the "$if" option of the "%s" attribute must evaluate to a boolean, "string" given.', Cache::class));

        $listener->onKernelControllerArguments($controllerArgumentsEvent);
    }

    private function createRequest(Cache ...$cache): Request
    {
        return new Request([], [], ['_cache' => $cache]);
    }

    private function createEventMock(Request $request, Response $response): ResponseEvent
    {
        return new ResponseEvent($this->getKernel(), $request, HttpKernelInterface::MAIN_REQUEST, $response);
    }

    private function getKernel(): Stub&HttpKernelInterface
    {
        return $this->createStub(HttpKernelInterface::class);
    }
}

class TestEntity
{
    public function getDate()
    {