-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from jolicode/fix/test-ref
fix(assertion): fix assertion added to the invalid test by using a fiber storage
- Loading branch information
Showing
4 changed files
with
43 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Asynit\Runner; | ||
|
||
use Asynit\Test; | ||
|
||
/** @internal */ | ||
final class TestStorage | ||
{ | ||
private static ?\WeakMap $localStorage = null; | ||
|
||
public static function set(Test $test): void | ||
{ | ||
$fiber = \Fiber::getCurrent(); | ||
|
||
if (null === $fiber) { | ||
return; | ||
} | ||
|
||
self::$localStorage ??= new \WeakMap(); | ||
self::$localStorage[$fiber] = $test; | ||
} | ||
|
||
public static function get(): ?Test | ||
{ | ||
$fiber = \Fiber::getCurrent(); | ||
|
||
if (null === $fiber) { | ||
return null; | ||
} | ||
|
||
self::$localStorage ??= new \WeakMap(); | ||
|
||
return self::$localStorage[$fiber] ?? null; | ||
} | ||
} |