mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
finishing the code
This commit is contained in:
@ -132,7 +132,7 @@ final class TestSuiteLoader
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($class->isAbstract() || ($class->getFileName() !== $suiteClassFile)) {
|
if ($class->isAbstract() || ($suiteClassFile !== $class->getFileName())) {
|
||||||
if (! str_contains($class->getFileName(), 'TestCaseFactory.php')) {
|
if (! str_contains($class->getFileName(), 'TestCaseFactory.php')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -239,7 +239,7 @@ final class Expectation
|
|||||||
$index = isset($callbacks[$index + 1]) ? $index + 1 : 0;
|
$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.');
|
throw new OutOfRangeException('Sequence expectations are more than the iterable items.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,7 @@ final class Depends implements AddsAnnotations
|
|||||||
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
public function __invoke(TestCaseMethodFactory $method, array $annotations): array
|
||||||
{
|
{
|
||||||
foreach ($method->depends as $depend) {
|
foreach ($method->depends as $depend) {
|
||||||
$depend = Str::evaluable($depend);
|
$depend = Str::evaluable($method->describing !== null ? Str::describe($method->describing, $depend) : $depend);
|
||||||
|
|
||||||
$annotations[] = "@depends $depend";
|
$annotations[] = "@depends $depend";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -241,7 +241,7 @@ final class TestCaseFactory
|
|||||||
throw ShouldNotHappen::fromMessage('The test description may not be empty.');
|
throw ShouldNotHappen::fromMessage('The test description may not be empty.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Str::evaluable($method->description) === $methodName) {
|
if ($methodName === Str::evaluable($method->description)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ final class TestCaseFactory
|
|||||||
throw ShouldNotHappen::fromMessage('The test description may not be empty.');
|
throw ShouldNotHappen::fromMessage('The test description may not be empty.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Str::evaluable($method->description) === $methodName) {
|
if ($methodName === Str::evaluable($method->description)) {
|
||||||
return $method;
|
return $method;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -950,7 +950,7 @@ final class Expectation
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! class_exists($exception)) {
|
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);
|
Assert::assertTrue(true);
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
|
|||||||
@ -16,6 +16,7 @@ use Pest\Support\Backtrace;
|
|||||||
use Pest\Support\Exporter;
|
use Pest\Support\Exporter;
|
||||||
use Pest\Support\HigherOrderCallables;
|
use Pest\Support\HigherOrderCallables;
|
||||||
use Pest\Support\NullClosure;
|
use Pest\Support\NullClosure;
|
||||||
|
use Pest\Support\Str;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
@ -209,7 +210,7 @@ final class TestCall
|
|||||||
*/
|
*/
|
||||||
private function skipOn(string $osFamily, string $message): self
|
private function skipOn(string $osFamily, string $message): self
|
||||||
{
|
{
|
||||||
return PHP_OS_FAMILY === $osFamily
|
return $osFamily === PHP_OS_FAMILY
|
||||||
? $this->skip($message)
|
? $this->skip($message)
|
||||||
: $this;
|
: $this;
|
||||||
}
|
}
|
||||||
@ -361,7 +362,7 @@ final class TestCall
|
|||||||
{
|
{
|
||||||
if (! is_null($this->describing)) {
|
if (! is_null($this->describing)) {
|
||||||
$this->testCaseMethod->describing = $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);
|
$this->testSuite->tests->set($this->testCaseMethod);
|
||||||
|
|||||||
@ -51,7 +51,7 @@ final class Str
|
|||||||
return true;
|
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];
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -76,3 +76,23 @@ describe('with on describe', function () {
|
|||||||
expect($foo)->toBe(3);
|
expect($foo)->toBe(3);
|
||||||
});
|
});
|
||||||
})->with([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]);
|
||||||
|
|||||||
Reference in New Issue
Block a user