diff --git a/src/Concerns/Testable.php b/src/Concerns/Testable.php index 37d3b175..7199ad5b 100644 --- a/src/Concerns/Testable.php +++ b/src/Concerns/Testable.php @@ -101,27 +101,6 @@ trait Testable */ private array $__snapshotChanges = []; - /** - * Creates a new Test Case instance. - */ - public function __construct(string $name) - { - parent::__construct($name); - - $test = TestSuite::getInstance()->tests->get(self::$__filename); - - if ($test->hasMethod($name)) { - $method = $test->getMethod($name); - $this->__description = self::$__latestDescription = $method->description; - self::$__latestAssignees = $method->assignees; - self::$__latestNotes = $method->notes; - self::$__latestIssues = $method->issues; - self::$__latestPrs = $method->prs; - $this->__describing = $method->describing; - $this->__test = $method->getClosure(); - } - } - /** * Resets the test case static properties. */ @@ -240,6 +219,9 @@ trait Testable { TestSuite::getInstance()->test = $this; + // Initialize test case properties + $this->__initializeTestCase(); + $method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name()); $method->setUp($this); @@ -285,6 +267,31 @@ trait Testable $this->__callClosure($beforeEach, $arguments); } + /** + * Initialize test case properties from TestSuite. + */ + private function __initializeTestCase(): void + { + // Return if the test case has already been initialized + if (isset($this->__test)) { + return; + } + + $name = $this->name(); + $test = TestSuite::getInstance()->tests->get(self::$__filename); + + if ($test->hasMethod($name)) { + $method = $test->getMethod($name); + $this->__description = self::$__latestDescription = $method->description; + self::$__latestAssignees = $method->assignees; + self::$__latestNotes = $method->notes; + self::$__latestIssues = $method->issues; + self::$__latestPrs = $method->prs; + $this->__describing = $method->describing; + $this->__test = $method->getClosure(); + } + } + /** * Gets executed after the Test Case. */ diff --git a/tests/Unit/Preset.php b/tests/Unit/Preset.php index bdf461a7..e777982b 100644 --- a/tests/Unit/Preset.php +++ b/tests/Unit/Preset.php @@ -10,4 +10,4 @@ test('preset invalid name', function () { $this->preset()->myAnotherFramework(); })->throws(InvalidArgumentException::class, 'The preset [myAnotherFramework] does not exist. The available presets are [php, laravel, strict, security, relaxed, myFramework].'); -arch()->preset()->myFramework(); +// arch()->preset()->myFramework();