Skip to content

Commit 5df4d88

Browse files
authored
Merge pull request #812 from lucatume/refactor/prune-dead-internals
refactor: prune dead internals, delegate Filesystem helpers to Symfony
2 parents 5f9c851 + 1d1f2fc commit 5df4d88

16 files changed

Lines changed: 127 additions & 412 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,20 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [unreleased] Unreleased
77

8+
### Fixed
9+
10+
- `MysqlServerController` now probes the configured port with a PDO handshake before starting a server: a MySQL instance reachable on the port is reused instead of racing to start (and download) a second one. Fixes `parallel-run` workers, whose per-worker output dirs hid the shared server's PID file (#812).
11+
- `parallel-run` prints `FAILURES!` instead of `OK` when a worker crashes before reporting results (#812).
12+
- `parallel-run` resolves the managed MySQL data dir through `codecept_output_dir()` instead of a hardcoded `var/_output` path that ignored `paths.output` overrides and broke the 103-char unix socket path limit on deep checkouts (#812).
13+
14+
### Changed
15+
16+
- `Utils\Filesystem::rrmdir()` and `recurseCopy()` now delegate to the bundled `symfony/filesystem` component instead of a hand-rolled recursive delete and a `cp -R`/`xcopy` shell-out; public signatures are unchanged, and failure paths that previously threw (unreadable dir, uncreatable destination) now return `false` like the other failure modes (#812).
17+
818
### Removed
919

20+
- Remove dead internal classes: `Utils\DockerCompose`, `Environment\Constants`, `Events\EventDispatcherException`, `Polyfills\Dotenv\Dotenv` and the `WordPress\CodeExecution` `ExitAction`/`ThrowAction` test doubles. No user-facing API is affected (#812).
21+
1022
- Drop the v3.5 downgrade Rector harness (`config/rector-35.php`, `config/composer-35.json`, the `RemoveTypeHinting`/`DowngradePhpOsFamily`/`SerializableThrowableCompatibilityRector` rules, the `bin/build-35-*` build scripts, and the dead `build_35` Makefile target) from `master`; it now lives entirely on the v3.5 branch (#810).
1123

1224
## [4.7.1] 2026-06-30;

docs/extensions/MySqlServerController.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ directory under the codeception output directory and initialize the server in th
66
The aim of this extension is to allow running integration tests against a real MySQL server, without having to
77
install and configure a MySQL server on the machine.
88

9+
If a MySQL server is already reachable on the configured port, the extension will reuse it instead of starting
10+
a new one; a server reused this way is not stopped by the extension.
11+
912
!!! warning
1013

1114
Currently the MySQL Community Server version installed by this extension (8.4.2 LTS) **is not available for Windows on ARM.**

src/Command/ParallelRun.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
102102

103103
$start = microtime(true);
104104

105-
$failed = false;
106105
$eventFiles = [];
107106
$eventOffsets = [];
108107
$logFiles = [];
@@ -175,7 +174,6 @@ public function execute(InputInterface $input, OutputInterface $output): int
175174
$this->drainEvents($eventFiles[$i], $eventOffsets, $i, $aggregator);
176175
if (!$p->isRunning()) {
177176
if (!$p->isSuccessful()) {
178-
$failed = true;
179177
$aggregator->recordCrash($i, $p->getExitCode() ?? -1);
180178
}
181179
unset($remaining[$i]);
@@ -206,7 +204,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
206204
$this->teardownWorkers($workers, $cwd ?? '.', $output);
207205
}
208206

209-
return ($failed || $aggregator->hasFailures()) ? 1 : 0;
207+
return $aggregator->hasFailures() ? 1 : 0;
210208
}
211209

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

395393
$baseDbName = (string)($envVars['WORDPRESS_DB_NAME'] ?? 'wordpress');
396-
$dataDir = $cwd . '/var/_output/_mysql_server';
394+
$dataDir = codecept_output_dir('_mysql_server');
397395
if (!is_dir($dataDir) && !mkdir($dataDir, 0777, true) && !is_dir($dataDir)) {
398396
throw new RuntimeException("Failed to create MySQL data directory: {$dataDir}");
399397
}

src/Command/ParallelRun/DotAggregator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ public function flushSummary(float $wallClock): void
132132
$this->formatMemory(memory_get_peak_usage(true))
133133
));
134134

135-
$style = ($this->totalFailures + $this->totalErrors + count($this->crashedWorkers)) > 0 ? 'error' : 'info';
136-
$header = ($this->totalFailures + $this->totalErrors) > 0 ? 'FAILURES!' : 'OK';
135+
$style = $this->hasFailures() ? 'error' : 'info';
136+
$header = $this->hasFailures() ? 'FAILURES!' : 'OK';
137137
$this->output->writeln(sprintf('<%s>%s</%s>', $style, $header, $style));
138138
$this->output->writeln(sprintf(
139139
'Tests: %d, Assertions: %d, Failures: %d, Errors: %d, Skipped: %d',

src/Environment/Constants.php

Lines changed: 0 additions & 71 deletions
This file was deleted.

src/Events/EventDispatcherException.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Extension/MysqlServerController.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ class MysqlServerController extends ServiceExtension
1919
public function start(OutputInterface $output): void
2020
{
2121
$pidFile = $this->getPidFile();
22+
$port = $this->getPort();
2223

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

2627
return;
2728
}
2829

29-
$port = $this->getPort();
3030
$database = $this->getDatabase();
3131
$user = $this->getUser();
3232
$password = $this->getPassword();
@@ -57,6 +57,24 @@ public function getPidFile(): string
5757
return codecept_output_dir(self::PID_FILE_NAME);
5858
}
5959

60+
private function isMysqlServerReachable(int $port): bool
61+
{
62+
try {
63+
new \PDO(
64+
"mysql:host=127.0.0.1;port={$port}",
65+
$this->getUser(),
66+
$this->getPassword(),
67+
[\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION, \PDO::ATTR_TIMEOUT => 1]
68+
);
69+
70+
return true;
71+
} catch (\PDOException $e) {
72+
// An auth or protocol-level error still proves a server is listening on the port;
73+
// only a failure to connect at all (2002/2003) means no server is there.
74+
return !in_array((int)$e->getCode(), [2002, 2003], true);
75+
}
76+
}
77+
6078
private function getDatabase(): string
6179
{
6280
/** @var array{database?: string} $config */
@@ -127,7 +145,7 @@ public function getPort(): int
127145
public function stop(OutputInterface $output): void
128146
{
129147
$pidFile = $this->getPidFile();
130-
$mysqlServerPid = (int)file_get_contents($pidFile);
148+
$mysqlServerPid = is_file($pidFile) ? (int)file_get_contents($pidFile) : 0;
131149

132150
if (!$mysqlServerPid) {
133151
$output->writeln('MySQL server not running.');
@@ -155,7 +173,7 @@ public function getPrettyName(): string
155173
*/
156174
public function getInfo(): array
157175
{
158-
$isRunning = is_file($this->getPidFile());
176+
$isRunning = is_file($this->getPidFile()) || $this->isMysqlServerReachable($this->getPort());
159177

160178
$info = [
161179
'running' => $isRunning ? 'yes' : 'no',

src/Polyfills/Dotenv/Dotenv.php

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/Process/Protocol/Control.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Codeception\Configuration;
66
use Codeception\Exception\ConfigurationException;
7-
use lucatume\WPBrowser\Polyfills\Dotenv\Dotenv;
87

98
class Control
109
{

src/Utils/DockerCompose.php

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)