Skip to content

Commit

Permalink
do not access typed properties before initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Oct 22, 2024
1 parent 4cbf327 commit 6e695b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion KernelBrowser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 8 additions & 0 deletions Tests/KernelBrowserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 6e695b9

Please sign in to comment.