Skip to content

Commit

Permalink
Updated CI (#225)
Browse files Browse the repository at this point in the history
* Better locking of Symfony versions in CI

* Fix tests with Symfony 4.4

* Skipped some tests when using Symfony 3.4
  • Loading branch information
DamienHarper authored Dec 11, 2020
1 parent 1f104dd commit 3631812
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 17 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ composer.lock
*.sqlite
var/
/tests/App/.preload.php
/tests/App/cache/
1 change: 1 addition & 0 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -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')
)
;
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/DependencyInjection/DHAuditorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
}
2 changes: 1 addition & 1 deletion tests/App/config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions tests/Controller/ViewerControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');

Expand All @@ -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));
});
});
}
Expand Down Expand Up @@ -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));
});
});
}
Expand Down Expand Up @@ -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));
});
});
}
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions tests/DHAuditorBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Nyholm\BundleTest\BaseBundleTestCase;
use Nyholm\BundleTest\CompilerPass\PublicServicePass;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Component\HttpKernel\Kernel;

/**
* @internal
Expand All @@ -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');
Expand Down
5 changes: 5 additions & 0 deletions tests/Twig/Extension/TwigExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Nyholm\BundleTest\BaseBundleTestCase;
use Nyholm\BundleTest\CompilerPass\PublicServicePass;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Component\HttpKernel\Kernel;

/**
* @internal
Expand All @@ -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
Expand Down

0 comments on commit 3631812

Please sign in to comment.