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

Update the codebase to PHP 8.1 #6747

Open
wants to merge 5 commits into
base: 5.2
Choose a base branch
from
Open
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
20 changes: 10 additions & 10 deletions .github/workflows/build.yml
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
ini-values: memory_limit=-1, date.timezone='UTC'
tools: phpcs

Expand All @@ -45,13 +45,13 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: ['8.0', '8.1', '8.2']
php: ['8.1', '8.2', '8.3']
mode: ['stable', 'experimental']
exclude:
- php: '8.1'
mode: 'experimental'
- php: '8.2'
mode: 'experimental'
- php: '8.3'
mode: 'experimental'

steps:
- name: Checkout
Expand Down Expand Up @@ -87,15 +87,15 @@ jobs:
if: matrix.mode == 'stable'
run: composer update --no-interaction --no-progress --optimize-autoloader --ansi

- name: Composer install lowest versions of dependencies on PHP 8.0 in experimental mode
if: matrix.php == '8.0' && matrix.mode == 'experimental'
- name: Composer install lowest versions of dependencies on PHP 8.1 in experimental mode
if: matrix.php == '8.1' && matrix.mode == 'experimental'
run: composer update --prefer-lowest --no-interaction --no-progress --optimize-autoloader --ansi

- 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;

# - name: Run tests without code coverage on PHP 8.0
# if: matrix.php == '8.0'
# - name: Run tests without code coverage on PHP 8.1
# if: matrix.php == '8.1'
# run: |
# php -S 127.0.0.1:8008 -t tests/data/app >/dev/null 2>&1 &
# php codecept build
Expand Down Expand Up @@ -137,7 +137,7 @@ jobs:
fail-fast: false
matrix:
os: [windows-latest]
php: ['8.0', '8.1', '8.2']
php: ['8.1', '8.2', '8.3']

steps:
- name: Checkout
Expand Down Expand Up @@ -172,7 +172,7 @@ jobs:
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run tests cli
if: matrix.php != '8.1'
if: matrix.php != '8.2'
run: php codecept run cli --skip-group coverage

- name: Run tests unit
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -15,7 +15,7 @@
"minimum-stability": "RC",

"require": {
"php": "^8.0",
"php": "^8.1",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
Expand Down
28 changes: 15 additions & 13 deletions ext/Recorder.php
Expand Up @@ -10,6 +10,7 @@
use Codeception\Exception\ExtensionException;
use Codeception\Extension;
use Codeception\Lib\Interfaces\ScreenshotSaver;
use Codeception\Module;
use Codeception\Module\WebDriver;
use Codeception\Step;
use Codeception\Step\Comment as CommentStep;
Expand Down Expand Up @@ -283,7 +284,7 @@ class Recorder extends Extension
Events::STEP_AFTER => 'afterStep',
];

protected ?\Codeception\Module $webDriverModule = null;
protected ?Module $webDriverModule = null;

protected ?string $dir = null;

Expand Down Expand Up @@ -345,12 +346,12 @@ public function beforeSuite(): void

