diff --git a/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php b/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php index e06b9a056a727..a77f97ea002ac 100644 --- a/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php +++ b/src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php @@ -56,7 +56,7 @@ public function getKernel(): KernelInterface */ public function getProfile(): HttpProfile|false|null { - if (null === $this->response || !$this->getContainer()->has('profiler')) { + if (!isset($this->response) || !$this->getContainer()->has('profiler')) { return false; } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/KernelBrowserTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/KernelBrowserTest.php index 1e462f7d0a8f6..4e62b5ee7b6f4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/KernelBrowserTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/KernelBrowserTest.php @@ -14,6 +14,7 @@ use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Tests\Functional\AbstractWebTestCase; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\KernelInterface; class KernelBrowserTest extends AbstractWebTestCase { @@ -61,6 +62,13 @@ public function testRequestAfterKernelShutdownAndPerformedRequest() $client->request('GET', '/'); } + public function testGetProfileWithoutRequest() + { + $browser = new KernelBrowser($this->createMock(KernelInterface::class)); + + $this->assertFalse($browser->getProfile()); + } + private function getKernelMock() { $mock = $this->getMockBuilder($this->getKernelClass()) diff --git a/src/Symfony/Component/BrowserKit/AbstractBrowser.php b/src/Symfony/Component/BrowserKit/AbstractBrowser.php index 69c2032b92d74..6ba9f488a005f 100644 --- a/src/Symfony/Component/BrowserKit/AbstractBrowser.php +++ b/src/Symfony/Component/BrowserKit/AbstractBrowser.php @@ -531,7 +531,7 @@ public function reload(): Crawler */ public function followRedirect(): Crawler { - if (!$this->redirect) { + if (!isset($this->redirect)) { throw new LogicException('The request was not redirected.'); } diff --git a/src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php b/src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php index 2267fca448799..ca822e245d6ef 100644 --- a/src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php +++ b/src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php @@ -15,6 +15,7 @@ use Symfony\Component\BrowserKit\CookieJar; use Symfony\Component\BrowserKit\Exception\BadMethodCallException; use Symfony\Component\BrowserKit\Exception\InvalidArgumentException; +use Symfony\Component\BrowserKit\Exception\LogicException; use Symfony\Component\BrowserKit\History; use Symfony\Component\BrowserKit\Request; use Symfony\Component\BrowserKit\Response; @@ -889,4 +890,14 @@ public function testInternalRequestNull() $client->getInternalRequest(); } + + public function testFollowRedirectWithoutRequest() + { + $browser = $this->getBrowser(); + + $this->expectException(LogicException::class); + $this->expectExceptionMessage('The request was not redirected.'); + + $browser->followRedirect(); + } }