Skip to content

Commit d05ed96

Browse files
bug symfony#58626 [BrowserKit][FrameworkBundle] do not access typed properties before initialization (xabbuh)
This PR was merged into the 7.1 branch. Discussion ---------- [BrowserKit][FrameworkBundle] do not access typed properties before initialization | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- 1a7278e do not access typed properties before initialization
2 parents f549ad4 + 1a7278e commit d05ed96

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/KernelBrowser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getKernel(): KernelInterface
5656
*/
5757
public function getProfile(): HttpProfile|false|null
5858
{
59-
if (null === $this->response || !$this->getContainer()->has('profiler')) {
59+
if (!isset($this->response) || !$this->getContainer()->has('profiler')) {
6060
return false;
6161
}
6262

src/Symfony/Bundle/FrameworkBundle/Tests/KernelBrowserTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
1515
use Symfony\Bundle\FrameworkBundle\Tests\Functional\AbstractWebTestCase;
1616
use Symfony\Component\HttpFoundation\Response;
17+
use Symfony\Component\HttpKernel\KernelInterface;
1718

1819
class KernelBrowserTest extends AbstractWebTestCase
1920
{
@@ -61,6 +62,13 @@ public function testRequestAfterKernelShutdownAndPerformedRequest()
6162
$client->request('GET', '/');
6263
}
6364

65+
public function testGetProfileWithoutRequest()
66+
{
67+
$browser = new KernelBrowser($this->createMock(KernelInterface::class));
68+
69+
$this->assertFalse($browser->getProfile());
70+
}
71+
6472
private function getKernelMock()
6573
{
6674
$mock = $this->getMockBuilder($this->getKernelClass())

src/Symfony/Component/BrowserKit/AbstractBrowser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ public function reload(): Crawler
531531
*/
532532
public function followRedirect(): Crawler
533533
{
534-
if (!$this->redirect) {
534+
if (!isset($this->redirect)) {
535535
throw new LogicException('The request was not redirected.');
536536
}
537537

src/Symfony/Component/BrowserKit/Tests/AbstractBrowserTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\BrowserKit\CookieJar;
1616
use Symfony\Component\BrowserKit\Exception\BadMethodCallException;
1717
use Symfony\Component\BrowserKit\Exception\InvalidArgumentException;
18+
use Symfony\Component\BrowserKit\Exception\LogicException;
1819
use Symfony\Component\BrowserKit\History;
1920
use Symfony\Component\BrowserKit\Request;
2021
use Symfony\Component\BrowserKit\Response;
@@ -889,4 +890,14 @@ public function testInternalRequestNull()
889890

890891
$client->getInternalRequest();
891892
}
893+
894+
public function testFollowRedirectWithoutRequest()
895+
{
896+
$browser = $this->getBrowser();
897+
898+
$this->expectException(LogicException::class);
899+
$this->expectExceptionMessage('The request was not redirected.');
900+
901+
$browser->followRedirect();
902+
}
892903
}

0 commit comments

Comments
 (0)