Skip to content

Commit

Permalink
Merge pull request #676 from lucatume/v35-wptestcase-rector
Browse files Browse the repository at this point in the history
v35 wptestcase rector
  • Loading branch information
lucatume authored Nov 27, 2023
2 parents 255ab20 + beffe0d commit 9c9440c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
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

0 comments on commit 9c9440c

Please sign in to comment.