From 7bcd3ebaeee7ac2c80331877f0d3237a25a05150 Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Thu, 18 Nov 2021 01:01:56 +0100 Subject: [PATCH] wip toward lvl9 --- src/Exceptions/ExpectationException.php | 11 +++++++++++ src/Expectation.php | 5 +++++ src/Functions.php | 5 ++++- src/HigherOrderExpectation.php | 5 ++++- src/Plugins/Coverage.php | 5 ++++- src/Support/Container.php | 8 +++++--- src/Support/ExceptionTrace.php | 2 ++ src/Support/HigherOrderCallables.php | 5 ++++- 8 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 src/Exceptions/ExpectationException.php diff --git a/src/Exceptions/ExpectationException.php b/src/Exceptions/ExpectationException.php new file mode 100644 index 00000000..dfe63bb9 --- /dev/null +++ b/src/Exceptions/ExpectationException.php @@ -0,0 +1,11 @@ +value)) { + throw ExpectationException::invalidValue('json', 'string'); + } + return $this->toBeJson()->and(json_decode($this->value, true)); } diff --git a/src/Functions.php b/src/Functions.php index ddc6f3af..0f72cee7 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -113,7 +113,10 @@ if (!function_exists('it')) { { $description = sprintf('it %s', $description); - return test($description, $closure); + /** @var TestCall $test */ + $test = test($description, $closure); + + return $test; } } diff --git a/src/HigherOrderExpectation.php b/src/HigherOrderExpectation.php index 839f3311..eb959cd4 100644 --- a/src/HigherOrderExpectation.php +++ b/src/HigherOrderExpectation.php @@ -80,7 +80,10 @@ final class HigherOrderExpectation } if (!$this->expectationHasMethod($name)) { - return new self($this->original, $this->retrieve($name, $this->getValue())); + /** @var array|object $value */ + $value = $this->getValue(); + + return new self($this->original, $this->retrieve($name, $value)); } return $this->performAssertion($name, []); diff --git a/src/Plugins/Coverage.php b/src/Plugins/Coverage.php index 8febde52..f2ee5457 100644 --- a/src/Plugins/Coverage.php +++ b/src/Plugins/Coverage.php @@ -80,7 +80,10 @@ final class Coverage implements AddsOutput, HandlesArguments } 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; diff --git a/src/Support/Container.php b/src/Support/Container.php index b87fdd65..6f2afc13 100644 --- a/src/Support/Container.php +++ b/src/Support/Container.php @@ -41,11 +41,13 @@ final class Container */ public function get(string $id) { - if (array_key_exists($id, $this->instances)) { - return $this->instances[$id]; + if (!array_key_exists($id, $this->instances)) { + $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]; } diff --git a/src/Support/ExceptionTrace.php b/src/Support/ExceptionTrace.php index ec17afc8..17fc2e40 100644 --- a/src/Support/ExceptionTrace.php +++ b/src/Support/ExceptionTrace.php @@ -50,6 +50,8 @@ final class ExceptionTrace $property = new ReflectionProperty($t, 'serializableTrace'); $property->setAccessible(true); + + /** @var array> $trace */ $trace = $property->getValue($t); $cleanedTrace = []; diff --git a/src/Support/HigherOrderCallables.php b/src/Support/HigherOrderCallables.php index 1637ccb2..be02b86d 100644 --- a/src/Support/HigherOrderCallables.php +++ b/src/Support/HigherOrderCallables.php @@ -31,7 +31,10 @@ final class HigherOrderCallables */ 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); } /**