public function afterSuite(): void
{
if (!$this->webDriverModule) {
if (!$this->webDriverModule instanceof Module) {
return;
}
$links = '';

if (!empty($this->slides)) {
if ($this->slides !== []) {
foreach ($this->recordedTests as $suiteName => $suite) {
$links .= "<ul><li><b>{$suiteName}</b></li><ul>";
foreach ($suite as $fileName => $tests) {
Expand Down Expand Up @@ -391,7 +392,7 @@ public function afterSuite(): void

public function before(TestEvent $event): void
{
if (!$this->webDriverModule) {
if (!$this->webDriverModule instanceof Module) {
return;
}
$this->dir = null;
Expand Down Expand Up @@ -435,7 +436,7 @@ public function cleanup(TestEvent $event): void
}
}

if (!$this->webDriverModule || !$this->dir) {
if (!$this->webDriverModule instanceof Module || !$this->dir) {
return;
}
if (!$this->config['delete_successful']) {
Expand All @@ -450,7 +451,7 @@ public function cleanup(TestEvent $event): void

public function persist(TestEvent $event): void
{
if (!$this->webDriverModule) {
if (!$this->webDriverModule instanceof Module) {
return;
}
$indicatorHtml = '';
Expand All @@ -466,7 +467,7 @@ public function persist(TestEvent $event): void
try {
!is_dir($dir) && !mkdir($dir) && !is_dir($dir);
$this->dir = $dir;
} catch (Exception $exception) {
} catch (Exception) {
$this->skipRecording[] = $testPath;
$this->appendErrorMessage(
$testPath,
Expand All @@ -486,7 +487,7 @@ public function persist(TestEvent $event): void
}

$this->webDriverModule->webDriver->takeScreenshot($this->dir . DIRECTORY_SEPARATOR . $filename);
} catch (Exception $exception) {
} catch (Exception) {
$this->appendErrorMessage(
$testPath,
"⏺ Unable to capture a screenshot for <info>{$testPath}/before</info>"
Expand All @@ -503,13 +504,13 @@ public function persist(TestEvent $event): void

$indicatorHtml .= (new Template($this->indicatorTemplate))
->place('step', (int)$i)
->place('isActive', (int)$i ? '' : 'active')
->place('isActive', (int)$i !== 0 ? '' : 'active')
->produce();

$slideHtml .= (new Template($this->slidesTemplate))
->place('image', $i)
->place('caption', $step->getHtml('#3498db'))
->place('isActive', (int)$i ? '' : 'active')
->place('isActive', (int)$i !== 0 ? '' : 'active')
->place('isError', $status === 'success' ? '' : 'error')
->place('timeStamp', $this->timeStamps[$i])
->produce();
Expand All @@ -518,7 +519,7 @@ public function persist(TestEvent $event): void
$html = (new Template($this->template))
->place('indicators', $indicatorHtml)
->place('slides', $slideHtml)
->place('feature', ucfirst($event->getTest()->getFeature()))
->place('feature', ucfirst((string) $event->getTest()->getFeature()))
->place('test', Descriptor::getTestSignature($event->getTest()))
->place('carousel_class', $this->config['animate_slides'] ? ' slide' : '')
->produce();
Expand Down Expand Up @@ -550,7 +551,7 @@ public function persist(TestEvent $event): void

public function afterStep(StepEvent $event): void
{
if ($this->webDriverModule === null || $this->dir === null) {
if (!$this->webDriverModule instanceof Module || $this->dir === null) {
return;
}

Expand All @@ -571,7 +572,7 @@ public function afterStep(StepEvent $event): void
}

$this->webDriverModule->webDriver->takeScreenshot($this->dir . DIRECTORY_SEPARATOR . $filename);
} catch (Exception $exception) {
} catch (Exception) {
$testPath = codecept_relative_path(Descriptor::getTestFullName($event->getTest()));
$this->appendErrorMessage(
$testPath,
Expand All @@ -589,6 +590,7 @@ protected function isStepIgnored(StepEvent $event): bool
$configIgnoredSteps = $this->config['ignore_steps'];
$annotationIgnoredSteps = $event->getTest()->getMetadata()->getParam('skipRecording');

/** @var string[] $ignoredSteps */
$ignoredSteps = array_unique(
array_merge(
$configIgnoredSteps,
Expand Down
2 changes: 1 addition & 1 deletion ext/RunBefore.php
Expand Up @@ -111,7 +111,7 @@ private function removeProcessFromMonitoring(int $index): void

private function processMonitoring(): void
{
while (count($this->processes) !== 0) {
while ($this->processes !== []) {
$this->checkProcesses();
sleep(1);
}
Expand Down
2 changes: 1 addition & 1 deletion ext/RunFailed.php
Expand Up @@ -88,7 +88,7 @@ public function saveFailed(PrintResultEvent $event): void
protected function localizePath(string $path): string
{
$root = realpath($this->getRootDir()) . DIRECTORY_SEPARATOR;
if (substr($path, 0, strlen($root)) === $root) {
if (str_starts_with($path, $root)) {
return substr($path, strlen($root));
}
return $path;
Expand Down
5 changes: 3 additions & 2 deletions ext/RunProcess.php
Expand Up @@ -4,6 +4,7 @@

namespace Codeception\Extension;

use BadMethodCallException;
use Codeception\Events;
use Codeception\Exception\ExtensionException;
use Codeception\Extension;
Expand Down Expand Up @@ -127,7 +128,7 @@ public function stopProcess(): void
*/
public function __sleep()
{
throw new \BadMethodCallException('Cannot serialize ' . __CLASS__);
throw new BadMethodCallException('Cannot serialize ' . self::class);
}

/**
Expand All @@ -138,6 +139,6 @@ public function __sleep()
*/
public function __wakeup()
{
throw new \BadMethodCallException('Cannot unserialize ' . __CLASS__);
throw new BadMethodCallException('Cannot unserialize ' . self::class);
}
}
2 changes: 1 addition & 1 deletion src/Codeception/Actor.php
Expand Up @@ -42,7 +42,7 @@ public function wantToTest(string $text): void

public function __call(string $method, array $arguments)
{
$class = $this::class;
$class = static::class;
throw new RuntimeException("Call to undefined method {$class}::{$method}");
}

Expand Down
4 changes: 2 additions & 2 deletions src/Codeception/Application.php
Expand Up @@ -101,7 +101,7 @@ protected function getCustomCommandName(string $commandClass): string
*/
public function run(InputInterface $input = null, OutputInterface $output = null): int
{
if ($input === null) {
if (!$input instanceof InputInterface) {
$input = $this->getCoreArguments();
}

Expand Down Expand Up @@ -135,7 +135,7 @@ protected function getDefaultInputDefinition(): InputDefinition
*/
protected function getCoreArguments(): SymfonyArgvInput
{
if ($this->coreArguments !== null) {
if ($this->coreArguments instanceof SymfonyArgvInput) {
return $this->coreArguments;
}

Expand Down
18 changes: 5 additions & 13 deletions src/Codeception/Codecept.php
Expand Up @@ -78,7 +78,7 @@ class Codecept

protected array $extensions = [];

private Output $output;
private readonly Output $output;

public function __construct(array $options = [])
{
Expand Down Expand Up @@ -154,7 +154,7 @@ public function registerSubscribers(): void

private function isConsolePrinterSubscribed(): bool
{
foreach ($this->dispatcher->getListeners() as $event => $listeners) {
foreach ($this->dispatcher->getListeners() as $listeners) {
foreach ($listeners as $listener) {
if ($listener instanceof ConsolePrinter) {
return true;
Expand Down Expand Up @@ -192,14 +192,6 @@ private function registerReporters(): void
}
}

private function absolutePath(string $path): string
{
if ((str_starts_with($path, '/')) or (strpos($path, ':') === 1)) { // absolute path
return $path;
}
return Configuration::outputDir() . $path;
}
Naktibalda marked this conversation as resolved.
Show resolved Hide resolved

public function run(string $suite, string $test = null, array $config = null): void
{
ini_set(
Expand All @@ -219,7 +211,7 @@ public function run(string $suite, string $test = null, array $config = null): v

// Iterate over all unique environment sets and runs the given suite with each of the merged configurations.
foreach (array_unique($selectedEnvironments) as $envList) {
$envSet = explode(',', $envList);
$envSet = explode(',', (string) $envList);
$suiteEnvConfig = $config;

// contains a list of the environments used in this suite configuration env set.
Expand Down Expand Up @@ -254,9 +246,9 @@ public function runSuite(array $settings, string $suite, string $test = null): v
$settings['shard'] = $this->options['shard'];
$suiteManager = new SuiteManager($this->dispatcher, $suite, $settings, $this->options);
$suiteManager->initialize();
srand($this->options['seed']);
mt_srand($this->options['seed']);
$suiteManager->loadTests($test);
srand();
mt_srand();
$suiteManager->run($this->resultAggregator);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Codeception/Command/Build.php
Expand Up @@ -77,7 +77,7 @@ private function buildActions(array $settings): bool
private function buildSuiteActors(): void
{
$suites = $this->getSuites();
if (!empty($suites)) {
if ($suites !== []) {
$this->output->writeln("<info>Building Actor classes for suites: " . implode(', ', $suites) . '</info>');
}
foreach ($suites as $suite) {
Expand All @@ -94,7 +94,7 @@ private function buildSuiteActors(): void
}
}

protected function buildActorsForConfig($configFile = null): void
protected function buildActorsForConfig(?string $configFile = null): void
{
$config = $this->getGlobalConfig($configFile);

Expand Down
6 changes: 3 additions & 3 deletions src/Codeception/Command/DryRun.php
Expand Up @@ -33,7 +33,7 @@
use function str_replace;

/**
* Shows step by step execution process for scenario driven tests without actually running them.
* Shows step-by-step execution process for scenario driven tests without actually running them.
*
* * `codecept dry-run acceptance`
* * `codecept dry-run acceptance MyCest`
Expand Down Expand Up @@ -65,7 +65,7 @@ public function getDescription(): string
public function execute(InputInterface $input, OutputInterface $output): int
{
$this->addStyles($output);
$suite = $input->getArgument('suite');
$suite = (string)$input->getArgument('suite');
$test = $input->getArgument('test');

$config = $this->getGlobalConfig();
Expand Down Expand Up @@ -219,7 +219,7 @@ private function returnDefaultValueForIntersectionType(ReflectionIntersectionTyp
if ($extends !== null) {
$code .= " extends \\$extends";
}
if (count($implements) > 0) {
if ($implements !== []) {
$code .= ' implements ' . implode(', ', $implements);
}
$code .= ' {}';
Expand Down
4 changes: 2 additions & 2 deletions src/Codeception/Command/GenerateFeature.php
Expand Up @@ -45,7 +45,7 @@ public function getDescription(): string
public function execute(InputInterface $input, OutputInterface $output): int
{
$suite = $input->getArgument('suite');
$filename = $input->getArgument('feature');
$filename = (string)$input->getArgument('feature');

$config = $this->getSuiteConfig($suite);
$this->createDirectoryFor($config['path'], $filename);
Expand All @@ -54,7 +54,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
if (!preg_match('#\.feature$#', $filename)) {
$filename .= '.feature';
}
$fullPath = rtrim($config['path'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $filename;
$fullPath = rtrim((string) $config['path'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $filename;
$res = $this->createFile($fullPath, $feature->produce());
if (!$res) {
$output->writeln("<error>Feature {$filename} already exists</error>");
Expand Down
4 changes: 1 addition & 3 deletions src/Codeception/Command/GenerateScenarios.php
Expand Up @@ -57,9 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$suiteConf = $this->getSuiteConfig($suite);

$path = $input->getOption('path')
? $input->getOption('path')
: Configuration::dataDir() . 'scenarios';
$path = $input->getOption('path') ?: Configuration::dataDir() . 'scenarios';

$format = $input->getOption('format');

Expand Down