fix: test description on beforeEach failure

This commit is contained in:
Nuno Maduro
2023-07-22 09:33:41 -05:00
parent cf5275293f
commit 5637dfa75d
3 changed files with 14 additions and 6 deletions

View File

@ -185,6 +185,10 @@ trait Testable
{ {
TestSuite::getInstance()->test = $this; TestSuite::getInstance()->test = $this;
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
$this->__description = self::$__latestDescription = $this->dataName() ? $method->description.' with '.$this->dataName() : $method->description;
parent::setUp(); parent::setUp();
$beforeEach = TestSuite::getInstance()->beforeEach->get(self::$__filename)[1]; $beforeEach = TestSuite::getInstance()->beforeEach->get(self::$__filename)[1];
@ -234,10 +238,6 @@ trait Testable
*/ */
private function __resolveTestArguments(array $arguments): array private function __resolveTestArguments(array $arguments): array
{ {
$method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name());
$this->__description = self::$__latestDescription = $this->dataName() ? $method->description.' with '.$this->dataName() : $method->description;
$underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure'); $underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure');
$testParameterTypes = array_values(Reflection::getFunctionArguments($underlyingTest)); $testParameterTypes = array_values(Reflection::getFunctionArguments($underlyingTest));

View File

@ -1052,6 +1052,7 @@
✓ it can return an array of all test suite filenames ✓ it can return an array of all test suite filenames
PASS Tests\Visual\BeforeEachTestName PASS Tests\Visual\BeforeEachTestName
✓ description
✓ latest description ✓ latest description
PASS Tests\Visual\Collision PASS Tests\Visual\Collision
@ -1084,4 +1085,4 @@
WARN Tests\Visual\Version WARN Tests\Visual\Version
- visual snapshot of help command output - visual snapshot of help command output
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 742 passed (1787 assertions) Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 743 passed (1788 assertions)

View File

@ -1,6 +1,13 @@
<?php <?php
beforeEach(fn () => $this->latestDescription = self::$__latestDescription); beforeEach(function () {
$this->description = $this->__description;
$this->latestDescription = self::$__latestDescription;
});
test('description', function () {
expect($this->description)->toBe('description');
});
test('latest description', function () { test('latest description', function () {
expect($this->latestDescription)->toBe('latest description'); expect($this->latestDescription)->toBe('latest description');