Add PHPStan by TavoNiievez · Pull Request #6851 · Codeception/Codeception · GitHub
Skip to content
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
84 changes: 48 additions & 36 deletions .github/workflows/build.yml
28 changes: 17 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
"behat/gherkin": "^4.12",
"codeception/lib-asserts": "^2.2",
"codeception/stub": "^4.1",
"phpunit/phpunit": "^9.5.20 || ^10.0 || ^11.0 || ^12.0",
"phpunit/php-code-coverage": "^9.2 || ^10.0 || ^11.0 || ^12.0",
"phpunit/php-text-template": "^2.0 || ^3.0 || ^4.0 || ^5.0",
"phpunit/php-timer": "^5.0.3 || ^6.0 || ^7.0 || ^8.0",
"sebastian/comparator": "^4.0.5 || ^5.0 || ^6.0 || ^7.0",
"sebastian/diff": "^4.0.3 || ^5.0 || ^6.0 || ^7.0",
"phpunit/php-code-coverage": "^9.2 | ^10.0 | ^11.0 | ^12.0",
"phpunit/php-text-template": "^2.0 | ^3.0 | ^4.0 | ^5.0",
"phpunit/php-timer": "^5.0.3 | ^6.0 | ^7.0 | ^8.0",
"phpunit/phpunit": "^9.5.20 | ^10.0 | ^11.0 | ^12.0",
"psy/psysh": "^0.11.2 | ^0.12",
"sebastian/comparator": "^4.0.5 | ^5.0 | ^6.0 | ^7.0",
"sebastian/diff": "^4.0.3 | ^5.0 | ^6.0 | ^7.0",
"symfony/console": ">=5.4.24 <8.0",
"symfony/css-selector": ">=5.4.24 <8.0",
"symfony/event-dispatcher": ">=5.4.24 <8.0",
"symfony/finder": ">=5.4.24 <8.0",
"symfony/yaml": ">=5.4.24 <8.0",
"symfony/var-dumper": ">=5.4.24 <8.0",
"psy/psysh": "^0.11.2 || ^0.12"
"symfony/yaml": ">=5.4.24 <8.0"
},
"require-dev": {
"ext-simplexml": "*",
Expand All @@ -45,11 +45,17 @@
"codeception/module-db": "*@dev",
"codeception/module-filesystem": "*@dev",
"codeception/module-phpbrowser": "*@dev",
"codeception/module-webdriver": "*@dev",
"codeception/util-universalframework": "*@dev",
"symfony/process": ">=5.4.24 <8.0",
"doctrine/orm": "^3.3",
"jetbrains/phpstorm-attributes": "^1.0",
"laravel-zero/phar-updater": "^1.4",
"php-webdriver/webdriver": "^1.15",
"stecman/symfony-console-completion": "^0.14",
"symfony/dotenv": ">=5.4.24 <8.0",
"vlucas/phpdotenv": "^5.1",
"jetbrains/phpstorm-attributes": "^1.0"
"symfony/error-handler": ">=5.4.24 <8.0",
"symfony/process": ">=5.4.24 <8.0",
"vlucas/phpdotenv": "^5.1"
},
"conflict": {
"codeception/lib-innerbrowser": "<3.1.3",
Expand Down
25 changes: 25 additions & 0 deletions ext/SuiteInitSubscriberTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Codeception\Extension;

use Codeception\Events;

use function is_array;

trait SuiteInitSubscriberTrait
{
public static function getSubscribedEvents(): array
{
$events = property_exists(static::class, 'events') && is_array(static::$events)
? static::$events
: [];

$suiteInit = (array) ($events[Events::SUITE_INIT] ?? []);
$suiteInit[] = 'receiveModuleContainer';
$events[Events::SUITE_INIT] = $suiteInit;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

see #6861


return $events;
}
}
18 changes: 18 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
parameters:
level: 1

paths:
- src

excludePaths:
analyseAndScan:
- src/Codeception/Test/Cest.php
- src/Codeception/Test/Test.php
- src/Codeception/Test/Unit.php
- src/Codeception/Coverage/Subscriber/Printer.php
- src/PHPUnit/Wrapper/PhpUnit9/Test.php

parallel:
maximumNumberOfProcesses: 8
minimumNumberOfJobsPerProcess: 2
jobSize: 20
14 changes: 2 additions & 12 deletions src/Codeception/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,14 @@ public function registerCustomCommands(): void
if ($e->getCode() === 404) {
return;
}
$this->renderExceptionWrapper($e, $output);
parent::renderThrowable($e, $output);
exit(1);
} catch (Exception $e) {
$this->renderExceptionWrapper($e, $output);
parent::renderThrowable($e, $output);
exit(1);
}
}

