mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
wip toward lvl9
This commit is contained in:
11
src/Exceptions/ExpectationException.php
Normal file
11
src/Exceptions/ExpectationException.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Pest\Exceptions;
|
||||||
|
|
||||||
|
class ExpectationException extends \Exception
|
||||||
|
{
|
||||||
|
public static function invalidValue($expectationName, $valueRequired): ExpectationException
|
||||||
|
{
|
||||||
|
return new ExpectationException(sprintf('%s expectation requires a %s value.', $expectationName, $valueRequired));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,6 +9,7 @@ use Closure;
|
|||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Pest\Concerns\Extendable;
|
use Pest\Concerns\Extendable;
|
||||||
use Pest\Concerns\RetrievesValues;
|
use Pest\Concerns\RetrievesValues;
|
||||||
|
use Pest\Exceptions\ExpectationException;
|
||||||
use Pest\Support\Arr;
|
use Pest\Support\Arr;
|
||||||
use Pest\Support\NullClosure;
|
use Pest\Support\NullClosure;
|
||||||
use PHPUnit\Framework\Assert;
|
use PHPUnit\Framework\Assert;
|
||||||
@ -68,6 +69,10 @@ final class Expectation
|
|||||||
*/
|
*/
|
||||||
public function json(): Expectation
|
public function json(): Expectation
|
||||||
{
|
{
|
||||||
|
if (!is_string($this->value)) {
|
||||||
|
throw ExpectationException::invalidValue('json', 'string');
|
||||||
|
}
|
||||||
|
|
||||||
return $this->toBeJson()->and(json_decode($this->value, true));
|
return $this->toBeJson()->and(json_decode($this->value, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -113,7 +113,10 @@ if (!function_exists('it')) {
|
|||||||
{
|
{
|
||||||
$description = sprintf('it %s', $description);
|
$description = sprintf('it %s', $description);
|
||||||
|
|
||||||
return test($description, $closure);
|
/** @var TestCall $test */
|
||||||
|
$test = test($description, $closure);
|
||||||
|
|
||||||
|
return $test;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -80,7 +80,10 @@ final class HigherOrderExpectation
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->expectationHasMethod($name)) {
|
if (!$this->expectationHasMethod($name)) {
|
||||||
return new self($this->original, $this->retrieve($name, $this->getValue()));
|
/** @var array<string, mixed>|object $value */
|
||||||
|
$value = $this->getValue();
|
||||||
|
|
||||||
|
return new self($this->original, $this->retrieve($name, $value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->performAssertion($name, []);
|
return $this->performAssertion($name, []);
|
||||||
|
|||||||
@ -80,7 +80,10 @@ final class Coverage implements AddsOutput, HandlesArguments
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($input->getOption(self::MIN_OPTION) !== null) {
|
if ($input->getOption(self::MIN_OPTION) !== null) {
|
||||||
$this->coverageMin = (float) $input->getOption(self::MIN_OPTION);
|
/** @var int|float $min_option */
|
||||||
|
$min_option = $input->getOption(self::MIN_OPTION);
|
||||||
|
|
||||||
|
$this->coverageMin = (float) $min_option;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $originals;
|
return $originals;
|
||||||
|
|||||||
@ -41,11 +41,13 @@ final class Container
|
|||||||
*/
|
*/
|
||||||
public function get(string $id)
|
public function get(string $id)
|
||||||
{
|
{
|
||||||
if (array_key_exists($id, $this->instances)) {
|
if (!array_key_exists($id, $this->instances)) {
|
||||||
return $this->instances[$id];
|
$this->instances[$id] = $this->build($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->instances[$id] = $this->build($id);
|
if (!is_object($this->instances[$id])) {
|
||||||
|
throw ShouldNotHappen::fromMessage('Cannot resolve a non-object from container');
|
||||||
|
}
|
||||||
|
|
||||||
return $this->instances[$id];
|
return $this->instances[$id];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,6 +50,8 @@ final class ExceptionTrace
|
|||||||
|
|
||||||
$property = new ReflectionProperty($t, 'serializableTrace');
|
$property = new ReflectionProperty($t, 'serializableTrace');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
|
|
||||||
|
/** @var array<array<string>> $trace */
|
||||||
$trace = $property->getValue($t);
|
$trace = $property->getValue($t);
|
||||||
|
|
||||||
$cleanedTrace = [];
|
$cleanedTrace = [];
|
||||||
|
|||||||
@ -31,7 +31,10 @@ final class HigherOrderCallables
|
|||||||
*/
|
*/
|
||||||
public function expect(mixed $value): Expectation
|
public function expect(mixed $value): Expectation
|
||||||
{
|
{
|
||||||
return new Expectation($value instanceof Closure ? Reflection::bindCallableWithData($value) : $value);
|
/** @var TValue $value */
|
||||||
|
$value = $value instanceof Closure ? Reflection::bindCallableWithData($value) : $value;
|
||||||
|
|
||||||
|
return new Expectation($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user