mirror of
https://github.com/pestphp/pest.git
synced 2026-03-09 09:17:23 +01:00
Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b53e396aac | |||
| 8b327aa8b4 | |||
| d0c6f9bc60 | |||
| b5e066939b | |||
| 7892237408 | |||
| 74df53c72b | |||
| ee26457705 | |||
| 09e6a0944a | |||
| bdee46043a | |||
| 3e25168777 | |||
| 21b8507252 | |||
| d8e283777e | |||
| 2b0aa4b9c9 | |||
| 040eb8142d | |||
| d1aeabc9da | |||
| e4ec2b3efa | |||
| dedcc6b887 | |||
| 2b0ed2bc45 | |||
| 9c859ae7c4 | |||
| ae0a230046 | |||
| 644fade478 | |||
| c9e919dd40 | |||
| 42323e27b1 | |||
| 3927177b23 | |||
| 038fd80428 | |||
| cc6c5bf199 | |||
| b88d9e8ff2 | |||
| 0fc232bbc7 | |||
| 7dcd42d113 | |||
| e79ffc6bad | |||
| 8ea425b266 | |||
| 3a0f6a1d09 | |||
| b9b90295fa | |||
| 9dabecacbf | |||
| 04fa6b6372 | |||
| a0d2856f51 | |||
| bbac28c9f4 | |||
| e69899559d | |||
| e6fe968d44 | |||
| 678898efe7 |
18
CHANGELOG.md
18
CHANGELOG.md
@ -2,6 +2,24 @@
|
|||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
|
## [v2.17.0 (2023-09-04)](https://github.com/pestphp/pest/compare/v2.16.1...v2.17.0)
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `toHaveMethod` expectation ([#947](https://github.com/pestphp/pest/pull/947))
|
||||||
|
- `toHaveAttribute` expectation ([#934](https://github.com/pestphp/pest/pull/934))
|
||||||
|
|
||||||
|
## [v2.16.1 (2023-08-29)](https://github.com/pestphp/pest/compare/v2.16.0...v2.16.1)
|
||||||
|
|
||||||
|
> New changelog format starting this release.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
* `toHaveSameSize` expectation by @hungthai1401 in https://github.com/pestphp/pest/pull/924, https://github.com/pestphp/pest/pull/930
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
* Inconsistent type have count exception by @hungthai1401 in https://github.com/pestphp/pest/pull/923
|
||||||
|
* Datasets defined in `Pest.php`
|
||||||
|
|
||||||
## [v2.16.0 (2023-08-21)](https://github.com/pestphp/pest/compare/v2.15.0...v2.16.0)
|
## [v2.16.0 (2023-08-21)](https://github.com/pestphp/pest/compare/v2.15.0...v2.16.0)
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@ -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.4"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"webmozart/assert": "<1.11.0",
|
"webmozart/assert": "<1.11.0",
|
||||||
"phpunit/phpunit": ">10.3.2"
|
"phpunit/phpunit": ">10.3.4"
|
||||||
},
|
},
|
||||||
"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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -78,6 +78,8 @@ final class BootFiles implements Bootstrapper
|
|||||||
|
|
||||||
private function bootDatasets(string $testsPath): void
|
private function bootDatasets(string $testsPath): void
|
||||||
{
|
{
|
||||||
|
assert(strlen($testsPath) > 0);
|
||||||
|
|
||||||
$files = (new PhpUnitFileIterator)->getFilesAsArray($testsPath, '.php');
|
$files = (new PhpUnitFileIterator)->getFilesAsArray($testsPath, '.php');
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
|
|||||||
@ -14,7 +14,7 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
final class NoDirtyTestsFound extends InvalidArgumentException implements ExceptionInterface, RenderlessEditor, RenderlessTrace, Panicable
|
final class NoDirtyTestsFound extends InvalidArgumentException implements ExceptionInterface, Panicable, RenderlessEditor, RenderlessTrace
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Renders the panic on the given output.
|
* Renders the panic on the given output.
|
||||||
|
|||||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest;
|
namespace Pest;
|
||||||
|
|
||||||
|
use Attribute;
|
||||||
use BadMethodCallException;
|
use BadMethodCallException;
|
||||||
use Closure;
|
use Closure;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
@ -238,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.');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -501,6 +502,19 @@ final class Expectation
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target has a specific method.
|
||||||
|
*/
|
||||||
|
public function toHaveMethod(string $method): ArchExpectation
|
||||||
|
{
|
||||||
|
return Targeted::make(
|
||||||
|
$this,
|
||||||
|
fn (ObjectDescription $object): bool => $object->reflectionClass->hasMethod($method),
|
||||||
|
'to have method',
|
||||||
|
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the given expectation target is enum.
|
* Asserts that the given expectation target is enum.
|
||||||
*/
|
*/
|
||||||
@ -833,4 +847,19 @@ final class Expectation
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target to have the given attribute.
|
||||||
|
*
|
||||||
|
* @param class-string<Attribute> $attribute
|
||||||
|
*/
|
||||||
|
public function toHaveAttribute(string $attribute): ArchExpectation
|
||||||
|
{
|
||||||
|
return Targeted::make(
|
||||||
|
$this,
|
||||||
|
fn (ObjectDescription $object): bool => $object->reflectionClass->getAttributes($attribute) !== [],
|
||||||
|
"to have attribute '{$attribute}'",
|
||||||
|
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Expectations;
|
namespace Pest\Expectations;
|
||||||
|
|
||||||
|
use Attribute;
|
||||||
use Pest\Arch\Contracts\ArchExpectation;
|
use Pest\Arch\Contracts\ArchExpectation;
|
||||||
use Pest\Arch\Expectations\Targeted;
|
use Pest\Arch\Expectations\Targeted;
|
||||||
use Pest\Arch\Expectations\ToBeUsedIn;
|
use Pest\Arch\Expectations\ToBeUsedIn;
|
||||||
@ -149,6 +150,19 @@ final class OppositeExpectation
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target does not have a specific method.
|
||||||
|
*/
|
||||||
|
public function toHaveMethod(string $method): ArchExpectation
|
||||||
|
{
|
||||||
|
return Targeted::make(
|
||||||
|
$this->original,
|
||||||
|
fn (ObjectDescription $object): bool => ! $object->reflectionClass->hasMethod($method),
|
||||||
|
'to not have method',
|
||||||
|
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the given expectation target is not enum.
|
* Asserts that the given expectation target is not enum.
|
||||||
*/
|
*/
|
||||||
@ -171,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
|
||||||
{
|
{
|
||||||
@ -213,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
|
||||||
*/
|
*/
|
||||||
@ -378,6 +392,21 @@ final class OppositeExpectation
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target not to have the given attribute.
|
||||||
|
*
|
||||||
|
* @param class-string<Attribute> $attribute
|
||||||
|
*/
|
||||||
|
public function toHaveAttribute(string $attribute): ArchExpectation
|
||||||
|
{
|
||||||
|
return Targeted::make(
|
||||||
|
$this->original,
|
||||||
|
fn (ObjectDescription $object): bool => $object->reflectionClass->getAttributes($attribute) === [],
|
||||||
|
"to not have attribute '{$attribute}'",
|
||||||
|
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle dynamic method calls into the original expectation.
|
* Handle dynamic method calls into the original expectation.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -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,10 +6,10 @@ namespace Pest;
|
|||||||
|
|
||||||
function version(): string
|
function version(): string
|
||||||
{
|
{
|
||||||
return '2.16.1';
|
return '2.18.2';
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDirectory(string $file = ''): string
|
function testDirectory(string $file = ''): string
|
||||||
{
|
{
|
||||||
return TestSuite::getInstance()->testPath.'/'.$file;
|
return TestSuite::getInstance()->testPath.DIRECTORY_SEPARATOR.$file;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,11 +12,6 @@
|
|||||||
<directory suffix="Test.php">./tests/Feature</directory>
|
<directory suffix="Test.php">./tests/Feature</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<coverage>
|
|
||||||
<include>
|
|
||||||
<directory suffix=".php">./app</directory>
|
|
||||||
</include>
|
|
||||||
</coverage>
|
|
||||||
<php>
|
<php>
|
||||||
<env name="APP_ENV" value="testing"/>
|
<env name="APP_ENV" value="testing"/>
|
||||||
<env name="BCRYPT_ROUNDS" value="4"/>
|
<env name="BCRYPT_ROUNDS" value="4"/>
|
||||||
@ -28,4 +23,9 @@
|
|||||||
<env name="SESSION_DRIVER" value="array"/>
|
<env name="SESSION_DRIVER" value="array"/>
|
||||||
<env name="TELESCOPE_ENABLED" value="false"/>
|
<env name="TELESCOPE_ENABLED" value="false"/>
|
||||||
</php>
|
</php>
|
||||||
|
<source>
|
||||||
|
<include>
|
||||||
|
<directory suffix=".php">./app</directory>
|
||||||
|
</include>
|
||||||
|
</source>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
@ -9,10 +9,10 @@
|
|||||||
<directory suffix="Test.php">./tests</directory>
|
<directory suffix="Test.php">./tests</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
<coverage>
|
<source>
|
||||||
<include>
|
<include>
|
||||||
<directory suffix=".php">./app</directory>
|
<directory suffix=".php">./app</directory>
|
||||||
<directory suffix=".php">./src</directory>
|
<directory suffix=".php">./src</directory>
|
||||||
</include>
|
</include>
|
||||||
</coverage>
|
</source>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
Pest Testing Framework 2.16.1.
|
Pest Testing Framework 2.18.2.
|
||||||
|
|
||||||
USAGE: pest <file> [options]
|
USAGE: pest <file> [options]
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
|
|
||||||
Pest Testing Framework 2.16.1.
|
Pest Testing Framework 2.18.2.
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
@ -630,6 +641,11 @@
|
|||||||
✓ failures with custom message
|
✓ failures with custom message
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Features\Expect\toHaveAttribute
|
||||||
|
✓ class has attribute
|
||||||
|
✓ opposite class has attribute
|
||||||
|
✓ class not has attribute
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toHaveCamelCaseKeys
|
PASS Tests\Features\Expect\toHaveCamelCaseKeys
|
||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
@ -695,10 +711,12 @@
|
|||||||
✓ it fails with message
|
✓ it fails with message
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toHaveMethod
|
PASS Tests\Features\Expect\toHaveMethod
|
||||||
✓ pass
|
✓ class has method
|
||||||
✓ failures
|
✓ opposite class has method
|
||||||
✓ failures with message
|
✓ class has method via a parent class
|
||||||
✓ not failures
|
✓ class has method via a trait
|
||||||
|
✓ failure when the class has no method
|
||||||
|
✓ class has no method
|
||||||
|
|
||||||
PASS Tests\Features\Expect\toHaveMethods
|
PASS Tests\Features\Expect\toHaveMethods
|
||||||
✓ pass
|
✓ pass
|
||||||
@ -1307,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, 925 passed (2204 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();
|
||||||
|
});
|
||||||
18
tests/Features/Expect/toHaveAttribute.php
Normal file
18
tests/Features/Expect/toHaveAttribute.php
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||||
|
|
||||||
|
test('class has attribute')
|
||||||
|
->expect('Tests\\Fixtures\\Arch\\ToHaveAttribute\\HaveAttribute')
|
||||||
|
->toHaveAttribute('Tests\\Fixtures\\Arch\\ToHaveAttribute\\Attributes\\AsAttribute');
|
||||||
|
|
||||||
|
test('opposite class has attribute')
|
||||||
|
->throws(ArchExpectationFailedException::class)
|
||||||
|
->expect('Tests\\Fixtures\\Arch\\ToHaveAttribute\\HaveAttribute')
|
||||||
|
->not
|
||||||
|
->toHaveAttribute('Tests\\Fixtures\\Arch\\ToHaveAttribute\\Attributes\\AsAttribute');
|
||||||
|
|
||||||
|
test('class not has attribute')
|
||||||
|
->expect('Tests\\Fixtures\\Arch\\ToHaveAttribute\\NotHaveAttribute')
|
||||||
|
->not
|
||||||
|
->toHaveAttribute('Tests\\Fixtures\\Arch\\ToHaveAttribute\\Attributes\\AsAttribute');
|
||||||
@ -1,28 +1,29 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use Pest\Arch\Exceptions\ArchExpectationFailedException;
|
||||||
|
|
||||||
$object = new class
|
test('class has method')
|
||||||
{
|
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod')
|
||||||
public function foo(): void
|
->toHaveMethod('foo');
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
test('pass', function () use ($object) {
|
test('opposite class has method')
|
||||||
expect($object)->toHaveMethod('foo')
|
->throws(ArchExpectationFailedException::class)
|
||||||
->and($object)->toHaveMethod('foo')
|
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod')
|
||||||
->and($object)->not->toHaveMethod('fooNull');
|
->not->toHaveMethod('foo');
|
||||||
});
|
|
||||||
|
|
||||||
test('failures', function () use ($object) {
|
test('class has method via a parent class')
|
||||||
expect($object)->toHaveMethod('bar');
|
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaParent')
|
||||||
})->throws(ExpectationFailedException::class);
|
->toHaveMethod('foo');
|
||||||
|
|
||||||
test('failures with message', function () use ($object) {
|
test('class has method via a trait')
|
||||||
expect($object)->toHaveMethod(name: 'bar', message: 'oh no!');
|
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaTrait')
|
||||||
})->throws(ExpectationFailedException::class, 'oh no!');
|
->toHaveMethod('foo');
|
||||||
|
|
||||||
test('not failures', function () use ($object) {
|
test('failure when the class has no method')
|
||||||
expect($object)->not->toHaveMethod('foo');
|
->throws(ArchExpectationFailedException::class)
|
||||||
})->throws(ExpectationFailedException::class);
|
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass')
|
||||||
|
->toHaveMethod('foo');
|
||||||
|
|
||||||
|
test('class has no method')
|
||||||
|
->expect('Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass')
|
||||||
|
->not->toHaveMethod('foo');
|
||||||
|
|||||||
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveAttribute\Attributes;
|
||||||
|
|
||||||
|
use Attribute;
|
||||||
|
|
||||||
|
#[Attribute()]
|
||||||
|
class AsAttribute
|
||||||
|
{
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveAttribute\HaveAttribute;
|
||||||
|
|
||||||
|
use Tests\Fixtures\Arch\ToHaveAttribute\Attributes\AsAttribute;
|
||||||
|
|
||||||
|
#[AsAttribute]
|
||||||
|
class HaveAttributeClass
|
||||||
|
{
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveAttribute\NotHaveAttribute;
|
||||||
|
|
||||||
|
class NotHaveAttributeClass
|
||||||
|
{
|
||||||
|
}
|
||||||
13
tests/Fixtures/Arch/ToHaveMethod/HasMethod/HasMethod.php
Normal file
13
tests/Fixtures/Arch/ToHaveMethod/HasMethod/HasMethod.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveMethod\HasMethod;
|
||||||
|
|
||||||
|
class HasMethod
|
||||||
|
{
|
||||||
|
public function foo(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveMethod\HasMethod;
|
||||||
|
|
||||||
|
trait HasMethodTrait
|
||||||
|
{
|
||||||
|
public function foo(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveMethod\HasMethod;
|
||||||
|
|
||||||
|
class HasMethodViaParent extends ParentHasMethodClass
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveMethod\HasMethod;
|
||||||
|
|
||||||
|
class HasMethodViaTrait
|
||||||
|
{
|
||||||
|
use HasMethodTrait;
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveMethod\HasMethod;
|
||||||
|
|
||||||
|
class ParentHasMethodClass
|
||||||
|
{
|
||||||
|
public function foo(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod;
|
||||||
|
|
||||||
|
class HasNoMethodClass
|
||||||
|
{
|
||||||
|
public function bar(): void
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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, 914 passed (2189 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