Skip to content

Add test to ensure all the e2e tests are listed in the GitHub Actions workflow #778

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ jobs:
- 'e2e_030'
- 'e2e_031'
- 'e2e_032'
- 'e2e_033'
- 'e2e_034'
php:
- '8.1'

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"ergebnis/composer-normalize": "^2.28",
"humbug/box": "^4.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.0"
"phpunit/phpunit": "^9.0",
"symfony/yaml": "^6.1"
},
"replace": {
"symfony/polyfill-php73": "*"
Expand Down
76 changes: 75 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,5 @@ parameters:
path: 'src/Scoper/SymfonyScoper.php'
- message: '#Class Isolated\\Symfony\\Component\\Finder\\Finder not found\.#'
path: 'tests/Configuration/DefaultConfigurationTest.php'
- message: '#Cannot access offset#'
path: 'tests/AutoReview/GAE2ECollector.php'
3 changes: 1 addition & 2 deletions tests/AutoReview/E2ECollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use PHPUnit\Framework\TestCase;
use function count;
use function in_array;

/**
* @covers \Humbug\PhpScoper\AutoReview\E2ECollector
Expand All @@ -40,6 +39,6 @@ public function test_it_ignores_non_e2e_tests(): void
{
$names = E2ECollector::getE2ENames();

self::assertFalse(in_array('e2e_000', $names, true));
self::assertNotContains('e2e_000', $names);
}
}
56 changes: 56 additions & 0 deletions tests/AutoReview/GAE2ECollector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/*
* This file is part of the humbug/php-scoper package.
*
* Copyright (c) 2017 Théo FIDRY <theo.fidry@gmail.com>,
* Pádraic Brady <padraic.brady@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Humbug\PhpScoper\AutoReview;

use Humbug\PhpScoper\NotInstantiable;
use Symfony\Component\Yaml\Yaml;
use function sort;
use const SORT_STRING;

final class GAE2ECollector
{
use NotInstantiable;

private const GA_FILE = __DIR__.'/../../.github/workflows/e2e-tests.yaml';

/**
* @return list<string>
*/
public static function getExecutedE2ETests(): array
{
static $names;

if (!isset($names)) {
$names = self::findE2ENames();
}

return $names;
}

/**
* @return list<string>
*/
private static function findE2ENames(): array
{
$parsedYaml = Yaml::parseFile(self::GA_FILE);

/** @var string[] $names */
$names = $parsedYaml['jobs']['e2e-tests']['strategy']['matrix']['e2e'];

sort($names, SORT_STRING);

return $names;
}
}
44 changes: 44 additions & 0 deletions tests/AutoReview/GAE2ECollectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

/*
* This file is part of the humbug/php-scoper package.
*
* Copyright (c) 2017 Théo FIDRY <theo.fidry@gmail.com>,
* Pádraic Brady <padraic.brady@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Humbug\PhpScoper\AutoReview;

use PHPUnit\Framework\TestCase;
use function count;

/**
* @covers \Humbug\PhpScoper\AutoReview\GAE2ECollector
*
* @internal
*/
class GAE2ECollectorTest extends TestCase
{
public function test_it_collects_the_e2e_test_names(): void
{
$names = GAE2ECollector::getExecutedE2ETests();

self::assertGreaterThan(0, count($names));

foreach ($names as $name) {
self::assertMatchesRegularExpression('/^e2e_\d{3}$/', $name);
}
}

public function test_it_ignores_non_e2e_tests(): void
{
$names = GAE2ECollector::getExecutedE2ETests();

self::assertNotContains('e2e_000', $names);
}
}
33 changes: 33 additions & 0 deletions tests/AutoReview/GAE2ETest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

/*
* This file is part of the humbug/php-scoper package.
*
* Copyright (c) 2017 Théo FIDRY <theo.fidry@gmail.com>,
* Pádraic Brady <padraic.brady@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Humbug\PhpScoper\AutoReview;

use PHPUnit\Framework\TestCase;

/**
* @coversNothing
*
* @internal
*/
class GAE2ETest extends TestCase
{
public function test_github_actions_executes_all_the_e2e_tests(): void
{
$expected = E2ECollector::getE2ENames();
$actual = GAE2ECollector::getExecutedE2ETests();

self::assertEqualsCanonicalizing($expected, $actual);
}
}