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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased] Unreleased

### Changed

- Transpile the v4 unreleased changes (test suite split, dead-code removal, `MysqlServerController` port reuse, `parallel-run` fixes, `Utils\Filesystem` delegation to `symfony/filesystem`) down to the PHP 7.1-compatible v3.5 line (#817).

## [3.8.0] 2026-07-01;

### Changed
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@
"psr-4": {
"lucatume\\WPBrowser\\Tests\\FSTemplates\\": "tests/_support/FSTemplates",
"lucatume\\WPBrowser\\Tests\\Traits\\": "tests/_support/Traits"
}
},
"classmap": [
"tests/_support/classmap"
]
},
"extra": {
"_hash": "484f861f69198089cab0e642f27e5653"
Expand Down
5 changes: 4 additions & 1 deletion config/composer-35.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@
"autoload-dev": {
"psr-4": {
"lucatume\\WPBrowser\\Tests\\": "tests/_support"
}
},
"classmap": [
"tests/_support/classmap"
]
},
"extra": {
"_hash": "484f861f69198089cab0e642f27e5653"
Expand Down
6 changes: 2 additions & 4 deletions src/Command/ParallelRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public function execute(InputInterface $input, OutputInterface $output): int

$start = microtime(true);

$failed = false;
$eventFiles = [];
$eventOffsets = [];
$logFiles = [];
Expand Down Expand Up @@ -175,7 +174,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
$this->drainEvents($eventFiles[$i], $eventOffsets, $i, $aggregator);
if (!$p->isRunning()) {
if (!$p->isSuccessful()) {
$failed = true;
$aggregator->recordCrash($i, $p->getExitCode() ?? -1);
}
unset($remaining[$i]);
Expand Down Expand Up @@ -206,7 +204,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
$this->teardownWorkers($workers, $cwd ?? '.', $output);
}

return ($failed || $aggregator->hasFailures()) ? 1 : 0;
return $aggregator->hasFailures() ? 1 : 0;
}

