From efacc159ab996d9309f3903f239fa64397902256 Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Wed, 28 Jun 2023 12:41:25 +0200 Subject: [PATCH 01/22] Update readme.md --- README.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 88b53cc..b89314d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,56 @@ -[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.0-8892BF)](https://php.net/) +[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.1-8892BF)](https://php.net/) + +## PHPUnit extensions + +Utility classes to make unit testing life easier. + + +## Features + +### withConsecutive +In PHPUnit 10 withConsecutive method was removed. To still be able to migrate existing codebases a replacement method: + +Before: +```php +$mock->method('myMethod')->withConsecutive([123, 'foobar'], [456]); +``` +```php +$mock->method('myMethod')->with(...consecutive([123, 'foobar'], [456])); +``` + + +### Symfony controller tests +Testing a Symfony controller internally invokes the dependency container. A utility class to mock these classes more easily. + +```php +use DR\PHPUnitExtensions\Symfony\AbstractControllerTestCase; + +class MyControllerTest extends AbstractControllerTestCase +{ + public function myTest(): void + { + $this->expectDenyAccessUnlessGranted('attribute', null, true); + $this->expectGetUser(new User()); + $this->expectCreateForm(TextType::class); + + ($this->controller)(); + } + + public function getController() { + return new MyController(); + } +} +``` + +**Methods** +- `expectGetUser` +- `expectDenyAccessUnlessGranted` +- `expectCreateForm` +- `expectAddFlash` +- `expectGenerateUrl` +- `expectRedirectToRoute` +- `expectForward` +- `expectRender` ## About us From b4fff5ee6294726c158d50e3d1cc26b181da675f Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Wed, 28 Jun 2023 12:43:13 +0200 Subject: [PATCH 02/22] Update readme.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b89314d..cccdfcf 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,11 @@ Utility classes to make unit testing life easier. ### withConsecutive In PHPUnit 10 withConsecutive method was removed. To still be able to migrate existing codebases a replacement method: -Before: +PHPUnit <= 9.5: ```php $mock->method('myMethod')->withConsecutive([123, 'foobar'], [456]); ``` +PHPUnit >= 9.6: ```php $mock->method('myMethod')->with(...consecutive([123, 'foobar'], [456])); ``` From ee3a84ca2f3b17d1f06a2638ed3ef5983436341f Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Wed, 28 Jun 2023 12:44:38 +0200 Subject: [PATCH 03/22] Fix phpunit configuration --- phpunit.xml.dist | 3 --- 1 file changed, 3 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c754967..93926f8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,9 +15,6 @@ tests/Integration - - tests/Unit - From bdf6880be25dcdabd61a88e3b1f461d4c9617bcf Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Wed, 28 Jun 2023 12:44:48 +0200 Subject: [PATCH 04/22] Fix phpunit configuration --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index d94d5e1..3655995 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,6 @@ "fix:phpcbf": "phpcbf src tests", "test": "phpunit", "test:integration": "phpunit --testsuite integration", - "test:unit": "phpunit --testsuite unit" }, "suggest": { "symfony/form": "Symfony form component is required for testing the controller createForm methods", From 2bf2ee371d53c96391671b2b5c9f3012e3ce989b Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Wed, 28 Jun 2023 12:46:21 +0200 Subject: [PATCH 05/22] Fix phpunit configuration --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3655995..38f2797 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "fix": "@fix:phpcbf", "fix:phpcbf": "phpcbf src tests", "test": "phpunit", - "test:integration": "phpunit --testsuite integration", + "test:integration": "phpunit --testsuite integration" }, "suggest": { "symfony/form": "Symfony form component is required for testing the controller createForm methods", From a59643bfd8402b41da1405541b2cbb817a67c907 Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Wed, 28 Jun 2023 13:05:49 +0200 Subject: [PATCH 06/22] Fix phpunit configuration --- .github/workflows/test.yml | 2 ++ phpunit.xml.dist | 13 +++++-------- phpunit9.xml.dist | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 phpunit9.xml.dist diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dfdfcd5..73e4956 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,8 @@ jobs: - name: Install dependencies run: composer update --prefer-dist --no-progress --no-suggest --prefer-stable ${{ matrix.composer-flags }} + - run: [[ "${{ matrix.composer-flags }}" == "--prefer-lowest" ]] && cp phpunit9.xml.dist phpunit.xml.dist + - name: Run test suite run: composer test diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 93926f8..a4bf679 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,21 @@ + requireCoverageMetadata="true"> tests/Integration - + - src + src - + diff --git a/phpunit9.xml.dist b/phpunit9.xml.dist new file mode 100644 index 0000000..c7e3994 --- /dev/null +++ b/phpunit9.xml.dist @@ -0,0 +1,24 @@ + + + + + tests/Integration + + + + + src + + + From fa12576881ce8d6bca48d2855ffc833220cc52ca Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Wed, 28 Jun 2023 13:07:23 +0200 Subject: [PATCH 07/22] Fix phpunit configuration --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 73e4956..af766c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,7 +32,7 @@ jobs: - name: Install dependencies run: composer update --prefer-dist --no-progress --no-suggest --prefer-stable ${{ matrix.composer-flags }} - - run: [[ "${{ matrix.composer-flags }}" == "--prefer-lowest" ]] && cp phpunit9.xml.dist phpunit.xml.dist + - run: '[[ "${{ matrix.composer-flags }}" == "--prefer-lowest" ]] && cp phpunit9.xml.dist phpunit.xml.dist' - name: Run test suite run: composer test From 08fbcdf8076175c91aa6dc56f2c478ad203a53c9 Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Wed, 28 Jun 2023 13:08:23 +0200 Subject: [PATCH 08/22] Fix phpunit configuration --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index af766c2..2a62303 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -66,7 +66,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.1 coverage: none - name: Install dependencies From 0c4276af3efc36ebe48570132a24f5fe3bb7ebdd Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Wed, 28 Jun 2023 13:28:59 +0200 Subject: [PATCH 09/22] Fix phpunit configuration --- phpunit9.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit9.xml.dist b/phpunit9.xml.dist index c7e3994..93926f8 100644 --- a/phpunit9.xml.dist +++ b/phpunit9.xml.dist @@ -1,7 +1,7 @@ Date: Wed, 28 Jun 2023 13:31:58 +0200 Subject: [PATCH 10/22] Fix phpunit configuration --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a62303..b5a7bb9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,7 +32,7 @@ jobs: - name: Install dependencies run: composer update --prefer-dist --no-progress --no-suggest --prefer-stable ${{ matrix.composer-flags }} - - run: '[[ "${{ matrix.composer-flags }}" == "--prefer-lowest" ]] && cp phpunit9.xml.dist phpunit.xml.dist' + - run: '[[ "${{ matrix.composer-flags }}" != "--prefer-lowest" ]] || cp phpunit9.xml.dist phpunit.xml.dist' - name: Run test suite run: composer test From 31cd9aad5d28079eb8c34a96aaef559756e192c0 Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Wed, 28 Jun 2023 13:34:08 +0200 Subject: [PATCH 11/22] Fix phpunit configuration --- tests/Integration/Mock/ConsecutiveTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Mock/ConsecutiveTest.php b/tests/Integration/Mock/ConsecutiveTest.php index d7511a4..3c187cd 100644 --- a/tests/Integration/Mock/ConsecutiveTest.php +++ b/tests/Integration/Mock/ConsecutiveTest.php @@ -59,7 +59,7 @@ public function testConsecutiveMinimumOfOneArguments(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('consecutive() is expecting at least 1 or more arguments for invocation'); - consecutive([123], []); + consecutive([], []); } public function testConsecutiveInvokeMoreThanExpected(): void From cac07c35f2a4360d40d3c9c45108b2fa66065ca4 Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Wed, 28 Jun 2023 13:40:47 +0200 Subject: [PATCH 12/22] Fix phpunit configuration --- tests/Integration/Symfony/Controller/FormControllerTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/Integration/Symfony/Controller/FormControllerTest.php b/tests/Integration/Symfony/Controller/FormControllerTest.php index 4caa7b3..bbdc04f 100644 --- a/tests/Integration/Symfony/Controller/FormControllerTest.php +++ b/tests/Integration/Symfony/Controller/FormControllerTest.php @@ -32,15 +32,17 @@ public function testInvoke(): void public function testInvokeInvalid(): void { + $formView = new FormView(); + $request = new Request(); $this->expectCreateForm(FormType::class) ->handleRequest($request) ->isSubmittedWillReturn(true) ->isValidWillReturn(false) - ->createViewWillReturn(new FormView()) + ->createViewWillReturn($formView) ->getWillReturn(['name' => 'foobar']); - $this->expectRender('form.html.twig', ['form' => new FormView()], 'FormView'); + $this->expectRender('form.html.twig', ['form' => $formView], 'FormView'); static::assertSame('FormView', ($this->controller)($request)->getContent()); } From 99475ff916ea937de25d30c36071b8d66c44fdf4 Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Wed, 28 Jun 2023 14:31:11 +0200 Subject: [PATCH 13/22] Fix phpunit configuration --- tests/Integration/Mock/ConsecutiveTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/Integration/Mock/ConsecutiveTest.php b/tests/Integration/Mock/ConsecutiveTest.php index 3c187cd..c6de5f7 100644 --- a/tests/Integration/Mock/ConsecutiveTest.php +++ b/tests/Integration/Mock/ConsecutiveTest.php @@ -4,19 +4,18 @@ namespace DR\PHPUnitExtensions\Tests\Integration\Mock; -use DR\PHPUnitExtensions\Mock\ConsecutiveParameters; use DR\PHPUnitExtensions\Tests\Resources\Mock\ConsecutiveMock; use DR\PHPUnitExtensions\Tests\Resources\Mock\MockInterface; use InvalidArgumentException; -use PHPUnit\Framework\Attributes\CoversClass; -use PHPUnit\Framework\Attributes\CoversFunction; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use function DR\PHPUnitExtensions\Mock\consecutive; -#[CoversClass(ConsecutiveParameters::class)] -#[CoversFunction('DR\PHPUnitExtensions\Mock\consecutive')] +/** + * @covers \DR\PHPUnitExtensions\Mock\ConsecutiveParameters + * @covers \DR\PHPUnitExtensions\Mock\consecutive + */ class ConsecutiveTest extends TestCase { public function testConsecutiveSingle(): void From 26f04652e91f916d348fadad20246ce5fa94b0aa Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Mon, 3 Jul 2023 13:36:55 +0200 Subject: [PATCH 14/22] Fix phpunit configuration --- phpunit.xml.dist | 13 ++++++++----- src/Symfony/AbstractControllerTestCase.php | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a4bf679..93926f8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,21 +1,24 @@ +> tests/Integration - + - src + src - + diff --git a/src/Symfony/AbstractControllerTestCase.php b/src/Symfony/AbstractControllerTestCase.php index e13511a..9fbb034 100644 --- a/src/Symfony/AbstractControllerTestCase.php +++ b/src/Symfony/AbstractControllerTestCase.php @@ -79,6 +79,8 @@ public function expectCreateForm(string $type, mixed $data = null, array $option public function expectAddFlash(string $type, mixed $message): void { $flashBag = $this->createMock(FlashBagInterface::class); + $flashBag->method('getName')->willReturn('name'); + $flashBag->method('getStorageKey')->willReturn('storageKey'); $request = new Request(); $request->setSession(new Session(new MockArraySessionStorage(), null, $flashBag)); $requestStack = new RequestStack(); From 568214ff22fab05cbf2ac0be41b528caa736516c Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Mon, 3 Jul 2023 15:55:17 +0200 Subject: [PATCH 15/22] Fix test --- .../Symfony/Controller/FormControllerTest.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/Integration/Symfony/Controller/FormControllerTest.php b/tests/Integration/Symfony/Controller/FormControllerTest.php index bbdc04f..280590f 100644 --- a/tests/Integration/Symfony/Controller/FormControllerTest.php +++ b/tests/Integration/Symfony/Controller/FormControllerTest.php @@ -7,7 +7,6 @@ use DR\PHPUnitExtensions\Symfony\AbstractControllerTestCase; use DR\PHPUnitExtensions\Tests\Resources\Symfony\Controller\FormController; use Symfony\Component\Form\Extension\Core\Type\FormType; -use Symfony\Component\Form\FormView; use Symfony\Component\HttpFoundation\Request; /** @@ -32,17 +31,14 @@ public function testInvoke(): void public function testInvokeInvalid(): void { - $formView = new FormView(); - - $request = new Request(); - $this->expectCreateForm(FormType::class) + $request = new Request(); + $formMock = $this->expectCreateForm(FormType::class) ->handleRequest($request) ->isSubmittedWillReturn(true) ->isValidWillReturn(false) - ->createViewWillReturn($formView) ->getWillReturn(['name' => 'foobar']); - $this->expectRender('form.html.twig', ['form' => $formView], 'FormView'); + $this->expectRender('form.html.twig', ['form' => $formMock->form], 'FormView'); static::assertSame('FormView', ($this->controller)($request)->getContent()); } From 22fc020b2381fcdb04c0186c2c295f2631597519 Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Mon, 3 Jul 2023 16:20:10 +0200 Subject: [PATCH 16/22] Fix test between Symfony versions --- tests/Integration/Symfony/Controller/FormControllerTest.php | 6 +++--- tests/Resources/Symfony/Controller/FormController.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Integration/Symfony/Controller/FormControllerTest.php b/tests/Integration/Symfony/Controller/FormControllerTest.php index 280590f..998136b 100644 --- a/tests/Integration/Symfony/Controller/FormControllerTest.php +++ b/tests/Integration/Symfony/Controller/FormControllerTest.php @@ -31,14 +31,14 @@ public function testInvoke(): void public function testInvokeInvalid(): void { - $request = new Request(); - $formMock = $this->expectCreateForm(FormType::class) + $request = new Request(); + $this->expectCreateForm(FormType::class) ->handleRequest($request) ->isSubmittedWillReturn(true) ->isValidWillReturn(false) ->getWillReturn(['name' => 'foobar']); - $this->expectRender('form.html.twig', ['form' => $formMock->form], 'FormView'); + $this->expectRender('form.html.twig', ['foo' => 'bar'], 'FormView'); static::assertSame('FormView', ($this->controller)($request)->getContent()); } diff --git a/tests/Resources/Symfony/Controller/FormController.php b/tests/Resources/Symfony/Controller/FormController.php index 132f1de..3d2df2f 100644 --- a/tests/Resources/Symfony/Controller/FormController.php +++ b/tests/Resources/Symfony/Controller/FormController.php @@ -23,6 +23,6 @@ public function __invoke(Request $request): Response $form->get('name'); - return $this->render('form.html.twig', ['form' => $form]); + return $this->render('form.html.twig', ['foo' => 'bar']); } } From 752990cd868412637839155b32ec0212f8e0dfae Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Mon, 3 Jul 2023 16:22:50 +0200 Subject: [PATCH 17/22] fix phpfci --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b5a7bb9..ca47e88 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,7 +55,7 @@ jobs: run: php -dpcov.enabled=1 -dpcov.exclude="~vendor~" vendor/bin/phpunit --testsuite unit --coverage-clover ./.coverage/coverage.xml - name: Check coverage - run: test ! -f ./.coverage/coverage.xml || php vendor/bin/phpfci inspect ./.coverage/coverage.xml ./.coverage/phpfci.xml --exit-code-on-failure + run: test ! -f ./.coverage/coverage.xml || php vendor/bin/phpfci inspect ./.coverage/coverage.xml --exit-code-on-failure --reportText quality: name: Quality checks From d471b123b34b5fac9b5190910283133555340b25 Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Thu, 6 Jul 2023 10:13:07 +0200 Subject: [PATCH 18/22] Remove "bootstrap" from phpunit.xml --- phpunit.xml.dist | 1 - phpunit9.xml.dist | 1 - 2 files changed, 2 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 93926f8..cedb15c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,6 @@ Date: Thu, 6 Jul 2023 10:53:58 +0200 Subject: [PATCH 19/22] Ensure function is only loaded once --- phpunit.xml.dist | 13 +++---- src/Mock/consecutive.php | 76 +++++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 45 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index cedb15c..948d6db 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,23 +1,20 @@ + requireCoverageMetadata="true"> tests/Integration - + - src + src - + diff --git a/src/Mock/consecutive.php b/src/Mock/consecutive.php index 18a82c3..2424a61 100644 --- a/src/Mock/consecutive.php +++ b/src/Mock/consecutive.php @@ -8,47 +8,49 @@ use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\Constraint\IsAnything; -/** - * @param array $firstInvocationArguments A list of arguments for each invocation that will be asserted against. - * Will fail on: too many invocations or if the argument doesn't match for each invocation. - * @param array $secondInvocationArguments - * @param array ...$expectedArgumentList - * - * @note Full qualified name to appease to phpstorm inspection gods - * phpcs:ignore - * @return \PHPUnit\Framework\Constraint\Callback[] - * @example ->with(...consecutive([5, 'foo'], [6, 'bar'])) - */ -function consecutive(array $firstInvocationArguments, array $secondInvocationArguments, array ...$expectedArgumentList): array -{ - array_unshift($expectedArgumentList, $secondInvocationArguments); - array_unshift($expectedArgumentList, $firstInvocationArguments); - - // count arguments - $maxArguments = (int)max(array_map(static fn($args) => count($args), $expectedArgumentList)); - if ($maxArguments === 0) { - throw new InvalidArgumentException('consecutive() is expecting at least 1 or more arguments for invocation'); - } +if (function_exists('\DR\PHPUnitExtensions\Mock\consecutive') === false) { + /** + * @param array $firstInvocationArguments A list of arguments for each invocation that will be asserted against. + * Will fail on: too many invocations or if the argument doesn't match for each invocation. + * @param array $secondInvocationArguments + * @param array ...$expectedArgumentList + * + * @note Full qualified name to appease to phpstorm inspection gods + * phpcs:ignore + * @return \PHPUnit\Framework\Constraint\Callback[] + * @example ->with(...consecutive([5, 'foo'], [6, 'bar'])) + */ + function consecutive(array $firstInvocationArguments, array $secondInvocationArguments, array ...$expectedArgumentList): array + { + array_unshift($expectedArgumentList, $secondInvocationArguments); + array_unshift($expectedArgumentList, $firstInvocationArguments); + + // count arguments + $maxArguments = (int)max(array_map(static fn($args) => count($args), $expectedArgumentList)); + if ($maxArguments === 0) { + throw new InvalidArgumentException('consecutive() is expecting at least 1 or more arguments for invocation'); + } - // reorganize arguments per argument index - $argumentsByIndex = []; - foreach ($expectedArgumentList as $invocation => $expectedArguments) { - foreach ($expectedArguments as $index => $argument) { - $argumentsByIndex[$index][$invocation] = $argument; + // reorganize arguments per argument index + $argumentsByIndex = []; + foreach ($expectedArgumentList as $invocation => $expectedArguments) { + foreach ($expectedArguments as $index => $argument) { + $argumentsByIndex[$index][$invocation] = $argument; + } } - } - $callbacks = []; - /** @var array $arguments */ - foreach ($argumentsByIndex as $arguments) { - for ($i = 0; $i < $maxArguments; $i++) { - if (isset($arguments[$i]) === false) { - $arguments[$i] = new IsAnything(); + $callbacks = []; + /** @var array $arguments */ + foreach ($argumentsByIndex as $arguments) { + for ($i = 0; $i < $maxArguments; $i++) { + if (isset($arguments[$i]) === false) { + $arguments[$i] = new IsAnything(); + } } + $constraint = new ConsecutiveParameters($arguments); + $callbacks[] = new Callback(static fn($actualArgument): bool => $constraint->evaluate($actualArgument)); } - $constraint = new ConsecutiveParameters($arguments); - $callbacks[] = new Callback(static fn($actualArgument): bool => $constraint->evaluate($actualArgument)); - } - return $callbacks; + return $callbacks; + } } From df323a30b1cc6e3d00aaf311c6e69768ced7f75c Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Thu, 6 Jul 2023 10:57:55 +0200 Subject: [PATCH 20/22] Run correct suite in github action --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ca47e88..5f7f76e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,7 +52,7 @@ jobs: run: composer update --prefer-dist --no-progress --no-suggest --prefer-stable - name: Run test suite - run: php -dpcov.enabled=1 -dpcov.exclude="~vendor~" vendor/bin/phpunit --testsuite unit --coverage-clover ./.coverage/coverage.xml + run: php -dpcov.enabled=1 -dpcov.exclude="~vendor~" vendor/bin/phpunit --coverage-clover ./.coverage/coverage.xml - name: Check coverage run: test ! -f ./.coverage/coverage.xml || php vendor/bin/phpfci inspect ./.coverage/coverage.xml --exit-code-on-failure --reportText From 44c259861c0891929bfbb94dd317cc3e966442f8 Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Thu, 6 Jul 2023 11:00:40 +0200 Subject: [PATCH 21/22] Add coverage createFormView --- tests/Integration/Symfony/Controller/FormControllerTest.php | 5 ++++- tests/Resources/Symfony/Controller/FormController.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/Integration/Symfony/Controller/FormControllerTest.php b/tests/Integration/Symfony/Controller/FormControllerTest.php index 998136b..1ceba81 100644 --- a/tests/Integration/Symfony/Controller/FormControllerTest.php +++ b/tests/Integration/Symfony/Controller/FormControllerTest.php @@ -7,6 +7,7 @@ use DR\PHPUnitExtensions\Symfony\AbstractControllerTestCase; use DR\PHPUnitExtensions\Tests\Resources\Symfony\Controller\FormController; use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\Form\FormView; use Symfony\Component\HttpFoundation\Request; /** @@ -31,14 +32,16 @@ public function testInvoke(): void public function testInvokeInvalid(): void { + $formView = new FormView(); $request = new Request(); $this->expectCreateForm(FormType::class) ->handleRequest($request) ->isSubmittedWillReturn(true) ->isValidWillReturn(false) + ->createViewWillReturn($formView) ->getWillReturn(['name' => 'foobar']); - $this->expectRender('form.html.twig', ['foo' => 'bar'], 'FormView'); + $this->expectRender('form.html.twig', ['form' => $formView], 'FormView'); static::assertSame('FormView', ($this->controller)($request)->getContent()); } diff --git a/tests/Resources/Symfony/Controller/FormController.php b/tests/Resources/Symfony/Controller/FormController.php index 3d2df2f..adc45a3 100644 --- a/tests/Resources/Symfony/Controller/FormController.php +++ b/tests/Resources/Symfony/Controller/FormController.php @@ -23,6 +23,6 @@ public function __invoke(Request $request): Response $form->get('name'); - return $this->render('form.html.twig', ['foo' => 'bar']); + return $this->render('form.html.twig', ['form' => $form->createView()]); } } From a681ba5e86595d1ce054c3ce95361c36167e18a0 Mon Sep 17 00:00:00 2001 From: Frank Dekker Date: Thu, 6 Jul 2023 11:07:45 +0200 Subject: [PATCH 22/22] Fix coverage --- src/Mock/consecutive.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Mock/consecutive.php b/src/Mock/consecutive.php index 2424a61..1cc8408 100644 --- a/src/Mock/consecutive.php +++ b/src/Mock/consecutive.php @@ -8,7 +8,9 @@ use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\Constraint\IsAnything; +// @codeCoverageIgnoreStart if (function_exists('\DR\PHPUnitExtensions\Mock\consecutive') === false) { + // @codeCoverageIgnoreEnd /** * @param array $firstInvocationArguments A list of arguments for each invocation that will be asserted against. * Will fail on: too many invocations or if the argument doesn't match for each invocation.