mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2b0aa4b9c9 | |||
| 040eb8142d | |||
| d1aeabc9da | |||
| e4ec2b3efa | |||
| dedcc6b887 | |||
| 2b0ed2bc45 | |||
| 9c859ae7c4 | |||
| ae0a230046 | |||
| 644fade478 | |||
| c9e919dd40 | |||
| 42323e27b1 | |||
| 3927177b23 | |||
| 038fd80428 |
@ -23,11 +23,11 @@
|
|||||||
"nunomaduro/termwind": "^1.15.1",
|
"nunomaduro/termwind": "^1.15.1",
|
||||||
"pestphp/pest-plugin": "^2.1.1",
|
"pestphp/pest-plugin": "^2.1.1",
|
||||||
"pestphp/pest-plugin-arch": "^2.3.3",
|
"pestphp/pest-plugin-arch": "^2.3.3",
|
||||||
"phpunit/phpunit": "^10.3.2"
|
"phpunit/phpunit": "^10.3.3"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"webmozart/assert": "<1.11.0",
|
"webmozart/assert": "<1.11.0",
|
||||||
"phpunit/phpunit": ">10.3.2"
|
"phpunit/phpunit": ">10.3.3"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
@ -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.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -185,7 +185,7 @@ final class OppositeExpectation
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the given expectation targets is an class.
|
* Asserts that the given expectation targets is not class.
|
||||||
*/
|
*/
|
||||||
public function toBeClass(): ArchExpectation
|
public function toBeClass(): ArchExpectation
|
||||||
{
|
{
|
||||||
@ -227,7 +227,7 @@ final class OppositeExpectation
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the given expectation target to be subclass of the given class.
|
* Asserts that the given expectation target to be not subclass of the given class.
|
||||||
*
|
*
|
||||||
* @param class-string $class
|
* @param class-string $class
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -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";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -142,7 +142,7 @@ final class TestCaseFactory
|
|||||||
$namespace = implode('\\', $partsFQN);
|
$namespace = implode('\\', $partsFQN);
|
||||||
$baseClass = sprintf('\%s', $this->class);
|
$baseClass = sprintf('\%s', $this->class);
|
||||||
|
|
||||||
if ('' === trim($className)) {
|
if (trim($className) === '') {
|
||||||
$className = 'InvalidTestName'.Str::random();
|
$className = 'InvalidTestName'.Str::random();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ use Pest\Matchers\Any;
|
|||||||
use Pest\Support\Arr;
|
use Pest\Support\Arr;
|
||||||
use Pest\Support\Exporter;
|
use Pest\Support\Exporter;
|
||||||
use Pest\Support\NullClosure;
|
use Pest\Support\NullClosure;
|
||||||
|
use Pest\Support\Str;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use PHPUnit\Framework\Assert;
|
use PHPUnit\Framework\Assert;
|
||||||
use PHPUnit\Framework\Constraint\Constraint;
|
use PHPUnit\Framework\Constraint\Constraint;
|
||||||
@ -926,7 +927,7 @@ final class Expectation
|
|||||||
$callback = $exception;
|
$callback = $exception;
|
||||||
$parameters = (new ReflectionFunction($exception))->getParameters();
|
$parameters = (new ReflectionFunction($exception))->getParameters();
|
||||||
|
|
||||||
if (1 !== count($parameters)) {
|
if (count($parameters) !== 1) {
|
||||||
throw new InvalidArgumentException('The given closure must have a single parameter type-hinted as the class string.');
|
throw new InvalidArgumentException('The given closure must have a single parameter type-hinted as the class string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -950,7 +951,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;
|
||||||
@ -1111,4 +1112,20 @@ final class Expectation
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the value is UUID.
|
||||||
|
*
|
||||||
|
* @return self<TValue>
|
||||||
|
*/
|
||||||
|
public function toBeUuid(string $message = ''): self
|
||||||
|
{
|
||||||
|
if (! is_string($this->value)) {
|
||||||
|
InvalidExpectationValue::expected('string');
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert::assertTrue(Str::isUuid($this->value), $message);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -6,7 +6,7 @@ namespace Pest;
|
|||||||
|
|
||||||
function version(): string
|
function version(): string
|
||||||
{
|
{
|
||||||
return '2.17.0';
|
return '2.18.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDirectory(string $file = ''): string
|
function testDirectory(string $file = ''): string
|
||||||
|
|||||||
@ -51,7 +51,7 @@ final class Str
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return substr($target, -$length) === $search;
|
return $search === substr($target, -$length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,4 +92,20 @@ final class Str
|
|||||||
{
|
{
|
||||||
return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0];
|
return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if a given value is a valid UUID.
|
||||||
|
*/
|
||||||
|
public static function isUuid(string $value): bool
|
||||||
|
{
|
||||||
|
return preg_match('/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/iD', $value) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a describe block as `$describeDescription` → `$testDescription` format.
|
||||||
|
*/
|
||||||
|
public static function describe(string $describeDescription, string $testDescription): string
|
||||||
|
{
|
||||||
|
return sprintf('`%s` → %s', $describeDescription, $testDescription);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
Pest Testing Framework 2.17.0.
|
Pest Testing Framework 2.18.0.
|
||||||
|
|
||||||
USAGE: pest <file> [options]
|
USAGE: pest <file> [options]
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
|
|
||||||
Pest Testing Framework 2.17.0.
|
Pest Testing Framework 2.18.0.
|
||||||
|
|
||||||
|
|||||||
@ -187,6 +187,10 @@
|
|||||||
✓ with with (1)
|
✓ with with (1)
|
||||||
✓ with on hook → value with (2)
|
✓ with on hook → value with (2)
|
||||||
✓ with on describe → value with (3)
|
✓ with on describe → value with (3)
|
||||||
|
✓ depends on describe → foo
|
||||||
|
✓ depends on describe → bar
|
||||||
|
✓ depends on describe using with → foo with (3)
|
||||||
|
✓ depends on describe using with → bar with (3)
|
||||||
|
|
||||||
PASS Tests\Features\DescriptionLess
|
PASS Tests\Features\DescriptionLess
|
||||||
✓ get 'foo'
|
✓ get 'foo'
|
||||||
@ -574,6 +578,13 @@
|
|||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
✓ failures with custom message
|
✓ failures with custom message
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Features\Expect\toBeUuid
|
||||||
|
✓ failures with wrong type
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
|
✓ failures with message
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toBeWritableDirectory
|
PASS Tests\Features\Expect\toBeWritableDirectory
|
||||||
@ -1314,4 +1325,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, 930 passed (2200 assertions)
|
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 939 passed (2220 assertions)
|
||||||
@ -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]);
|
||||||
|
|||||||
31
tests/Features/Expect/toBeUuid.php
Normal file
31
tests/Features/Expect/toBeUuid.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Pest\Exceptions\InvalidExpectationValue;
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
test('failures with wrong type', function () {
|
||||||
|
expect([])->toBeUuid();
|
||||||
|
})->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].');
|
||||||
|
|
||||||
|
test('pass', function () {
|
||||||
|
expect('3cafb226-4326-11ee-a516-846993788c86')->toBeUuid(); // version 1
|
||||||
|
expect('0000415c-4326-21ee-a700-846993788c86')->toBeUuid(); // version 2
|
||||||
|
expect('3f703955-aaba-3e70-a3cb-baff6aa3b28f')->toBeUuid(); // version 3
|
||||||
|
expect('ca0a8228-cdf6-41db-b34b-c2f31485796c')->toBeUuid(); // version 4
|
||||||
|
expect('a35477ae-bfb1-5f2e-b5a4-4711594d855f')->toBeUuid(); // version 5
|
||||||
|
expect('1ee43263-cf5a-6fd8-8f47-846993788c86')->toBeUuid(); // version 6
|
||||||
|
expect('018a2bef-09f2-728c-becb-c3f569d91486')->toBeUuid(); // version 7
|
||||||
|
expect('00112233-4455-8677-8899-aabbccddeeff')->toBeUuid(); // version 8
|
||||||
|
});
|
||||||
|
|
||||||
|
test('failures', function () {
|
||||||
|
expect('foo')->toBeUuid();
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('failures with message', function () {
|
||||||
|
expect('bar')->toBeUuid('oh no!');
|
||||||
|
})->throws(ExpectationFailedException::class, 'oh no!');
|
||||||
|
|
||||||
|
test('not failures', function () {
|
||||||
|
expect('foo')->not->toBeUuid();
|
||||||
|
});
|
||||||
@ -16,7 +16,7 @@ $run = function () {
|
|||||||
|
|
||||||
test('parallel', function () use ($run) {
|
test('parallel', function () use ($run) {
|
||||||
expect($run('--exclude-group=integration'))
|
expect($run('--exclude-group=integration'))
|
||||||
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 919 passed (2185 assertions)')
|
->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 928 passed (2205 assertions)')
|
||||||
->toContain('Parallel: 3 processes');
|
->toContain('Parallel: 3 processes');
|
||||||
})->skipOnWindows();
|
})->skipOnWindows();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user