mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 17:57:23 +01:00
create Any matcher
This commit is contained in:
@ -14,6 +14,7 @@ use Pest\Exceptions\InvalidExpectationValue;
|
||||
use Pest\Expectations\EachExpectation;
|
||||
use Pest\Expectations\HigherOrderExpectation;
|
||||
use Pest\Expectations\OppositeExpectation;
|
||||
use Pest\Matchers\Any;
|
||||
use Pest\Support\ExpectationPipeline;
|
||||
use PHPUnit\Framework\Assert;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
@ -339,4 +340,9 @@ final class Expectation
|
||||
|| method_exists(Mixins\Expectation::class, $name)
|
||||
|| self::hasExtend($name);
|
||||
}
|
||||
|
||||
public function any(): Any
|
||||
{
|
||||
return new Any();
|
||||
}
|
||||
}
|
||||
|
||||
9
src/Matchers/Any.php
Normal file
9
src/Matchers/Any.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Matchers;
|
||||
|
||||
final class Any
|
||||
{
|
||||
}
|
||||
@ -9,9 +9,9 @@ use Closure;
|
||||
use Error;
|
||||
use InvalidArgumentException;
|
||||
use Pest\Exceptions\InvalidExpectationValue;
|
||||
use Pest\Matchers\Any;
|
||||
use Pest\Support\Arr;
|
||||
use Pest\Support\NullClosure;
|
||||
use Pest\Support\NullValue;
|
||||
use PHPUnit\Framework\Assert;
|
||||
use PHPUnit\Framework\Constraint\Constraint;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
@ -272,14 +272,14 @@ final class Expectation
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function toHaveProperty(string $name, mixed $value = new NullValue(), string $failureMessage = ''): self
|
||||
public function toHaveProperty(string $name, mixed $value = new Any(), string $failureMessage = ''): self
|
||||
{
|
||||
$this->toBeObject();
|
||||
|
||||
// @phpstan-ignore-next-line
|
||||
Assert::assertTrue(property_exists($this->value, $name), $failureMessage);
|
||||
|
||||
if (! $value instanceof NullValue) {
|
||||
if (! $value instanceof Any) {
|
||||
/* @phpstan-ignore-next-line */
|
||||
Assert::assertEquals($value, $this->value->{$name}, $failureMessage);
|
||||
}
|
||||
@ -559,7 +559,7 @@ final class Expectation
|
||||
*
|
||||
* @return self<TValue>
|
||||
*/
|
||||
public function toHaveKey(string|int $key, mixed $value = new NullValue(), string $failureMessage = ''): self
|
||||
public function toHaveKey(string|int $key, mixed $value = new Any(), string $failureMessage = ''): self
|
||||
{
|
||||
if (is_object($this->value) && method_exists($this->value, 'toArray')) {
|
||||
$array = $this->value->toArray();
|
||||
@ -579,7 +579,7 @@ final class Expectation
|
||||
throw new ExpectationFailedException($failureMessage, $exception->getComparisonFailure());
|
||||
}
|
||||
|
||||
if (! $value instanceof NullValue) {
|
||||
if (! $value instanceof Any) {
|
||||
Assert::assertEquals($value, Arr::get($array, $key), $failureMessage);
|
||||
}
|
||||
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Support;
|
||||
|
||||
final class NullValue
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user