-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Makefile test to an auto-review namespace (#777)
- Loading branch information
Showing
3 changed files
with
164 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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,95 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the humbug/php-scoper package. | ||
* | ||
* Copyright (c) 2017 Théo FIDRY <[email protected]>, | ||
* Pádraic Brady <[email protected]> | ||
* | ||
* 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 SplFileInfo; | ||
use Symfony\Component\Finder\Finder; | ||
use function array_filter; | ||
use function array_map; | ||
use function in_array; | ||
use function iterator_to_array; | ||
use function sort; | ||
use function substr; | ||
use const SORT_STRING; | ||
|
||
final class E2ECollector | ||
{ | ||
use NotInstantiable; | ||
|
||
private const E2E_DIR = __DIR__.'/../../fixtures'; | ||
|
||
private const NON_E2E_TESTS = [ | ||
'set000', | ||
'set001', | ||
'set002', | ||
'set003', | ||
'set006', | ||
'set007', | ||
'set008', | ||
'set009', | ||
'set010', | ||
'set012', | ||
]; | ||
|
||
/** | ||
* @return list<string> | ||
*/ | ||
public static function getE2ENames(): array | ||
{ | ||
static $names; | ||
|
||
if (!isset($names)) { | ||
$names = self::findE2ENames(); | ||
} | ||
|
||
return $names; | ||
} | ||
|
||
/** | ||
* @return list<string> | ||
*/ | ||
private static function findE2ENames(): array | ||
{ | ||
$finder = Finder::create() | ||
->directories() | ||
->in(self::E2E_DIR) | ||
->depth(0); | ||
|
||
$names = array_filter( | ||
array_map( | ||
self::extractName(...), | ||
iterator_to_array($finder, false), | ||
), | ||
); | ||
|
||
sort($names, SORT_STRING); | ||
|
||
return $names; | ||
} | ||
|
||
private static function extractName(SplFileInfo $fileInfo): ?string | ||
{ | ||
$filename = $fileInfo->getFilename(); | ||
|
||
if (in_array($filename, self::NON_E2E_TESTS, true)) { | ||
return null; | ||
} | ||
|
||
$setNumber = substr($filename, 3, 3); | ||
|
||
return 'e2e_'.$setNumber; | ||
} | ||
} |
This file contains 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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the humbug/php-scoper package. | ||
* | ||
* Copyright (c) 2017 Théo FIDRY <[email protected]>, | ||
* Pádraic Brady <[email protected]> | ||
* | ||
* 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; | ||
use function in_array; | ||
|
||
/** | ||
* @covers \Humbug\PhpScoper\AutoReview\E2ECollector | ||
* | ||
* @internal | ||
*/ | ||
class E2ECollectorTest extends TestCase | ||
{ | ||
public function test_it_collects_the_e2e_test_names(): void | ||
{ | ||
$names = E2ECollector::getE2ENames(); | ||
|
||
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 = E2ECollector::getE2ENames(); | ||
|
||
self::assertFalse(in_array('e2e_000', $names, true)); | ||
} | ||
} |
This file contains 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