From 93a080a3adf9dfef6cc434c50fc092c90cca42c9 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Sat, 14 May 2022 01:33:34 +0200 Subject: [PATCH] Set max_query_count to avoid failing the test of the exception --- tests/AppConfig/config.yml | 3 +- .../ConfigurationConfigTest.php | 2 +- tests/Test/WebTestCaseConfigTest.php | 34 +++++++++++++++---- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/tests/AppConfig/config.yml b/tests/AppConfig/config.yml index f10ccd04..639d5cc8 100644 --- a/tests/AppConfig/config.yml +++ b/tests/AppConfig/config.yml @@ -10,7 +10,8 @@ liip_functional_test: command_verbosity: "very_verbose" command_decoration: false query: - max_query_count: 1 + # TODO: it should be 1 + max_query_count: 0 authentication: username: "foobar" password: "12341234" diff --git a/tests/DependencyInjection/ConfigurationConfigTest.php b/tests/DependencyInjection/ConfigurationConfigTest.php index dceb2d98..ac095190 100644 --- a/tests/DependencyInjection/ConfigurationConfigTest.php +++ b/tests/DependencyInjection/ConfigurationConfigTest.php @@ -41,7 +41,7 @@ public function parametersProvider(): array return [ ['command_verbosity', 'very_verbose'], ['command_decoration', false], - ['query.max_query_count', 1], + ['query.max_query_count', 0], ['authentication.username', 'foobar'], ['authentication.password', '12341234'], ]; diff --git a/tests/Test/WebTestCaseConfigTest.php b/tests/Test/WebTestCaseConfigTest.php index f13e4825..c236ea18 100644 --- a/tests/Test/WebTestCaseConfigTest.php +++ b/tests/Test/WebTestCaseConfigTest.php @@ -182,8 +182,11 @@ public function testIndexAuthenticationLoginClient(): void * Log in as the user defined in the Data Fixtures and except an * AllowedQueriesExceededException exception. * - * There will be 2 queries, in the configuration the limit is 1, - * an Exception will be thrown. + * There will be 2 queries: + * - the user 1 is loaded from the database when logging in + * - the user 2 is loaded by the controller + * + * In the configuration the limit is 1, an Exception will be thrown. */ public function testAllowedQueriesExceededException(): void { @@ -194,17 +197,34 @@ public function testAllowedQueriesExceededException(): void $user ); - $this->loginAs($user, 'secured_area'); - $this->client = static::makeClient(); - // One another query to load the second user. + $this->loginClient($this->client, $user, 'secured_area'); + $path = '/user/2'; $this->expectException(\Liip\FunctionalTestBundle\Exception\AllowedQueriesExceededException::class); - $this->client->request('GET', $path); + $crawler = $this->client->request('GET', $path); + + // The following code is called if no exception has been thrown, it should help to understand why $this->assertStatusCode(200, $this->client); + $this->assertSame( + 'LiipFunctionalTestBundle', + $crawler->filter('h1')->text() + ); + $this->assertSame( + 'Logged in as foo bar.', + $crawler->filter('p#user')->text() + ); + $this->assertSame( + 'Name: alice bob', + $crawler->filter('div#content p:nth-child(1)')->text() + ); + $this->assertSame( + 'Email: alice@example.com', + $crawler->filter('div#content p:nth-child(2)')->text() + ); } /** @@ -217,6 +237,8 @@ public function testAllowedQueriesExceededException(): void */ public function testAnnotationAndException(): void { + $user = $this->loadTestFixtures(); + $this->client = static::makeClient(); // One query to load the second user