From bdd6cd5ec6bcb69be5a566087701bbe8605ccf72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Tue, 3 Jul 2018 22:35:47 +0200 Subject: [PATCH] Allow to whitelist functions (#241) --- Makefile | 19 ++- README.md | 108 ++++++++++--- fixtures/set025/composer.json | 5 + fixtures/set025/composer.lock | 62 ++++++++ fixtures/set025/expected-output | 12 ++ fixtures/set025/main.php | 19 +++ fixtures/set025/scoper.inc.php | 19 +++ specs/func-declaration/global.php | 56 +++++++ specs/func-declaration/namespace.php | 60 ++++++++ specs/use/use-func.php | 3 +- src/Autoload/ScoperAutoloadGenerator.php | 115 +++++++++++--- ....php => WhitelistedFunctionCollection.php} | 2 +- .../FunctionIdentifierRecorder.php | 20 ++- src/PhpParser/TraverserFactory.php | 5 +- src/Whitelist.php | 14 +- .../Autoload/ScoperAutoloadGeneratorTest.php | 143 +++++++++++++++--- tests/MakefileE2ETest.php | 12 +- 17 files changed, 584 insertions(+), 90 deletions(-) create mode 100644 fixtures/set025/composer.json create mode 100644 fixtures/set025/composer.lock create mode 100644 fixtures/set025/expected-output create mode 100644 fixtures/set025/main.php create mode 100644 fixtures/set025/scoper.inc.php rename src/PhpParser/NodeVisitor/Collection/{UserGlobalFunctionCollection.php => WhitelistedFunctionCollection.php} (92%) diff --git a/Makefile b/Makefile index f6f0f6ec..61408903 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ tm: bin/phpunit .PHONY: e2e e2e: ## Run end-to-end tests -e2e: e2e_004 e2e_005 e2e_011 e2e_013 e2e_014 e2e_015 e2e_016 e2e_017 e2e_018 e2e_019 e2e_020 e2e_021 e2e_022 e2e_023 e2e_024 +e2e: e2e_004 e2e_005 e2e_011 e2e_013 e2e_014 e2e_015 e2e_016 e2e_017 e2e_018 e2e_019 e2e_020 e2e_021 e2e_022 e2e_023 e2e_024 e2e_025 PHPSCOPER=bin/php-scoper.phar @@ -238,6 +238,20 @@ e2e_024: bin/php-scoper.phar fixtures/set024/vendor php build/set024/main.php > build/set024/output diff fixtures/set024/expected-output build/set024/output +.PHONY: e2e_025 +e2e_025: ## Run end-to-end tests for the fixture set 025 — Whitelisting a vendor function +e2e_025: bin/php-scoper.phar fixtures/set025/vendor + $(PHPNOGC) $(PHPSCOPER) add-prefix \ + --working-dir=fixtures/set025 \ + --output-dir=../../build/set025 \ + --force \ + --no-interaction \ + --stop-on-failure + composer --working-dir=build/set025 dump-autoload + + php build/set025/main.php > build/set025/output + diff fixtures/set025/expected-output build/set025/output + .PHONY: tb BLACKFIRE=blackfire @@ -358,6 +372,9 @@ fixtures/set023/composer.lock: fixtures/set023/composer.json fixtures/set024/composer.lock: fixtures/set024/composer.json @echo fixtures/set024/composer.lock is not up to date. +fixtures/set025/composer.lock: fixtures/set025/composer.json + @echo fixtures/set025/composer.lock is not up to date. + bin/php-scoper.phar: bin/php-scoper src vendor scoper.inc.php box.json $(BOX) compile touch $@ diff --git a/README.md b/README.md index 7eec35f8..b6194e76 100644 --- a/README.md +++ b/README.md @@ -38,9 +38,13 @@ potentially very difficult to debug due to dissimilar or unsupported package ver - [Finders and paths](#finders-and-paths) - [Patchers](#patchers) - [Whitelist][whitelist] - - [Constants from the global namespace whitelisting](#constants-from-the-global-namespace-whitelisting) - - [Classes & Constants whitelisting](#classes--constants-whitelisting) - - [Global user functions](#global-user-functions) + - [Constants & functions from the global namespace](#constants--functions-from-the-global-namespace) + - [Symbols](#symbols) + - [Caveats](#caveats) + - [Implementation insights](#implementation-insights) + - [Class whitelisting](#class-whitelisting) + - [Constants whitelisting](#constants-whitelisting) + - [Functions whitelisting](#functions-whitelisting) - [Namespaces whitelisting](#namespaces-whitelisting) - [Building a scoped PHAR](#building-a-scoped-phar) - [With Box](#with-box) @@ -266,11 +270,11 @@ a PHPUnit PHAR with isolated code, you still want the PHAR to be able to understand the `PHPUnit\Framework\TestCase` class. -### Constants from the global namespace whitelisting +### Constants & functions from the global namespace -By default, PHP-Scoper will not prefix the user defined constants belonging to -the global namespace. You can however change that setting for them to be -prefixed as usual unless explicitely whitelisted: +By default, PHP-Scoper will not prefix the user defined constants and functions +belonging to the global namespace. You can however change that setting for them +to be prefixed as usual unless explicitly whitelisted: ```php false, + 'whitelist-global-functions' => false, ]; ``` -### Classes & Constants whitelisting +### Symbols -You can whitelist classes, interfaces and constants like so like so: +You can whitelist classes, interfaces, constants and functions like so like so: ```php [ 'PHPUnit\Framework\TestCase', 'PHPUNIT_VERSION', + 'iter\count', ], ]; ``` -This will _not_ work on traits or functions. +#### Caveats + +This will _not_ work on traits and this alias mechanism is case insensitive, i.e. +when passing `'iter\count'`, if a class `Iter\Count` is found, this class will +also be whitelisted. + + +#### Implementation insights + +##### Class whitelisting The class aliasing mechanism is done like follows: - Prefix the class or interface as usual @@ -316,31 +331,78 @@ dumped in `vendor/scoper-autoload.php`, do not forget to include this file in favour of `vendor/autoload.php`. This part is however sorted out by [Box][box] if you are using it with the [`PhpScoper` compactor][php-scoper-integration]. +So if you have the following file with a whitelisted class: + +```php + true, -]; +namespace Humbug\Acme; + +\define('FOO', 'X'); ``` -So when you declare a function like so: +##### Functions whitelisting + +The function aliasing mechanism is done by declaring the original function +as an alias of the prefixed one in the `vendor/scoper-autoload.php` file. + +Given the following file with a function declaration: ```php =5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0|~5.0" + }, + "type": "library", + "autoload": { + "files": [ + "src/bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov", + "email": "nikic@php.net" + } + ], + "description": "Iteration primitives using generators", + "keywords": [ + "functional", + "generator", + "iterator" + ], + "time": "2017-11-10T22:56:03+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [] +} diff --git a/fixtures/set025/expected-output b/fixtures/set025/expected-output new file mode 100644 index 00000000..66ff4f06 --- /dev/null +++ b/fixtures/set025/expected-output @@ -0,0 +1,12 @@ +array(5) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(4) + [4]=> + int(5) +} diff --git a/fixtures/set025/main.php b/fixtures/set025/main.php new file mode 100644 index 00000000..4f58a08f --- /dev/null +++ b/fixtures/set025/main.php @@ -0,0 +1,19 @@ +, + * Pádraic Brady + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +return [ + 'whitelist' => [ + 'iter\RANGE', // Use a case mismatch on purpose: function references should be case insensitive + ], +]; diff --git a/specs/func-declaration/global.php b/specs/func-declaration/global.php index a5fe3cbb..dbdafe7a 100644 --- a/specs/func-declaration/global.php +++ b/specs/func-declaration/global.php @@ -22,6 +22,62 @@ 'whitelist-global-functions' => true, ], + 'Simple function declaration' => <<<'PHP' + [ + 'whitelist' => ['foo'], + 'payload' => <<<'PHP' + [ + 'whitelist-global-functions' => false, + 'whitelist' => ['foo'], + 'payload' => <<<'PHP' + <<<'SPEC' Function declaration in the global namespace: diff --git a/specs/func-declaration/namespace.php b/specs/func-declaration/namespace.php index dbc8092e..aeeeca47 100644 --- a/specs/func-declaration/namespace.php +++ b/specs/func-declaration/namespace.php @@ -22,6 +22,66 @@ 'whitelist-global-functions' => true, ], + 'Simple function declaration' => <<<'PHP' + [ + 'whitelist' => ['Acme\foo'], + 'payload' => <<<'PHP' + [ + 'whitelist-global-functions' => false, + 'whitelist' => ['foo'], + 'payload' => <<<'PHP' + <<<'SPEC' Function declaration in a namespace: diff --git a/specs/use/use-func.php b/specs/use/use-func.php index 85ca09d5..da09d9d5 100644 --- a/specs/use/use-func.php +++ b/specs/use/use-func.php @@ -131,8 +131,7 @@ [ 'spec' => <<<'SPEC' -Use statement for a namespaced function which has been whitelisted: -- prefix the use statement: the whitelist only works for classes +Use statement for a namespaced function which has been whitelisted SPEC , 'whitelist' => ['Foo\bar'], diff --git a/src/Autoload/ScoperAutoloadGenerator.php b/src/Autoload/ScoperAutoloadGenerator.php index 794ab13f..620ece92 100644 --- a/src/Autoload/ScoperAutoloadGenerator.php +++ b/src/Autoload/ScoperAutoloadGenerator.php @@ -14,14 +14,16 @@ namespace Humbug\PhpScoper\Autoload; -use Humbug\PhpScoper\PhpParser\NodeVisitor\Collection\UserGlobalFunctionCollection; +use Humbug\PhpScoper\PhpParser\NodeVisitor\Collection\WhitelistedFunctionCollection; use Humbug\PhpScoper\Whitelist; use PhpParser\Node\Name\FullyQualified; use const PHP_EOL; use function array_map; use function array_unshift; +use function count; use function iterator_to_array; use function sprintf; +use function str_repeat; use function str_replace; final class ScoperAutoloadGenerator @@ -35,12 +37,32 @@ public function __construct(Whitelist $whitelist) public function dump(string $prefix): string { - $classAliasStatements = $this->createClassAliasStatements($prefix); + $whitelistedFunctions = $this->whitelist->getWhitelistedFunctions(); - $statements = implode(PHP_EOL, $classAliasStatements).PHP_EOL.PHP_EOL; - $statements .= implode(PHP_EOL, $this->createFunctionAliasStatements($this->whitelist->getUserGlobalFunctions())); + $hasNamespacedFunctions = $this->hasNamespacedFunctions($whitelistedFunctions); - $dump = <<createClassAliasStatements($prefix, $hasNamespacedFunctions)).PHP_EOL.PHP_EOL; + $statements .= implode(PHP_EOL, $this->createFunctionAliasStatements($whitelistedFunctions, $hasNamespacedFunctions)); + + if ($hasNamespacedFunctions) { + $dump = <<cleanAutoload($dump); return $dump; } @@ -65,7 +84,7 @@ public function dump(string $prefix): string /** * @return string[] */ - public function createClassAliasStatements(string $prefix): array + private function createClassAliasStatements(string $prefix, bool $hasNamespacedFunctions): array { $statements = array_map( function (string $whitelistedElement) use ($prefix): string { @@ -82,11 +101,23 @@ function (string $whitelistedElement) use ($prefix): string { return $statements; } + if ($hasNamespacedFunctions) { + $statements = array_map( + function (string $statement): string { + return str_repeat(' ', 4).$statement; + }, + $statements + ); + + array_unshift($statements, 'namespace {'); + $statements[] = '}'.PHP_EOL; + } + array_unshift( $statements, <<<'EOF' // Aliases for the whitelisted classes. For more information see: -// https://github.com/humbug/php-scoper/blob/master/README.md#classes--constants-whitelisting +// https://github.com/humbug/php-scoper/blob/master/README.md#class-whitelisting EOF ); @@ -96,16 +127,39 @@ function (string $whitelistedElement) use ($prefix): string { /** * @return string[] */ - public function createFunctionAliasStatements(UserGlobalFunctionCollection $userGlobalFunctions): array - { + private function createFunctionAliasStatements( + WhitelistedFunctionCollection $whitelistedFunctions, + bool $hasNamespacedFunctions + ): array { $statements = array_map( - function (array $node): string { + function (array $node) use ($hasNamespacedFunctions): string { /** * @var FullyQualified * @var FullyQualified $alias */ [$original, $alias] = $node; + if ($hasNamespacedFunctions) { + $namespace = $original->slice(0, -1); + + return sprintf( + <<<'PHP' +namespace %s{ + if (!function_exists('%s')) { + function %s() { + return \%s(...func_get_args()); + } + } +} +PHP + , + null === $namespace ? '' : $namespace->toString().' ', + $original->toString(), + null === $namespace ? $original->toString() : $original->slice(1)->toString(), + $alias->toString() + ); + } + return sprintf( <<<'PHP' if (!function_exists('%1$s')) { @@ -119,7 +173,7 @@ function %1$s() { $alias->toString() ); }, - iterator_to_array($userGlobalFunctions) + iterator_to_array($whitelistedFunctions) ); if ([] === $statements) { @@ -130,10 +184,37 @@ function %1$s() { $statements, <<<'EOF' // Functions whitelisting. For more information see: -// https://github.com/humbug/php-scoper/blob/master/README.md#global-user-functions +// https://github.com/humbug/php-scoper/blob/master/README.md#functions-whitelisting EOF ); return $statements; } + + private function hasNamespacedFunctions(WhitelistedFunctionCollection $functions): bool + { + foreach ($functions as [$original, $alias]) { + /** + * @var FullyQualified + * @var FullyQualified $alias + */ + if (count($original->parts) > 1) { + return true; + } + } + + return false; + } + + private function cleanAutoload(string $dump): string + { + $cleanedDump = $dump; + + do { + $dump = $cleanedDump; + $cleanedDump = str_replace("\n\n\n", "\n\n", $dump); + } while ($cleanedDump !== $dump); + + return $dump; + } } diff --git a/src/PhpParser/NodeVisitor/Collection/UserGlobalFunctionCollection.php b/src/PhpParser/NodeVisitor/Collection/WhitelistedFunctionCollection.php similarity index 92% rename from src/PhpParser/NodeVisitor/Collection/UserGlobalFunctionCollection.php rename to src/PhpParser/NodeVisitor/Collection/WhitelistedFunctionCollection.php index e2d39b8c..c22e56b9 100644 --- a/src/PhpParser/NodeVisitor/Collection/UserGlobalFunctionCollection.php +++ b/src/PhpParser/NodeVisitor/Collection/WhitelistedFunctionCollection.php @@ -20,7 +20,7 @@ use PhpParser\Node\Name\FullyQualified; use function count; -final class UserGlobalFunctionCollection implements IteratorAggregate, Countable +final class WhitelistedFunctionCollection implements IteratorAggregate, Countable { /** * @var FullyQualified[][] diff --git a/src/PhpParser/NodeVisitor/FunctionIdentifierRecorder.php b/src/PhpParser/NodeVisitor/FunctionIdentifierRecorder.php index 63d585b2..30e27a59 100644 --- a/src/PhpParser/NodeVisitor/FunctionIdentifierRecorder.php +++ b/src/PhpParser/NodeVisitor/FunctionIdentifierRecorder.php @@ -69,20 +69,18 @@ public function enterNode(Node $node): Node ); $resolvedName = $resolvedValue->getName(); - if (null !== $resolvedValue->getNamespace() - || false === ($resolvedName instanceof FullyQualified) - || count($resolvedName->parts) > 1 + if ($resolvedName instanceof FullyQualified + && ( + (1 === count($resolvedName->parts) && $this->whitelist->whitelistGlobalFunctions()) + || $this->whitelist->isClassWhitelisted((string) $resolvedName) + ) ) { - return $node; + $this->whitelist->recordWhitelistedFunction( + $resolvedName, + FullyQualified::concat($this->prefix, $resolvedName) + ); } - /* @var FullyQualified $resolvedName */ - - $this->whitelist->recordUserGlobalFunction( - $resolvedName, - FullyQualified::concat($this->prefix, $resolvedName) - ); - return $node; } } diff --git a/src/PhpParser/TraverserFactory.php b/src/PhpParser/TraverserFactory.php index d7408ad7..a76e6e8c 100644 --- a/src/PhpParser/TraverserFactory.php +++ b/src/PhpParser/TraverserFactory.php @@ -49,10 +49,7 @@ public function create(string $prefix, Whitelist $whitelist): NodeTraverserInter $traverser->addVisitor(new NodeVisitor\UseStmt\UseStmtCollector($namespaceStatements, $useStatements)); $traverser->addVisitor(new NodeVisitor\UseStmt\UseStmtPrefixer($prefix, $whitelist, $this->reflector)); - if ($whitelist->whitelistGlobalFunctions()) { - $traverser->addVisitor(new NodeVisitor\FunctionIdentifierRecorder($prefix, $nameResolver, $whitelist)); - } - + $traverser->addVisitor(new NodeVisitor\FunctionIdentifierRecorder($prefix, $nameResolver, $whitelist)); $traverser->addVisitor(new NodeVisitor\NameStmtPrefixer($prefix, $whitelist, $nameResolver, $this->reflector)); $traverser->addVisitor(new NodeVisitor\StringScalarPrefixer($prefix, $whitelist, $this->reflector)); diff --git a/src/Whitelist.php b/src/Whitelist.php index 469059fe..d9e259df 100644 --- a/src/Whitelist.php +++ b/src/Whitelist.php @@ -15,7 +15,7 @@ namespace Humbug\PhpScoper; use Countable; -use Humbug\PhpScoper\PhpParser\NodeVisitor\Collection\UserGlobalFunctionCollection; +use Humbug\PhpScoper\PhpParser\NodeVisitor\Collection\WhitelistedFunctionCollection; use InvalidArgumentException; use PhpParser\Node\Name\FullyQualified; use function array_filter; @@ -39,7 +39,7 @@ final class Whitelist implements Countable private $namespaces; private $whitelistGlobalConstants; private $whitelistGlobalFunctions; - private $userGlobalFunctions; + private $whitelistedFunctions; public static function create(bool $whitelistGlobalConstants, bool $whitelistGlobalFunctions, string ...$elements): self { @@ -104,17 +104,17 @@ private function __construct( $this->classes = $classes; $this->constants = $constants; $this->namespaces = $namespaces; - $this->userGlobalFunctions = new UserGlobalFunctionCollection(); + $this->whitelistedFunctions = new WhitelistedFunctionCollection(); } - public function recordUserGlobalFunction(FullyQualified $original, FullyQualified $alias): void + public function recordWhitelistedFunction(FullyQualified $original, FullyQualified $alias): void { - $this->userGlobalFunctions->add($original, $alias); + $this->whitelistedFunctions->add($original, $alias); } - public function getUserGlobalFunctions(): UserGlobalFunctionCollection + public function getWhitelistedFunctions(): WhitelistedFunctionCollection { - return $this->userGlobalFunctions; + return $this->whitelistedFunctions; } public function whitelistGlobalConstants(): bool diff --git a/tests/Autoload/ScoperAutoloadGeneratorTest.php b/tests/Autoload/ScoperAutoloadGeneratorTest.php index e34d797e..2171b39d 100644 --- a/tests/Autoload/ScoperAutoloadGeneratorTest.php +++ b/tests/Autoload/ScoperAutoloadGeneratorTest.php @@ -60,7 +60,7 @@ public function provideWhitelists() $loader = require_once __DIR__.'/autoload.php'; // Aliases for the whitelisted classes. For more information see: -// https://github.com/humbug/php-scoper/blob/master/README.md#classes--constants-whitelisting +// https://github.com/humbug/php-scoper/blob/master/README.md#class-whitelisting class_exists('Humbug\A\Foo'); class_exists('Humbug\B\Bar'); @@ -73,12 +73,12 @@ class_exists('Humbug\B\Bar'); (function () { $whitelist = Whitelist::create(true, true); - $whitelist->recordUserGlobalFunction( + $whitelist->recordWhitelistedFunction( new FullyQualified('foo'), new FullyQualified('Humbug\foo') ); - $whitelist->recordUserGlobalFunction( + $whitelist->recordWhitelistedFunction( new FullyQualified('bar'), new FullyQualified('Humbug\bar') ); @@ -93,7 +93,7 @@ class_exists('Humbug\B\Bar'); $loader = require_once __DIR__.'/autoload.php'; // Functions whitelisting. For more information see: -// https://github.com/humbug/php-scoper/blob/master/README.md#global-user-functions +// https://github.com/humbug/php-scoper/blob/master/README.md#functions-whitelisting if (!function_exists('foo')) { function foo() { return \Humbug\foo(...func_get_args()); @@ -107,6 +107,67 @@ function bar() { return $loader; +PHP + ]; + + yield [ + (function () { + $whitelist = Whitelist::create(true, true); + + $whitelist->recordWhitelistedFunction( + new FullyQualified('Acme\foo'), + new FullyQualified('Humbug\Acme\foo') + ); + + $whitelist->recordWhitelistedFunction( + new FullyQualified('Acme\bar'), + new FullyQualified('Humbug\Acme\bar') + ); + + $whitelist->recordWhitelistedFunction( + new FullyQualified('Emca\baz'), + new FullyQualified('Humbug\Emca\baz') + ); + + return $whitelist; + })(), + <<<'PHP' +recordUserGlobalFunction( + $whitelist->recordWhitelistedFunction( new FullyQualified('foo'), new FullyQualified('Humbug\foo') ); - $whitelist->recordUserGlobalFunction( + $whitelist->recordWhitelistedFunction( new FullyQualified('bar'), new FullyQualified('Humbug\bar') ); + $whitelist->recordWhitelistedFunction( + new FullyQualified('Acme\foo'), + new FullyQualified('Humbug\Acme\foo') + ); + + $whitelist->recordWhitelistedFunction( + new FullyQualified('Acme\bar'), + new FullyQualified('Humbug\Acme\bar') + ); + + $whitelist->recordWhitelistedFunction( + new FullyQualified('Emca\baz'), + new FullyQualified('Humbug\Emca\baz') + ); + return $whitelist; })(), <<<'PHP' @@ -131,27 +207,58 @@ function bar() { // scoper-autoload.php @generated by PhpScoper -$loader = require_once __DIR__.'/autoload.php'; +namespace { + $loader = require_once __DIR__.'/autoload.php'; +} // Aliases for the whitelisted classes. For more information see: -// https://github.com/humbug/php-scoper/blob/master/README.md#classes--constants-whitelisting -class_exists('Humbug\A\Foo'); -class_exists('Humbug\B\Bar'); +// https://github.com/humbug/php-scoper/blob/master/README.md#class-whitelisting +namespace { + class_exists('Humbug\A\Foo'); + class_exists('Humbug\B\Bar'); +} // Functions whitelisting. For more information see: -// https://github.com/humbug/php-scoper/blob/master/README.md#global-user-functions -if (!function_exists('foo')) { - function foo() { - return \Humbug\foo(...func_get_args()); +// https://github.com/humbug/php-scoper/blob/master/README.md#functions-whitelisting +namespace { + if (!function_exists('foo')) { + function foo() { + return \Humbug\foo(...func_get_args()); + } } } -if (!function_exists('bar')) { - function bar() { - return \Humbug\bar(...func_get_args()); +namespace { + if (!function_exists('bar')) { + function bar() { + return \Humbug\bar(...func_get_args()); + } + } +} +namespace Acme { + if (!function_exists('Acme\foo')) { + function foo() { + return \Humbug\Acme\foo(...func_get_args()); + } + } +} +namespace Acme { + if (!function_exists('Acme\bar')) { + function bar() { + return \Humbug\Acme\bar(...func_get_args()); + } + } +} +namespace Emca { + if (!function_exists('Emca\baz')) { + function baz() { + return \Humbug\Emca\baz(...func_get_args()); + } } } -return $loader; +namespace { + return $loader; +} PHP ]; diff --git a/tests/MakefileE2ETest.php b/tests/MakefileE2ETest.php index 813a21c5..0ebaa6ed 100644 --- a/tests/MakefileE2ETest.php +++ b/tests/MakefileE2ETest.php @@ -29,20 +29,20 @@ */ class MakefileE2ETest extends TestCase { - public function test_the_e2e_test_executes_all_the_e2e_subsets() + public function test_the_e2e_test_executes_all_the_e2e_sub_rules() { $contents = file_get_contents(__DIR__.'/../Makefile'); - $e2e = $this->retrieveE2EStep($contents); - $sube2e = $this->retrieveE2ESubSteps($contents); + $mainE2ERule = $this->retrieveE2ERule($contents); + $e2eSubRules = $this->retrieveSubE2ERules($contents); - $this->assertSame($sube2e, $e2e); + $this->assertSame($e2eSubRules, $mainE2ERule); } /** * @return string[] */ - private function retrieveE2EStep(string $makefileContents): array + private function retrieveE2ERule(string $makefileContents): array { if (1 !== preg_match( '/e2e:(?[\p{L}\d_ ]+)/u', @@ -66,7 +66,7 @@ private function retrieveE2EStep(string $makefileContents): array /** * @return string[] */ - private function retrieveE2ESubSteps(string $makefileContents): array + private function retrieveSubE2ERules(string $makefileContents): array { if (1 !== preg_match_all( '/(?e2e_\d+):/u',