From 0eb55ef7a67390fd8f8ea85503bf1fc16f59e71e Mon Sep 17 00:00:00 2001 From: hanisko Date: Tue, 11 Jul 2023 17:05:11 +0200 Subject: [PATCH 1/6] Add new nette tester options - php_ini_configuration_path - default_php_ini_configuration --- doc/tasks/tester.md | 14 ++++++++++++++ src/Task/Tester.php | 6 ++++++ test/Unit/Task/TesterTest.php | 25 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/doc/tasks/tester.md b/doc/tasks/tester.md index a8eff8f25..d1fb799ce 100644 --- a/doc/tasks/tester.md +++ b/doc/tasks/tester.md @@ -29,6 +29,8 @@ grumphp: colors: ~ coverage: ~ coverage_src: ~ + php_ini_configuration_path: null + load_php_ini_configuration: false ``` **path** @@ -102,3 +104,15 @@ Example: `coverage.html` or `coverage.xml` *Default: null* This is issued with the `coverage` option. This is a path to the source code for which we generate the report. + +**php_ini_configuration_path** + +*Default: null* + +The Tester runs PHP processes from custom php.ini file. + +**default_php_ini_configuration** + +*Default: false* + +When this option is set to `true`, Tester runs PHP processes with system configuration .ini files. diff --git a/src/Task/Tester.php b/src/Task/Tester.php index b17680776..2f50acd69 100644 --- a/src/Task/Tester.php +++ b/src/Task/Tester.php @@ -34,6 +34,8 @@ public static function getConfigurableOptions(): ConfigOptionsResolver 'colors' => null, 'coverage' => null, 'coverage_src' => null, + 'php_ini_configuration_path' => null, + 'default_php_ini_configuration' => false, ]); $resolver->addAllowedTypes('path', ['string']); @@ -48,6 +50,8 @@ public static function getConfigurableOptions(): ConfigOptionsResolver $resolver->addAllowedTypes('colors', ['null', 'int']); $resolver->addAllowedTypes('coverage', ['null', 'string']); $resolver->addAllowedTypes('coverage_src', ['null', 'string']); + $resolver->addAllowedTypes('php_ini_configuration_path', ['null', 'string']); + $resolver->addAllowedTypes('default_php_ini_configuration', ['bool']); return ConfigOptionsResolver::fromOptionsResolver($resolver); } @@ -80,6 +84,8 @@ public function run(ContextInterface $context): TaskResultInterface $arguments->addOptionalIntegerArgument('%s', $config['colors']); $arguments->addOptionalArgumentWithSeparatedValue('--coverage', $config['coverage']); $arguments->addOptionalArgumentWithSeparatedValue('--coverage-src', $config['coverage_src']); + $arguments->addOptionalArgumentWithSeparatedValue('-c', $config['php_ini_configuration_path']); + $arguments->addOptionalArgument('-C', $config['default_php_ini_configuration']); $process = $this->processBuilder->buildProcess($arguments); $process->run(); diff --git a/test/Unit/Task/TesterTest.php b/test/Unit/Task/TesterTest.php index f7a1174fc..e61822f6b 100644 --- a/test/Unit/Task/TesterTest.php +++ b/test/Unit/Task/TesterTest.php @@ -37,6 +37,8 @@ public function provideConfigurableOptions(): iterable 'colors' => null, 'coverage' => null, 'coverage_src' => null, + 'php_ini_configuration_path' => null, + 'default_php_ini_configuration' => false, ] ]; } @@ -255,5 +257,28 @@ public function provideExternalTaskRuns(): iterable 'coverageSrdFile', ] ]; + yield 'php_ini_configuration_path' => [ + [ + 'php_ini_configuration_path' => 'customPhpIniFile', + ], + $this->mockContext(RunContext::class, ['helloTest.php', 'hello2Test.php']), + 'tester', + [ + '.', + '-c', + 'customPhpIniFile', + ] + ]; + yield 'default_php_ini_configuration' => [ + [ + 'default_php_ini_configuration' => true, + ], + $this->mockContext(RunContext::class, ['helloTest.php', 'hello2Test.php']), + 'tester', + [ + '.', + '-C', + ] + ]; } } From 2f05fc5419fdf49248e89e8ac5cc20e1cd6ea3cc Mon Sep 17 00:00:00 2001 From: hanisko Date: Wed, 12 Jul 2023 08:55:49 +0200 Subject: [PATCH 2/6] fix coding-style --- src/Task/Tester.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Task/Tester.php b/src/Task/Tester.php index 2f50acd69..0f94b281a 100644 --- a/src/Task/Tester.php +++ b/src/Task/Tester.php @@ -50,7 +50,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver $resolver->addAllowedTypes('colors', ['null', 'int']); $resolver->addAllowedTypes('coverage', ['null', 'string']); $resolver->addAllowedTypes('coverage_src', ['null', 'string']); - $resolver->addAllowedTypes('php_ini_configuration_path', ['null', 'string']); + $resolver->addAllowedTypes('php_ini_configuration_path', ['null', 'string']); $resolver->addAllowedTypes('default_php_ini_configuration', ['bool']); return ConfigOptionsResolver::fromOptionsResolver($resolver); From 60fd39f8a3efae86263d4c71afdf8ce10af34356 Mon Sep 17 00:00:00 2001 From: hanisko Date: Wed, 12 Jul 2023 15:01:44 +0200 Subject: [PATCH 3/6] Fix psalm DeprecatedProperty error --- src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php b/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php index 089b61acf..364e521bb 100644 --- a/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php +++ b/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php @@ -41,7 +41,7 @@ public function leaveNode(Node $node): void return; } - $class = implode('\\', $node->class->parts); + $class = implode('\\', $node->class->getParts()); $method = $node->name; $normalized = sprintf('%s::%s', $class, $method); From f4bf8ac42d38470b314c0da59f6cdddbbbe41c8a Mon Sep 17 00:00:00 2001 From: hanisko Date: Wed, 12 Jul 2023 16:35:45 +0200 Subject: [PATCH 4/6] Fix psalm PossiblyUndefinedMethod error --- src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php b/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php index 364e521bb..88b963e19 100644 --- a/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php +++ b/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php @@ -37,7 +37,7 @@ public function configure(array $options): void */ public function leaveNode(Node $node): void { - if (!$node instanceof Node\Expr\StaticCall) { + if (!$node instanceof Node\Expr\StaticCall || !$node->class instanceof Node\Name) { return; } From a6df0f08db6d9ace4e8c657921f64c2ee970139c Mon Sep 17 00:00:00 2001 From: hanisko Date: Thu, 13 Jul 2023 14:33:57 +0200 Subject: [PATCH 5/6] Fix psalm UndefinedMethod for nikic/php-parser version < 4.16 --- src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php b/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php index 88b963e19..4a609a6ef 100644 --- a/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php +++ b/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php @@ -41,7 +41,10 @@ public function leaveNode(Node $node): void return; } - $class = implode('\\', $node->class->getParts()); + $class = implode( + '\\', + method_exists($node->class, 'getParts') ? $node->class->getParts() : $node->class->parts + ); $method = $node->name; $normalized = sprintf('%s::%s', $class, $method); From be375863f91832f21541c2a9fdd151048b9ba6c2 Mon Sep 17 00:00:00 2001 From: hanisko Date: Thu, 13 Jul 2023 16:03:32 +0200 Subject: [PATCH 6/6] Supress psalm DeprecatedProperty error --- .../Php/Visitor/ForbiddenStaticMethodCallsVisitor.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php b/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php index 4a609a6ef..7e4f7c50c 100644 --- a/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php +++ b/src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php @@ -41,10 +41,12 @@ public function leaveNode(Node $node): void return; } - $class = implode( - '\\', - method_exists($node->class, 'getParts') ? $node->class->getParts() : $node->class->parts - ); + /** + * https://github.com/nikic/PHP-Parser/releases/tag/v4.16.0 + * @psalm-suppress DeprecatedProperty + */ + $class = implode('\\', $node->class->parts); + $method = $node->name; $normalized = sprintf('%s::%s', $class, $method);