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
Original file line number Diff line number Diff line change
@@ -1,56 +1,66 @@
on:
pull_request:
branches-ignore: gh-pages
branches-ignore:
- gh-pages
push:
branches:
- main

name: build

concurrency:
group: build-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
actions: write

env:
PHP_INI_VALUES: memory_limit=-1,date.timezone=UTC
COMPOSER_ROOT_VERSION: 5.0.99
SYMFONY_DEPRECATIONS_HELPER: weak

jobs:
phpcs:
name: Code style
name: Code style & Static Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
- name: Install PHP & tools
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
ini-values: memory_limit=-1, date.timezone='UTC'
tools: phpcs
ini-values: ${{ env.PHP_INI_VALUES }}
tools: phpcs, composer:v2, phpstan

- name: Install dependencies
run: composer install --no-interaction --no-progress --ansi

- name: Check production code style
run: composer cs-prod

- name: Check test code style
run: composer cs-tests

linux:
name: PHP ${{ matrix.php }}-${{ matrix.os }}-${{ matrix.mode }}
- name: PHPStan
run: phpstan analyse src

linux:
name: PHP ${{ matrix.php }}–${{ matrix.os }}–${{ matrix.mode }}
runs-on: ${{ matrix.os }}
env:
extensions: curl, mbstring, openssl, pdo, pdo_sqlite
SYMFONY_DEPRECATIONS_HELPER: weak
COMPOSER_ROOT_VERSION: 5.0.99
extensions: curl, mbstring, openssl, pdo, pdo_sqlite, zip
COLUMNS: 120

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: ['8.2', '8.3', '8.4']
mode: ['stable', 'experimental']
exclude:
- php: '8.2'
mode: 'experimental'
- php: '8.3'
mode: 'experimental'
- php: '8.4'
Expand All @@ -60,12 +70,12 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
- name: Install PHP & Composer
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
ini-values: memory_limit=-1, date.timezone='UTC'
ini-values: ${{ env.PHP_INI_VALUES }}
coverage: xdebug
tools: composer:v2

Expand All @@ -84,18 +94,22 @@ jobs:
run: composer self-update

- name: Validate composer.json
run: composer validate

- name: Install latest versions of dependencies in stable mode
if: matrix.mode == 'stable'
run: composer update --no-interaction --no-progress --optimize-autoloader --ansi
run: composer validate --strict

- name: Composer install lowest versions of dependencies on PHP 8.2 in experimental mode
if: matrix.php == '8.2' && matrix.mode == 'experimental'
run: composer update --prefer-lowest --no-interaction --no-progress --optimize-autoloader --ansi
- name: Install / Update Dependencies
run: |
if [ "${{ matrix.mode }}" = "stable" ]; then
composer update --no-interaction --no-progress --optimize-autoloader --ansi
else
composer update --prefer-lowest --no-interaction --no-progress --optimize-autoloader --ansi
fi

- name: Test that failing test really fails
run: if php codecept run -c tests/data/claypit/ scenario FailedCept -vvv; then echo "Test hasn't failed"; false; fi;
run: |
if php codecept run -c tests/data/claypit/ scenario FailedCept -vvv; then
echo "Test hasn't failed"
false
fi

# - name: Run tests without code coverage on PHP 8.2
# if: matrix.php == '8.2'
Expand Down Expand Up @@ -127,15 +141,12 @@ jobs:
php ../../../codecept run tests/unit/Codeception/Module/PhpBrowserTest.php

windows-latest:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

name: PHP ${{ matrix.php }}${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
extensions: curl, mbstring, openssl, pdo, pdo_sqlite
extensions: curl, mbstring, openssl, pdo, pdo_sqlite, zip
SYMFONY_DEPRECATIONS_HELPER: weak
COMPOSER_ROOT_VERSION: 5.0.99

runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
Expand All @@ -146,16 +157,17 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
- name: Install PHP & Composer
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
ini-values: memory_limit=-1, date.timezone='UTC'
ini-values: ${{ env.PHP_INI_VALUES }}
tools: composer:v2

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=~\\AppData\\Local\\Composer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
run: |
echo "COMPOSER_CACHE_DIR=~\\AppData\\Local\\Composer" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
Expand All @@ -169,7 +181,7 @@ jobs:
run: composer self-update

- name: Validate composer.json
run: composer validate
run: composer validate --strict

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Executor extends CodeceptionStep
{
public function __construct(protected Closure $callable, array $arguments = [])
{
parent::__construct('execute callable function', []);
parent::__construct('execute callable function', $arguments);
}

public function run(?ModuleContainer $container = null)
Expand Down
Loading
Loading