Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add new nette tester options #1097

Merged
merged 6 commits into from
Jul 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/tasks/tester.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ grumphp:
colors: ~
coverage: ~
coverage_src: ~
php_ini_configuration_path: null
load_php_ini_configuration: false
```

**path**
Expand Down Expand Up @@ -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.
7 changes: 6 additions & 1 deletion src/Parser/Php/Visitor/ForbiddenStaticMethodCallsVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,16 @@ 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;
}

/**
* https://github.com/nikic/PHP-Parser/releases/tag/v4.16.0
* @psalm-suppress DeprecatedProperty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets do it like that for now.

*/
$class = implode('\\', $node->class->parts);

$method = $node->name;
$normalized = sprintf('%s::%s', $class, $method);

Expand Down
6 changes: 6 additions & 0 deletions src/Task/Tester.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
25 changes: 25 additions & 0 deletions test/Unit/Task/TesterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]
];
}
Expand Down Expand Up @@ -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',
]
];
}
}