-
Notifications
You must be signed in to change notification settings - Fork 182
feat: split tests of query.max_query_count
#670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexislefebvre
wants to merge
2
commits into
liip:master
Choose a base branch
from
alexislefebvre:feat-split-tests-of-query.max_query_count
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
tests/AppConfigMaxQueryCount/AppConfigMaxQueryCountKernel.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * This file is part of the Liip/FunctionalTestBundle | ||
| * | ||
| * (c) Lukas Kahwe Smith <smith@pooteeweet.org> | ||
| * | ||
| * This source file is subject to the MIT license that is bundled | ||
| * with this source code in the file LICENSE. | ||
| */ | ||
|
|
||
| namespace Liip\Acme\Tests\AppConfigMaxQueryCount; | ||
|
|
||
| /* | ||
| * This file is part of the Liip/FunctionalTestBundle | ||
| * | ||
| * (c) Lukas Kahwe Smith <smith@pooteeweet.org> | ||
| * | ||
| * This source file is subject to the MIT license that is bundled | ||
| * with this source code in the file LICENSE. | ||
| */ | ||
|
|
||
| use Liip\Acme\Tests\AppConfig\AppConfigKernel; | ||
| use Symfony\Component\Config\Loader\LoaderInterface; | ||
|
|
||
| class AppConfigMaxQueryCountKernel extends AppConfigKernel | ||
| { | ||
| /** | ||
| * Load the config.yml from the current directory. | ||
| */ | ||
| public function registerContainerConfiguration(LoaderInterface $loader): void | ||
| { | ||
| // Load the default file. | ||
| parent::registerContainerConfiguration($loader); | ||
|
|
||
| // Load the file with "liip_functional_test" parameters | ||
| $loader->load(__DIR__.'/config.yml'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # inherits configuration from ../AppConfig/config.yml | ||
|
|
||
| liip_functional_test: | ||
| query: | ||
| max_query_count: 0 |
51 changes: 51 additions & 0 deletions
51
tests/DependencyInjection/ConfigurationConfigMaxQueryCountTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * This file is part of the Liip/FunctionalTestBundle | ||
| * | ||
| * (c) Lukas Kahwe Smith <smith@pooteeweet.org> | ||
| * | ||
| * This source file is subject to the MIT license that is bundled | ||
| * with this source code in the file LICENSE. | ||
| */ | ||
|
|
||
| namespace DependencyInjection; | ||
|
|
||
| use Liip\Acme\Tests\AppConfigMaxQueryCount\AppConfigMaxQueryCountKernel; | ||
| use Liip\Acme\Tests\DependencyInjection\ConfigurationTest; | ||
|
|
||
| /** | ||
| * Use Tests/AppConfigMaxQueryCount/AppConfigMaxQueryCountKernel.php instead of | ||
| * Tests/App/AppKernel.php. | ||
| * So it must be loaded in a separate process. | ||
| * | ||
| * @runTestsInSeparateProcesses | ||
| * | ||
| * @preserveGlobalState disabled | ||
| */ | ||
| class ConfigurationConfigMaxQueryCountTest extends ConfigurationTest | ||
| { | ||
| /** | ||
| * Use another Kernel to load another config file. | ||
| */ | ||
| protected static function getKernelClass(): string | ||
| { | ||
| return AppConfigMaxQueryCountKernel::class; | ||
| } | ||
|
|
||
| /** | ||
| * Override values to be tested. | ||
| */ | ||
| public static function parametersProvider(): array | ||
| { | ||
| return [ | ||
| ['command_verbosity', 'very_verbose'], | ||
| ['command_decoration', false], | ||
| ['query.max_query_count', 0], | ||
| ['authentication.username', 'foobar'], | ||
| ['authentication.password', '12341234'], | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * This file is part of the Liip/FunctionalTestBundle | ||
| * | ||
| * (c) Lukas Kahwe Smith <smith@pooteeweet.org> | ||
| * | ||
| * This source file is subject to the MIT license that is bundled | ||
| * with this source code in the file LICENSE. | ||
| */ | ||
|
|
||
| namespace Liip\Acme\Tests\Test; | ||
|
|
||
| use Liip\Acme\Tests\App\Entity\User; | ||
| use Liip\Acme\Tests\AppConfigMaxQueryCount\AppConfigMaxQueryCountKernel; | ||
| use Liip\Acme\Tests\Traits\LiipAcmeFixturesTrait; | ||
| use Liip\FunctionalTestBundle\Test\WebTestCase; | ||
| use Symfony\Component\HttpKernel\Kernel; | ||
|
|
||
| /** | ||
| * Tests that AllowedQueriesExceededException is thrown. | ||
| * | ||
| * Use Tests/AppConfigMaxQueryCount/AppConfigMaxQueryCountKernel.php instead of | ||
| * Tests/App/AppKernel.php. | ||
| * So it must be loaded in a separate process. | ||
| * | ||
| * @runTestsInSeparateProcesses | ||
| * | ||
| * @preserveGlobalState disabled | ||
| */ | ||
| class WebTestCaseConfigMaxQueryCountTest extends WebTestCase | ||
| { | ||
| use LiipAcmeFixturesTrait; | ||
|
|
||
| /** @var \Symfony\Bundle\FrameworkBundle\Client client */ | ||
| private $client; | ||
|
|
||
| protected function tearDown(): void | ||
| { | ||
| parent::tearDown(); | ||
|
|
||
| restore_exception_handler(); | ||
| } | ||
|
|
||
| protected static function getKernelClass(): string | ||
| { | ||
| return AppConfigMaxQueryCountKernel::class; | ||
| } | ||
|
|
||
| /** | ||
| * Log in as the user defined in the Data Fixtures and except an | ||
| * AllowedQueriesExceededException exception. | ||
| * | ||
| * 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 | ||
| { | ||
| $this->skipTestIfSymfonyHasVersion7(); | ||
|
|
||
| $user = $this->loadTestFixtures(); | ||
|
|
||
| $this->assertInstanceOf( | ||
| User::class, | ||
| $user | ||
| ); | ||
|
|
||
| $this->client = static::makeClient(); | ||
|
|
||
| $this->loginClient($this->client, $user, 'secured_area'); | ||
|
|
||
| $path = '/user/2'; | ||
|
|
||
| $this->expectException(\Liip\FunctionalTestBundle\Exception\AllowedQueriesExceededException::class); | ||
|
|
||
| $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() | ||
| ); | ||
| } | ||
|
|
||
| private function skipTestIfSymfonyHasVersion7(): void | ||
| { | ||
| if (Kernel::MAJOR_VERSION >= 7) { | ||
| $this->markTestSkipped('The QueryCount is not compatible with Symfony 7+'); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Providing this information is better than before, but this warning may not appear when running tests, so it may be ineffective.