diff --git a/overrides/Runner/TestSuiteLoader.php b/overrides/Runner/TestSuiteLoader.php index 9c1a0935..cc36904c 100644 --- a/overrides/Runner/TestSuiteLoader.php +++ b/overrides/Runner/TestSuiteLoader.php @@ -132,7 +132,7 @@ final class TestSuiteLoader continue; } - if ($class->isAbstract() || ($class->getFileName() !== $suiteClassFile)) { + if ($class->isAbstract() || ($suiteClassFile !== $class->getFileName())) { if (! str_contains($class->getFileName(), 'TestCaseFactory.php')) { continue; } diff --git a/src/Expectation.php b/src/Expectation.php index ef3c3950..979dde28 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -239,7 +239,7 @@ final class Expectation $index = isset($callbacks[$index + 1]) ? $index + 1 : 0; } - if (count($callbacks) > $valuesCount) { + if ($valuesCount < count($callbacks)) { throw new OutOfRangeException('Sequence expectations are more than the iterable items.'); } diff --git a/src/Factories/Annotations/Depends.php b/src/Factories/Annotations/Depends.php index 24fb03cc..2da826ea 100644 --- a/src/Factories/Annotations/Depends.php +++ b/src/Factories/Annotations/Depends.php @@ -19,7 +19,7 @@ final class Depends implements AddsAnnotations public function __invoke(TestCaseMethodFactory $method, array $annotations): array { foreach ($method->depends as $depend) { - $depend = Str::evaluable($depend); + $depend = Str::evaluable($method->describing !== null ? Str::describe($method->describing, $depend) : $depend); $annotations[] = "@depends $depend"; } diff --git a/src/Factories/TestCaseFactory.php b/src/Factories/TestCaseFactory.php index cbe50985..f6f518c1 100644 --- a/src/Factories/TestCaseFactory.php +++ b/src/Factories/TestCaseFactory.php @@ -241,7 +241,7 @@ final class TestCaseFactory throw ShouldNotHappen::fromMessage('The test description may not be empty.'); } - if (Str::evaluable($method->description) === $methodName) { + if ($methodName === Str::evaluable($method->description)) { return true; } } @@ -259,7 +259,7 @@ final class TestCaseFactory throw ShouldNotHappen::fromMessage('The test description may not be empty.'); } - if (Str::evaluable($method->description) === $methodName) { + if ($methodName === Str::evaluable($method->description)) { return $method; } } diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index 2617fea4..400095f9 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -950,7 +950,7 @@ final class Expectation } if (! class_exists($exception)) { - if ($e instanceof Error && $e->getMessage() === "Class \"$exception\" not found") { + if ($e instanceof Error && "Class \"$exception\" not found" === $e->getMessage()) { Assert::assertTrue(true); throw $e; diff --git a/src/PendingCalls/TestCall.php b/src/PendingCalls/TestCall.php index 9b1edabc..6ade188b 100644 --- a/src/PendingCalls/TestCall.php +++ b/src/PendingCalls/TestCall.php @@ -16,6 +16,7 @@ use Pest\Support\Backtrace; use Pest\Support\Exporter; use Pest\Support\HigherOrderCallables; use Pest\Support\NullClosure; +use Pest\Support\Str; use Pest\TestSuite; use PHPUnit\Framework\TestCase; @@ -209,7 +210,7 @@ final class TestCall */ private function skipOn(string $osFamily, string $message): self { - return PHP_OS_FAMILY === $osFamily + return $osFamily === PHP_OS_FAMILY ? $this->skip($message) : $this; } @@ -361,7 +362,7 @@ final class TestCall { if (! is_null($this->describing)) { $this->testCaseMethod->describing = $this->describing; - $this->testCaseMethod->description = sprintf('`%s` → %s', $this->describing, $this->testCaseMethod->description); + $this->testCaseMethod->description = Str::describe($this->describing, $this->testCaseMethod->description); // @phpstan-ignore-line } $this->testSuite->tests->set($this->testCaseMethod); diff --git a/src/Support/Str.php b/src/Support/Str.php index ee4e7231..35b109c3 100644 --- a/src/Support/Str.php +++ b/src/Support/Str.php @@ -51,7 +51,7 @@ final class Str return true; } - return substr($target, -$length) === $search; + return $search === substr($target, -$length); } /** @@ -92,4 +92,12 @@ final class Str { return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0]; } + + /** + * Creates a describe block as `$right` → `$left` format. + */ + public static function describe(string $right, string $left): string + { + return sprintf('`%s` → %s', $right, $left); + } } diff --git a/tests/Features/Describe.php b/tests/Features/Describe.php index 6173a4dd..64bf3453 100644 --- a/tests/Features/Describe.php +++ b/tests/Features/Describe.php @@ -76,3 +76,23 @@ describe('with on describe', function () { expect($foo)->toBe(3); }); })->with([3]); + +describe('depends on describe', function () { + test('foo', function () { + expect('foo')->toBe('foo'); + }); + + test('bar', function () { + expect('bar')->toBe('bar'); + })->depends('foo'); +}); + +describe('depends on describe using with', function () { + test('foo', function ($foo) { + expect($foo)->toBe(3); + }); + + test('bar', function ($foo) { + expect($foo + $foo)->toBe(6); + })->depends('foo'); +})->with([3]);