Merge branch 'master' into nested-higher-order-expectations

# Conflicts:
#	src/Expectation.php
#	tests/.snapshots/success.txt
This commit is contained in:
luke
2021-06-17 00:17:25 +01:00
5 changed files with 158 additions and 16 deletions

View File

@ -7,8 +7,10 @@ namespace Pest;
use BadMethodCallException;
use Pest\Concerns\Extendable;
use Pest\Concerns\RetrievesValues;
use Pest\Support\Arr;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\ExpectationFailedException;
use SebastianBergmann\Exporter\Exporter;
/**
@ -526,10 +528,16 @@ final class Expectation
$array = (array) $this->value;
}
Assert::assertArrayHasKey($key, $array);
try {
Assert::assertTrue(Arr::has($array, $key));
/* @phpstan-ignore-next-line */
} catch (ExpectationFailedException $exception) {
throw new ExpectationFailedException("Failed asserting that an array has the key '$key'", $exception->getComparisonFailure());
}
if (func_num_args() > 1) {
Assert::assertEquals($value, $array[$key]);
Assert::assertEquals($value, Arr::get($array, $key));
}
return $this;