Merge branch 'master' into non-callable-sequence

# Conflicts:
#	tests/.snapshots/success.txt
This commit is contained in:
luke
2021-06-18 21:45:02 +01:00
9 changed files with 190 additions and 17 deletions

View File

@ -6,8 +6,10 @@ namespace Pest;
use BadMethodCallException;
use Pest\Concerns\Extendable;
use Pest\Support\Arr;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\ExpectationFailedException;
use SebastianBergmann\Exporter\Exporter;
/**
@ -58,6 +60,14 @@ final class Expectation
return new self($value);
}
/**
* Creates a new expectation with the decoded JSON value.
*/
public function json(): Expectation
{
return $this->toBeJson()->and(json_decode($this->value, true));
}
/**
* Dump the expectation value and end the script.
*
@ -529,10 +539,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;