Skip to content

Commit

Permalink
feat(IsolationSupport) add support for process isolation
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Feb 7, 2024
1 parent 45da35f commit a4764ae
Show file tree
Hide file tree
Showing 23 changed files with 804 additions and 109 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ composer.lock

# Backup files and folders
*.bak

# Logs
*.log
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).

- The `WPTestCase` class will **not** backup globals and static attributes by default. Version `3` of wp-browser did not backup globals and static attributes by default, this change in version `4` is aligned with that behaviour to ease migration from version `3` to version `4`.

### Added

- Restored support for the `@runInSeparateProcess` annotation for test methods. Along with it, improved support for the `@dataProvider` annotation for test methods used in conjunction with the `@runInSeparateProcess` annotation to run data provider methods at most once.
- Implemented support for the `runTestsInSeparateProcesses` annotation for test classes; supporting the `@dataProvider` annotation ro run data provider methods at most once.

## [4.0.18] 2024-01-23;

- Improve messaging and documentation around initialization and setup.
Expand Down
1 change: 1 addition & 0 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ extensions:
- "lucatume\\WPBrowser\\Extension\\BuiltInServerController"
- "lucatume\\WPBrowser\\Extension\\ChromeDriverController"
- "lucatume\\WPBrowser\\Extension\\DockerComposeController"
- "lucatume\\WPBrowser\\Extension\\IsolationSupport"
config:
"lucatume\\WPBrowser\\Extension\\BuiltInServerController":
docroot: '%WORDPRESS_ROOT_DIR%'
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"src/",
"src/Deprecated"
],
"Codeception\\Extension\\": "src/Extension",
"Hautelook\\Phpass\\": "includes/Hautelook/Phpass",
"lucatume\\WPBrowser\\Opis\\Closure\\" : "includes/opis/closure/src"
},
Expand Down
1 change: 1 addition & 0 deletions config/phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ parameters:
treatPhpDocTypesAsCertain: false
excludePaths:
- ./../src/WordPress/Version.php # Using the WordPress version file.
- ./../src/TestCase/WPTestCasePHPUnitMethodsTraitPHPUnitLt8.php # Compat file has missing return types.
13 changes: 8 additions & 5 deletions src/Adapters/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace lucatume\WPBrowser\Adapters\Symfony\Component\Process;

use ReflectionMethod;
use ReflectionProperty;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Pipes\PipesInterface;
use Symfony\Component\Process\Process as SymfonyProcess;
Expand Down Expand Up @@ -29,12 +31,13 @@ public function __construct(
if (self::$inheritEnvironmentVariables === null) {
self::$inheritEnvironmentVariables = method_exists($this, 'inheritEnvironmentVariables')
&& !str_contains(
(new \ReflectionMethod($this, 'inheritEnvironmentVariables'))->getDocComment(),
(string)(new ReflectionMethod($this, 'inheritEnvironmentVariables'))->getDocComment(),
'@deprecated'
);
}

if (self::$inheritEnvironmentVariables) {
// @phpstan-ignore-next-line
$this->inheritEnvironmentVariables(true);
}

Expand All @@ -51,7 +54,7 @@ public function getStartTime(): float
throw new LogicException('Start time is only available after process start.');
}

$startTimeReflectionProperty = new \ReflectionProperty(SymfonyProcess::class, 'starttime');
$startTimeReflectionProperty = new ReflectionProperty(SymfonyProcess::class, 'starttime');
$startTimeReflectionProperty->setAccessible(true);
/** @var float $startTime */
$startTime = $startTimeReflectionProperty->getValue($this);
Expand All @@ -62,7 +65,7 @@ public function getStartTime(): float
public function __destruct()
{
if ($this->createNewConsole) {
$processPipesProperty = new \ReflectionProperty(SymfonyProcess::class, 'processPipes');
$processPipesProperty = new ReflectionProperty(SymfonyProcess::class, 'processPipes');
$processPipesProperty->setAccessible(true);
/** @var PipesInterface $processPipes */
$processPipes = $processPipesProperty->getValue($this);
Expand All @@ -78,7 +81,7 @@ public function createNewConsole(): void
{
$this->createNewConsole = true;

$optionsReflectionProperty = new \ReflectionProperty(SymfonyProcess::class, 'options');
$optionsReflectionProperty = new ReflectionProperty(SymfonyProcess::class, 'options');
$optionsReflectionProperty->setAccessible(true);
$options = $optionsReflectionProperty->getValue($this);
$options = is_array($options) ? $options : [];
Expand All @@ -95,7 +98,7 @@ public static function __callStatic(string $name, array $arguments):mixed
if ($name === 'fromShellCommandline') {
$command = array_shift($arguments);
$process = new self([], ...$arguments); // @phpstan-ignore-line
$processCommandLineProperty = new \ReflectionProperty(SymfonyProcess::class, 'commandline');
$processCommandLineProperty = new ReflectionProperty(SymfonyProcess::class, 'commandline');
$processCommandLineProperty->setAccessible(true);
$processCommandLineProperty->setValue($process, $command);

Expand Down
Loading

0 comments on commit a4764ae

Please sign in to comment.