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

v35 wptestcase rector #676

Merged
merged 3 commits into from
Nov 27, 2023
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: 3 additions & 1 deletion src/Process/Loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ public function addWorkers(array $workers, array $options = []): Loop
}
}

array_push($this->workers, ...$builtWorkers);
if (count($builtWorkers)) {
array_push($this->workers, ...$builtWorkers);
}
$this->sortWorkersByResource();

return $this;
Expand Down
14 changes: 7 additions & 7 deletions src/Process/Worker/worker-script.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
use lucatume\WPBrowser\Process\Protocol\Response;
use lucatume\WPBrowser\Process\SerializableThrowable;

$processSrcRoot = __DIR__ . '/..';
require_once $processSrcRoot . '/Protocol/Parser.php';
require_once $processSrcRoot . '/Protocol/Control.php';
require_once $processSrcRoot . '/Protocol/Request.php';
require_once $processSrcRoot . '/Protocol/ProtocolException.php';
require_once __DIR__ . '/../Protocol/Parser.php';
require_once __DIR__ . '/../Protocol/Control.php';
require_once __DIR__ . '/../Protocol/Request.php';
require_once __DIR__ . '/../Protocol/ProtocolException.php';

try {
if (!isset($argv[1])) {
Expand All @@ -22,8 +21,9 @@
}

$request = Request::fromPayload($payload);
$serializableClosure = $request->getSerializableClosure();
$returnValue = $serializableClosure();
$_wpBrowserWorkerClosure = $request->getSerializableClosure();
unset($payload, $request);
$returnValue = $_wpBrowserWorkerClosure();
} catch (Throwable $throwable) {
$returnValue = new SerializableThrowable($throwable);
}
Expand Down
28 changes: 23 additions & 5 deletions src/TestCase/WPTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class WPTestCase extends Unit
// Additional globals.
'_wp_registered_theme_features',
// wp-browser
'_wpBrowserWorkerClosure',
'_wpTestsBackupGlobals',
'_wpTestsBackupGlobalsExcludeList',
'_wpTestsBackupStaticAttributes',
Expand Down Expand Up @@ -77,12 +78,19 @@ public function __construct(?string $name = null, array $data = [], $dataName =
$_wpTestsBackupStaticAttributesExcludeList;

$backupGlobalsReflectionProperty = new \ReflectionProperty($this, 'backupGlobals');
$backupGlobalsReflectionProperty->setAccessible(true);
$isDefinedInThis = $backupGlobalsReflectionProperty->getDeclaringClass()->getName() !== WPTestCase::class;
if (!$isDefinedInThis && isset($_wpTestsBackupGlobals) && is_bool($_wpTestsBackupGlobals)) {
$this->backupGlobals = $_wpTestsBackupGlobals;
}

$backupGlobalsExcludeListReflectionProperty = new \ReflectionProperty($this, 'backupGlobalsExcludeList');
if (property_exists($this, 'backupGlobalsExcludeList')) {
$backupGlobalsExcludeListReflectionProperty = new \ReflectionProperty($this, 'backupGlobalsExcludeList');
} else {
// Older versions of PHPUnit.
$backupGlobalsExcludeListReflectionProperty = new \ReflectionProperty($this, 'backupGlobalsBlacklist');
}
$backupGlobalsExcludeListReflectionProperty->setAccessible(true);
$isDefinedInThis = $backupGlobalsExcludeListReflectionProperty->getDeclaringClass()
->getName() !== WPTestCase::class;
if (!$isDefinedInThis
Expand All @@ -96,16 +104,26 @@ public function __construct(?string $name = null, array $data = [], $dataName =
}

$backupStaticAttributesReflectionProperty = new \ReflectionProperty($this, 'backupStaticAttributes');
$backupStaticAttributesReflectionProperty->setAccessible(true);
$isDefinedInThis = $backupStaticAttributesReflectionProperty->getDeclaringClass()
->getName() !== WPTestCase::class;
if (!$isDefinedInThis && isset($_wpTestsBackupStaticAttributes) && is_bool($_wpTestsBackupStaticAttributes)) {
$this->backupStaticAttributes = $_wpTestsBackupStaticAttributes;
}

$backupStaticAttributesExcludeListReflectionProperty = new \ReflectionProperty(
$this,
'backupStaticAttributesExcludeList'
);
if (property_exists($this, 'backupStaticAttributesExcludeList')) {
$backupStaticAttributesExcludeListReflectionProperty = new \ReflectionProperty(
$this,
'backupStaticAttributesExcludeList'
);
} else {
// Older versions of PHPUnit.
$backupStaticAttributesExcludeListReflectionProperty = new \ReflectionProperty(
$this,
'backupStaticAttributesBlacklist'
);
}
$backupStaticAttributesExcludeListReflectionProperty->setAccessible(true);
$isDefinedInThis = $backupStaticAttributesExcludeListReflectionProperty->getDeclaringClass()
->getName() !== WPTestCase::class;
if (!$isDefinedInThis
Expand Down