Skip to content

Commit

Permalink
chore: disable tests of QueryCount on Symfony 7+
Browse files Browse the repository at this point in the history
  • Loading branch information
alexislefebvre committed Jan 7, 2024
1 parent 3ae6ce6 commit 88fb291
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/QueryCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@

final class QueryCounter
{
/** @var int */
private $defaultMaxCount;
private ?int $defaultMaxCount;
private ?Reader $annotationReader;

/** @var Reader */
private $annotationReader;

public function __construct(?int $defaultMaxCount, Reader $annotationReader)
public function __construct(?int $defaultMaxCount, ?Reader $annotationReader)
{
$this->defaultMaxCount = $defaultMaxCount;
$this->annotationReader = $annotationReader;
Expand Down Expand Up @@ -57,6 +54,10 @@ private function getMaxQueryCount(): ?int

private function getMaxQueryAnnotation(): ?int
{
if (null === $this->annotationReader) {
@trigger_error('The annotationReader is not available', \E_USER_ERROR);
}

foreach (debug_backtrace() as $step) {
if ('test' === substr($step['function'], 0, 4)) { //TODO: handle tests with the @test annotation
$annotations = $this->annotationReader->getMethodAnnotations(
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/functional_test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<service id="liip_functional_test.query.counter" class="Liip\FunctionalTestBundle\QueryCounter">
<argument>%liip_functional_test.query.max_query_count%</argument>
<argument type="service" id="annotation_reader" />
<argument type="service" id="annotation_reader" on-invalid="null" />
</service>
</services>
</container>
22 changes: 21 additions & 1 deletion tests/Test/WebTestCaseConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Liip\Acme\Tests\Traits\LiipAcmeFixturesTrait;
use Liip\FunctionalTestBundle\Annotations\QueryCount;
use Liip\FunctionalTestBundle\Test\WebTestCase;
use Symfony\Component\HttpKernel\Kernel;

/**
* Tests that configuration has been loaded and users can be logged in.
Expand Down Expand Up @@ -52,6 +53,8 @@ protected static function getKernelClass(): string
*/
public function testIndexClientWithCredentials(): void
{
$this->skipTestIfSymfonyHasVersion7();

$this->client = static::makeClientWithCredentials('foobar', '12341234');

$path = '/admin';
Expand Down Expand Up @@ -83,6 +86,8 @@ public function testIndexClientWithCredentials(): void
*/
public function testIndexAuthenticatedClient(): void
{
$this->skipTestIfSymfonyHasVersion7();

$this->client = static::makeAuthenticatedClient();

$path = '/admin';
Expand Down Expand Up @@ -114,6 +119,8 @@ public function testIndexAuthenticatedClient(): void
*/
public function testIndexAuthenticationLoginAs(): void
{
$this->skipTestIfSymfonyHasVersion7();

$user = $this->loadTestFixtures();

$loginAs = $this->loginAs($user, 'secured_area');
Expand Down Expand Up @@ -152,6 +159,8 @@ public function testIndexAuthenticationLoginAs(): void
*/
public function testIndexAuthenticationLoginClient(): void
{
$this->skipTestIfSymfonyHasVersion7();

$user = $this->loadTestFixtures();

$this->client = static::makeClient();
Expand Down Expand Up @@ -192,6 +201,8 @@ public function testIndexAuthenticationLoginClient(): void
*/
public function testAllowedQueriesExceededException(): void
{
$this->skipTestIfSymfonyHasVersion7();

$user = $this->loadTestFixtures();

$this->assertInstanceOf(
Expand Down Expand Up @@ -239,7 +250,9 @@ public function testAllowedQueriesExceededException(): void
*/
public function testAnnotationAndException(): void
{
$user = $this->loadTestFixtures();
$this->skipTestIfSymfonyHasVersion7();

$this->loadTestFixtures();

$this->client = static::makeClient();

Expand All @@ -251,4 +264,11 @@ public function testAnnotationAndException(): void
$this->client->request('GET', $path);
$this->assertStatusCode(200, $this->client);
}

private function skipTestIfSymfonyHasVersion7(): void
{
if (Kernel::MAJOR_VERSION >= 7) {
$this->markTestSkipped('The QueryCount is not compatible with Symfony 7+');
}
}
}

0 comments on commit 88fb291

Please sign in to comment.