Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Symfony/Bundle/Test/ApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ abstract class ApiTestCase extends KernelTestCase
*/
protected static function createClient(array $kernelOptions = [], array $defaultOptions = []): Client
{
if (!static::$booted) {
if (null === ($alwaysBootKernel = $kernelOptions['alwaysBootKernel'] ?? static::alwaysBootKernel())) {
trigger_deprecation('api-platform/symfony', '5.0', \sprintf('We will not boot the kernel if it is booted already. Define the kernelOptions "alwaysBootKernel" or override "%s::alwaysBootKernel" to return "true" if you want to keep the old behavior.', static::class));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. question: IMHO, there is no need to check !static::$booted if we want to keep exactly the same behaviour as before.
  2. question: Maybe the condition can be simplified to if ($checkContainerIsBooted) because it's a boolean

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. suggestion: override instead of implements

if ($alwaysBootKernel ? true : !static::$booted) {
static::bootKernel($kernelOptions);
}

Expand Down Expand Up @@ -99,4 +103,12 @@ protected function getIriFromResource(object $resource): ?string

return $iriConverter->getIriFromResource($resource);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. suggestion: Rename the method and the $kernelOptions['checkContainerIsBooted'] to alwaysBootKernel for better clarity
  2. suggestion: Set false as default value, so there is no need to set it in ApiTestCaseTest::checkContainerIsBooted
  3. suggestion: Encourage people using Alice to set this value to true by adding a comment on the method

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using false will certainly break current usages I'll move to false in API Platform 5

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on how we name the method. When using checkContainerIsBooted --> default value is false, if we name it alwaysBootKernel --> default value should be true.

BTW, I proposed #7007 for this bug fix if you want to adapt yours accordingly.

/**
* When using Alice we recommend to use "true"
*/
protected static function alwaysBootKernel(): ?bool
{
return null;
}
}
7 changes: 6 additions & 1 deletion tests/Symfony/Bundle/Test/ApiTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@ public function testDoNotRebootKernelOnCreateClient(): void

self::$kernel = $mock;

self::createClient();
self::createClient(['checkContainerIsBooted' => true]);
}

protected static function checkContainerIsBooted(): ?bool
{
return false;
}
}
5 changes: 5 additions & 0 deletions tests/Symfony/Bundle/Test/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,9 @@ public function testLoginUser(): void
$client->request('GET', '/secured_dummies');
$this->assertResponseIsSuccessful();
}

protected static function checkContainerIsBooted(): ?bool
{
return true;
}
}
Loading