diff --git a/src/Assert/AssertCaseTrait.php b/src/Assert/AssertCaseTrait.php index eb865bd..f416404 100644 --- a/src/Assert/AssertCaseTrait.php +++ b/src/Assert/AssertCaseTrait.php @@ -4,8 +4,6 @@ namespace Asynit\Assert; -use Asynit\Attribute\OnCreate; -use Asynit\Test; use bovigo\assert\predicate\Predicate; use function bovigo\assert\counting; @@ -50,14 +48,6 @@ trait AssertCaseTrait { - protected Test $test; - - #[OnCreate] - public function setUpTest(Test $test): void - { - $this->test = $test; - } - /** * Asserts that an array has a specified key. * @@ -535,7 +525,7 @@ public function assertContainsSubset(array $other, array $subset, bool $strict = public function assert($value, callable $predicate, ?string $description = null): bool { - return (new Assertion($value, exporter(), $this->test)) + return (new Assertion($value, exporter())) ->evaluate(counting(Predicate::castFrom($predicate)), $description); } diff --git a/src/Assert/Assertion.php b/src/Assert/Assertion.php index 8c9e2b1..93937af 100644 --- a/src/Assert/Assertion.php +++ b/src/Assert/Assertion.php @@ -4,6 +4,7 @@ namespace Asynit\Assert; +use Asynit\Runner\TestStorage; use Asynit\Test; use bovigo\assert\Assertion as BaseAssertion; use bovigo\assert\AssertionFailure; @@ -16,18 +17,15 @@ class Assertion extends BaseAssertion private Exporter $exporter; - private Test $test; - /** * constructor. */ - public function __construct($value, Exporter $exporter, Test $test) + public function __construct($value, Exporter $exporter) { parent::__construct($value, $exporter); $this->value = $value; $this->exporter = $exporter; - $this->test = $test; } public function evaluate(Predicate $predicate, ?string $description = null): bool @@ -50,7 +48,7 @@ public function evaluate(Predicate $predicate, ?string $description = null): boo throw new AssertionFailure($message); } - $this->test->addAssertion($this->describeSuccess($predicate, $description)); + TestStorage::get()?->addAssertion($this->describeSuccess($predicate, $description)); return $result; } diff --git a/src/Runner/PoolRunner.php b/src/Runner/PoolRunner.php index 0eb61ce..6167653 100644 --- a/src/Runner/PoolRunner.php +++ b/src/Runner/PoolRunner.php @@ -46,6 +46,8 @@ public function loop(Pool $pool): void $futures[$test->getIdentifier()] = async(function () use ($test, &$futures) { $lock = $this->semaphore->acquire(); + TestStorage::set($test); + $this->run($test); $lock->release(); @@ -100,7 +102,7 @@ private function getTestCase(Test $test): object continue; } - $testCase->{$reflectionMethod->getName()}($test); + $testCase->{$reflectionMethod->getName()}(); } $this->testCases[$reflectionClass->getName()] = $testCase; diff --git a/src/Runner/TestStorage.php b/src/Runner/TestStorage.php new file mode 100644 index 0000000..2ad275a --- /dev/null +++ b/src/Runner/TestStorage.php @@ -0,0 +1,36 @@ +