/**
Expand Down Expand Up @@ -393,7 +391,7 @@ private function ensureMysqlStarted(string $cwd, OutputInterface $output): void
$output->writeln('<info>MySQL not reachable at ' . $host . '; starting a managed instance...</info>');

$baseDbName = (string)($envVars['WORDPRESS_DB_NAME'] ?? 'wordpress');
$dataDir = $cwd . '/var/_output/_mysql_server';
$dataDir = codecept_output_dir('_mysql_server');
if (!is_dir($dataDir) && !mkdir($dataDir, 0777, true) && !is_dir($dataDir)) {
throw new RuntimeException("Failed to create MySQL data directory: {$dataDir}");
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ParallelRun/DotAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public function flushSummary(float $wallClock): void
$this->formatMemory(memory_get_peak_usage(true))
));

$style = ($this->totalFailures + $this->totalErrors + count($this->crashedWorkers)) > 0 ? 'error' : 'info';
$header = ($this->totalFailures + $this->totalErrors) > 0 ? 'FAILURES!' : 'OK';
$style = $this->hasFailures() ? 'error' : 'info';
$header = $this->hasFailures() ? 'FAILURES!' : 'OK';
$this->output->writeln(sprintf('<%s>%s</%s>', $style, $header, $style));
$this->output->writeln(sprintf(
'Tests: %d, Assertions: %d, Failures: %d, Errors: %d, Skipped: %d',
Expand Down
71 changes: 0 additions & 71 deletions src/Environment/Constants.php

This file was deleted.

9 changes: 0 additions & 9 deletions src/Events/EventDispatcherException.php

This file was deleted.

28 changes: 23 additions & 5 deletions src/Extension/MysqlServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class MysqlServerController extends ServiceExtension
public function start(OutputInterface $output): void
{
$pidFile = $this->getPidFile();
$port = $this->getPort();

if ($this->isProcessRunning($pidFile)) {
$output->writeln('MySQL server already running.');
if ($this->isProcessRunning($pidFile) || $this->isMysqlServerReachable($port)) {
$output->writeln("MySQL server already running on port $port.");

return;
}

$port = $this->getPort();
$database = $this->getDatabase();
$user = $this->getUser();
$password = $this->getPassword();
Expand Down Expand Up @@ -60,6 +60,24 @@ public function getPidFile(): string
return codecept_output_dir(self::PID_FILE_NAME);
}

private function isMysqlServerReachable(int $port): bool
{
try {
new \PDO(
"mysql:host=127.0.0.1;port={$port}",
$this->getUser(),
$this->getPassword(),
[\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_TIMEOUT => 1]
);

return true;
} catch (\PDOException $e) {
// An auth or protocol-level error still proves a server is listening on the port;
// only a failure to connect at all (2002/2003) means no server is there.
return !in_array((int)$e->getCode(), [2002, 2003], true);
}
}

private function getDatabase(): string
{
/** @var array{database?: string} $config */
Expand Down Expand Up @@ -130,7 +148,7 @@ public function getPort(): int
public function stop(OutputInterface $output): void
{
$pidFile = $this->getPidFile();
$mysqlServerPid = (int)file_get_contents($pidFile);
$mysqlServerPid = is_file($pidFile) ? (int)file_get_contents($pidFile) : 0;

if (!$mysqlServerPid) {
$output->writeln('MySQL server not running.');
Expand Down Expand Up @@ -158,7 +176,7 @@ public function getPrettyName(): string
*/
public function getInfo(): array
{
$isRunning = is_file($this->getPidFile());
$isRunning = is_file($this->getPidFile()) || $this->isMysqlServerReachable($this->getPort());

$info = [
'running' => $isRunning ? 'yes' : 'no',
Expand Down
10 changes: 0 additions & 10 deletions src/Generators/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@ public static function _time(): int
return self::$time ?: time();
}

/**
* Returns the 0 time string in WordPress specific format.
*
* @return string The "0000-00-00 00:00:00" string.
*/
public static function zero(): string
{
return '0000-00-00 00:00:00';
}

/**
* The current date in GMT time.
*
Expand Down
1 change: 0 additions & 1 deletion src/ManagedProcess/ManagedProcessInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ interface ManagedProcessInterface
public const ERR_PID = 3;
public const ERR_PID_FILE = 4;
public const ERR_BINARY_NOT_FOUND = 5;
public const ERR_STOP = 6;
public const ERR_NOT_RUNNING = 7;
public const ERR_PID_FILE_DELETE = 8;

Expand Down
24 changes: 14 additions & 10 deletions src/Module/Support/DbDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,26 @@ class DbDump
* @return array<string> The modified SQL array.
*/
public function replaceSiteDomainInSqlArray(array $sql): array
{
return $this->replaceSiteDomainInJoinedSql($sql, false);
}

/**
* @param array<string> $sql
*
* @return array<string>
*/
private function replaceSiteDomainInJoinedSql(array $sql, bool $multisite): array
{
if (empty($sql)) {
return [];
}

$delimiter = md5(uniqid('delim', true));
$joined = implode($delimiter, $sql);
$replaced = $this->replaceSiteDomainInSqlString($joined);
$replaced = $multisite ?
$this->replaceSiteDomainInMultisiteSqlString($joined)
: $this->replaceSiteDomainInSqlString($joined);

return explode($delimiter, $replaced);
}
Expand All @@ -58,15 +70,7 @@ public function replaceSiteDomainInSqlArray(array $sql): array
*/
public function replaceSiteDomainInMultisiteSqlArray(array $sql): array
{
if (empty($sql)) {
return [];
}

$delimiter = md5(uniqid('delim', true));
$joined = implode($delimiter, $sql);
$replaced = $this->replaceSiteDomainInMultisiteSqlString($joined);

return explode($delimiter, $replaced);
return $this->replaceSiteDomainInJoinedSql($sql, true);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Module/WPCLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public function dontSeeInShellOutput(string $text): void
*/
public function seeShellOutputMatches(string $regex): void
{
$this->assertMatchesRegularExpression($regex, $this->grabLastShellOutput());
$this->assertRegExp($regex, $this->grabLastShellOutput());
}

/**
Expand All @@ -415,7 +415,7 @@ public function seeShellOutputMatches(string $regex): void
*/
public function dontSeeShellOutputMatches(string $regex): void
{
$this->assertDoesNotMatchRegularExpression($regex, $this->grabLastShellOutput());
$this->assertNotRegExp($regex, $this->grabLastShellOutput());
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Module/WPDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -3058,9 +3058,8 @@ protected function _seeTableInDatabase(string $table): bool
$sth = $dbh->prepare('SHOW TABLES LIKE :table');
$this->debugSection('Query', $sth->queryString);
$sth->execute(['table' => $table]);
$count = $sth->rowCount();

return $count === 1;
return $sth->rowCount() === 1;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Module/WPFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public function dontSeeUploadedFileFound(string $file, $date = null): void
if (method_exists(Assert::class, 'assertFileDoesNotExist')) {
Assert::assertFileDoesNotExist($this->getUploadsPath($file, $date));
} else {
Assert::assertFileDoesNotExist($this->getUploadsPath($file, $date));
Assert::assertFileNotExists($this->getUploadsPath($file, $date));
}
}

Expand Down
Loading
Loading