From 36318127f7f33f8544a2b02773a1a4f3984cee34 Mon Sep 17 00:00:00 2001 From: Damien Harper Date: Fri, 11 Dec 2020 12:07:17 +0100 Subject: [PATCH] Updated CI (#225) * Better locking of Symfony versions in CI * Fix tests with Symfony 4.4 * Skipped some tests when using Symfony 3.4 --- .github/workflows/ci.yml | 15 +++++++++++++-- .gitignore | 1 + .php_cs | 1 + composer.json | 7 +++++-- src/DependencyInjection/DHAuditorExtension.php | 6 ++++-- tests/App/config/packages/security.yaml | 2 +- tests/Controller/ViewerControllerTest.php | 18 ++++++++---------- tests/DHAuditorBundleTest.php | 5 +++++ tests/Twig/Extension/TwigExtensionTest.php | 5 +++++ 9 files changed, 43 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19ec920f..aab98918 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,7 +38,9 @@ jobs: coverage: pcov - name: Configure Symfony - run: composer config extra.symfony.require "${{ matrix.symfony }}" + run: | + composer global require --no-progress --no-scripts --no-plugins symfony/flex + composer config extra.symfony.require "${{ matrix.symfony }}" - name: Get Composer Cache Directory id: composer-cache @@ -51,7 +53,16 @@ jobs: key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }} restore-keys: ${{ matrix.php }}-composer- - - name: Update project dependencies + - name: Update project dependencies (3.4.*) + if: matrix.symfony == '3.4.*' + run: SYMFONY_REQUIRE="^3.4" composer update --no-progress --ansi --prefer-stable + + - name: Update project dependencies (4.4.*) + if: matrix.symfony == '4.4.*' + run: SYMFONY_REQUIRE="^4.4" composer update --no-progress --ansi --prefer-stable + + - name: Update project dependencies (5.*) + if: matrix.symfony == '5.*' run: composer update --no-progress --ansi --prefer-stable - name: Validate composer diff --git a/.gitignore b/.gitignore index 7a66ed76..5a399db8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ composer.lock *.sqlite var/ /tests/App/.preload.php +/tests/App/cache/ diff --git a/.php_cs b/.php_cs index c15142d7..a1d0851a 100644 --- a/.php_cs +++ b/.php_cs @@ -54,6 +54,7 @@ $config = PhpCsFixer\Config::create() ->setFinder(PhpCsFixer\Finder::create() ->in(__DIR__) ->notPath('tests/App/var/') + ->notPath('tests/App/cache/') ->notPath('src/DependencyInjection/Configuration.php') ) ; diff --git a/composer.json b/composer.json index ed7c038e..d4eb8f9d 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "phpstan/phpstan-strict-rules": "^0.12", "phpstan/phpstan-symfony": "^0.12", "phpunit/phpunit": "^8.0|^9.0", - "symfony/browser-kit": "^5.1", + "symfony/browser-kit": "^3.4|^4.0|^5.1", "symfony/css-selector": "^5.1", "symfony/framework-bundle": "^3.4|^4.0|^5.0", "symfony/var-dumper": "^3.4|^4.0|^5.0", @@ -56,7 +56,10 @@ "scripts": { "test": "php -d pcov.enabled=1 ./vendor/bin/phpunit --colors=always", "csfixer": "vendor/bin/php-cs-fixer fix --config=.php_cs --using-cache=no --verbose --ansi", - "stan": "vendor/bin/phpstan --ansi analyse src" + "stan": "vendor/bin/phpstan --ansi analyse src", + "setup34": "SYMFONY_REQUIRE='^3.4' composer update --prefer-stable", + "setup44": "SYMFONY_REQUIRE='^4.4' composer update --prefer-stable", + "setup5": "composer update --prefer-stable" }, "config": { "sort-packages": true diff --git a/src/DependencyInjection/DHAuditorExtension.php b/src/DependencyInjection/DHAuditorExtension.php index 26832e35..2aabdaeb 100644 --- a/src/DependencyInjection/DHAuditorExtension.php +++ b/src/DependencyInjection/DHAuditorExtension.php @@ -33,8 +33,10 @@ private function loadProviders(ContainerBuilder $container, array $config): void foreach ($config['providers'] as $providerName => $providerConfig) { $container->setParameter('dh_auditor.provider.'.$providerName.'.configuration', $providerConfig); - $serviceId = 'dh_auditor.provider.'.$providerName; - $container->registerAliasForArgument($serviceId, ProviderInterface::class, "{$providerName}Provider"); + if (method_exists($container, 'registerAliasForArgument')) { + $serviceId = 'dh_auditor.provider.'.$providerName; + $container->registerAliasForArgument($serviceId, ProviderInterface::class, "{$providerName}Provider"); + } } } } diff --git a/tests/App/config/packages/security.yaml b/tests/App/config/packages/security.yaml index 72567875..1830e035 100644 --- a/tests/App/config/packages/security.yaml +++ b/tests/App/config/packages/security.yaml @@ -12,7 +12,7 @@ security: security: false main: anonymous: true - lazy: true +# lazy: true # activate different ways to authenticate # https://symfony.com/doc/current/security.html#firewalls-authentication diff --git a/tests/Controller/ViewerControllerTest.php b/tests/Controller/ViewerControllerTest.php index 9993f98e..a56d7bc5 100644 --- a/tests/Controller/ViewerControllerTest.php +++ b/tests/Controller/ViewerControllerTest.php @@ -17,6 +17,7 @@ use Symfony\Component\BrowserKit\Cookie; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Symfony\Component\Security\Core\User\User; @@ -43,13 +44,6 @@ public function testListAuditsAnonymously(): void $this->login(); $crawler = $this->client->request('GET', '/audit'); - // asserts a specific 200 status code -// self::assertEquals(200, $this->client->getResponse()->getStatusCode(), 'Response status is 200'); -// self::assertEquals(Response::HTTP_OK, $this->client->getResponse()->getStatusCode(), 'Response status is 200'); - - // asserts that the response status code is 404 -// self::assertTrue($this->client->getResponse()->isNotFound(), 'Response status is 404'); - // asserts that the response status code is 2xx self::assertTrue($this->client->getResponse()->isSuccessful(), 'Response status is 2xx'); @@ -72,7 +66,7 @@ public function testListAuditsAnonymously(): void $cells = $row->filter('td'); self::assertSame(4, $cells->count(), 'Each row is composed of 4 cells.'); $cells->each(function ($cell, $cellIndex) use ($expected, $rowIndex): void { - self::assertSame($expected[$rowIndex][$cellIndex], $cell->text(), sprintf('Cell #%s of row #%s is ok.', $cellIndex, $rowIndex)); + self::assertSame($expected[$rowIndex][$cellIndex], trim($cell->text()), sprintf('Cell #%s of row #%s is ok.', $cellIndex, $rowIndex)); }); }); } @@ -106,7 +100,7 @@ public function testListAuditsWithRoleNotGrantedForAuthorAuditViewing(): void $cells = $row->filter('td'); self::assertSame(4, $cells->count(), 'Each row is composed of 4 cells.'); $cells->each(function ($cell, $cellIndex) use ($expected, $rowIndex): void { - self::assertSame($expected[$rowIndex][$cellIndex], $cell->text(), sprintf('Cell #%s of row #%s is ok.', $cellIndex, $rowIndex)); + self::assertSame($expected[$rowIndex][$cellIndex], trim($cell->text()), sprintf('Cell #%s of row #%s is ok.', $cellIndex, $rowIndex)); }); }); } @@ -141,7 +135,7 @@ public function testListAuditsWithRoleGrantedForAuthorAuditViewing(): void $cells = $row->filter('td'); self::assertSame(4, $cells->count(), 'Each row is composed of 4 cells.'); $cells->each(function ($cell, $cellIndex) use ($expected, $rowIndex): void { - self::assertSame($expected[$rowIndex][$cellIndex], $cell->text(), sprintf('Cell #%s of row #%s is ok.', $cellIndex, $rowIndex)); + self::assertSame($expected[$rowIndex][$cellIndex], trim($cell->text()), sprintf('Cell #%s of row #%s is ok.', $cellIndex, $rowIndex)); }); }); } @@ -322,6 +316,10 @@ private function fixRequestStack(): void private function createAndInitDoctrineProvider(): void { + if (3 === Kernel::MAJOR_VERSION) { + self::markTestSkipped('Test skipped for Symfony <= 3.4'); + } + if (!self::$booted) { $this->client = self::createClient(); // boots the Kernel and populates container } diff --git a/tests/DHAuditorBundleTest.php b/tests/DHAuditorBundleTest.php index 60deb51e..aec3331b 100644 --- a/tests/DHAuditorBundleTest.php +++ b/tests/DHAuditorBundleTest.php @@ -15,6 +15,7 @@ use Nyholm\BundleTest\BaseBundleTestCase; use Nyholm\BundleTest\CompilerPass\PublicServicePass; use Symfony\Bundle\SecurityBundle\SecurityBundle; +use Symfony\Component\HttpKernel\Kernel; /** * @internal @@ -31,6 +32,10 @@ protected function setUp(): void public function testInitBundle(): void { + if (3 === Kernel::MAJOR_VERSION) { + self::markTestSkipped('Test skipped for Symfony <= 3.4'); + } + $kernel = $this->createKernel(); $kernel->addConfigFile(__DIR__.'/Fixtures/Resources/config/dh_auditor.yaml'); diff --git a/tests/Twig/Extension/TwigExtensionTest.php b/tests/Twig/Extension/TwigExtensionTest.php index 6f3f6c56..2ce3f0b1 100644 --- a/tests/Twig/Extension/TwigExtensionTest.php +++ b/tests/Twig/Extension/TwigExtensionTest.php @@ -8,6 +8,7 @@ use Nyholm\BundleTest\BaseBundleTestCase; use Nyholm\BundleTest\CompilerPass\PublicServicePass; use Symfony\Bundle\SecurityBundle\SecurityBundle; +use Symfony\Component\HttpKernel\Kernel; /** * @internal @@ -18,6 +19,10 @@ final class TwigExtensionTest extends BaseBundleTestCase protected function setUp(): void { + if (3 === Kernel::MAJOR_VERSION) { + self::markTestSkipped('Test skipped for Symfony <= 3.4'); + } + parent::setUp(); // Make services public