public function renderExceptionWrapper(Exception $exception, OutputInterface $output): void
{
if (method_exists(BaseApplication::class, 'renderException')) {
//Symfony 5
parent::renderException($exception, $output);
} else {
parent::renderThrowable($exception, $output);
}
}

/**
* Search custom commands and register them.
*
Expand Down
17 changes: 3 additions & 14 deletions src/Codeception/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

use Codeception\Event\SuiteEvent;
use Codeception\Exception\ModuleRequireException;
use Codeception\Extension\SuiteInitSubscriberTrait;
use Codeception\Lib\Console\Output;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

use function array_keys;
use function array_merge;
use function is_array;

/**
* A base class for all Codeception Extensions and GroupObjects
Expand All @@ -23,6 +23,8 @@
*/
abstract class Extension implements EventSubscriberInterface
{
use SuiteInitSubscriberTrait;

/**
* @var array<int|string, mixed>
*/
Expand All @@ -44,19 +46,6 @@ public function __construct(array $config, protected array $options)
$this->_initialize();
}

public static function getSubscribedEvents(): array
{
$events = property_exists(static::class, 'events') && is_array(static::$events)
? static::$events
: [];

$suiteInit = (array) ($events[Events::SUITE_INIT] ?? []);
$suiteInit[] = 'receiveModuleContainer';
$events[Events::SUITE_INIT] = $suiteInit;

return $events;
}

public function receiveModuleContainer(SuiteEvent $event): void
{
$this->modules = $event->getSuite()->getModules();
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Lib/Di.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function instantiate(
$constructorArgs ??= $this->prepareArgs($reflectedClass->getConstructor());

try {
$object = $reflectedClass->newInstanceArgs($constructorArgs ?? []);
$object = $reflectedClass->newInstanceArgs($constructorArgs);
} catch (ReflectionException $e) {
throw new InjectionException("Failed to create instance of '{$className}'. " . $e->getMessage());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Lib/ParamsLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function load(array|string $paramStorage): array
}
}

throw new ConfigurationException("Params can't be loaded from `{$paramFile}`.");
throw new ConfigurationException("Params can't be loaded from `{$paramsFile}`.");
}

/**
Expand Down
5 changes: 4 additions & 1 deletion src/Codeception/Reporter/JUnitReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,10 @@ private function addFault(Test $test, Throwable $t, string $type): void
$buffer = '';
}

if (PHPUnitVersion::series() < 10) {
if (
version_compare(PHPUnitVersion::series(), '10.0', '<')
&& class_exists(TestFailure::class)
) {
$exceptionString = TestFailure::exceptionToString($t);
} else {
$exceptionString = ThrowableToStringMapper::map($t);
Expand Down
5 changes: 4 additions & 1 deletion src/Codeception/Scenario.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ public function comment(string $comment): void

public function skip(string $message = ''): void
{
if (PHPUnitVersion::series() < 10) {
if (
version_compare(PHPUnitVersion::series(), '10.0', '<')
&& class_exists(SkippedTestError::class)
) {
throw new SkippedTestError($message);
}
throw new SkippedWithMessageException($message);
Expand Down
2 changes: 1 addition & 1 deletion src/Codeception/Step/Executor.php
Loading