From d5334f96a458d876beef90c42af1dd39da40ea8e Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 15 Jun 2023 18:18:42 +0200 Subject: [PATCH] chore: increase deps --- src/Expectation.php | 15 ++++++++++++++- src/Expectations/OppositeExpectation.php | 11 ++++++++++- src/Support/Coverage.php | 4 +++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index 893cc049..7a8090f0 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -14,6 +14,7 @@ use Pest\Arch\Expectations\ToOnlyBeUsedIn; use Pest\Arch\Expectations\ToOnlyUse; use Pest\Arch\Expectations\ToUse; use Pest\Arch\Expectations\ToUseNothing; +use Pest\Arch\PendingArchExpectation; use Pest\Arch\Support\FileLineFinder; use Pest\Concerns\Extendable; use Pest\Concerns\Pipeable; @@ -39,6 +40,7 @@ use PHPUnit\Framework\ExpectationFailedException; * @property EachExpectation $each Creates an expectation on each element on the traversable value. * * @mixin Mixins\Expectation + * @mixin PendingArchExpectation */ final class Expectation { @@ -290,9 +292,15 @@ final class Expectation * @param array $parameters * @return Expectation|HigherOrderExpectation, TValue> */ - public function __call(string $method, array $parameters): Expectation|HigherOrderExpectation + public function __call(string $method, array $parameters): Expectation|HigherOrderExpectation|PendingArchExpectation { if (! self::hasMethod($method)) { + if (! is_object($this->value) && method_exists(PendingArchExpectation::class, $method)) { + $pendingArchExpectation = new PendingArchExpectation($this, []); + + return $pendingArchExpectation->$method(...$parameters); // @phpstan-ignore-line + } + /* @phpstan-ignore-next-line */ return new HigherOrderExpectation($this, call_user_func_array($this->value->$method(...), $parameters)); } @@ -336,6 +344,11 @@ final class Expectation public function __get(string $name) { if (! self::hasMethod($name)) { + if (! is_object($this->value) && method_exists(PendingArchExpectation::class, $name)) { + /* @phpstan-ignore-next-line */ + return $this->{$name}(); + } + /* @phpstan-ignore-next-line */ return new HigherOrderExpectation($this, $this->retrieve($name, $this->value)); } diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index d84c00f2..ceec8337 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -10,6 +10,7 @@ use Pest\Arch\Expectations\ToBeUsedIn; use Pest\Arch\Expectations\ToBeUsedInNothing; use Pest\Arch\Expectations\ToUse; use Pest\Arch\GroupArchExpectation; +use Pest\Arch\PendingArchExpectation; use Pest\Arch\SingleArchExpectation; use Pest\Arch\Support\FileLineFinder; use Pest\Exceptions\InvalidExpectation; @@ -318,6 +319,10 @@ final class OppositeExpectation public function __call(string $name, array $arguments): Expectation { try { + if (! is_object($this->original->value) && method_exists(PendingArchExpectation::class, $name)) { + throw InvalidExpectation::fromMethods(['not', $name]); + } + /* @phpstan-ignore-next-line */ $this->original->{$name}(...$arguments); } catch (ExpectationFailedException|AssertionFailedError) { @@ -335,8 +340,12 @@ final class OppositeExpectation public function __get(string $name): Expectation { try { + if (! is_object($this->original->value) && method_exists(PendingArchExpectation::class, $name)) { + throw InvalidExpectation::fromMethods(['not', $name]); + } + $this->original->{$name}; // @phpstan-ignore-line - } catch (ExpectationFailedException) { // @phpstan-ignore-line + } catch (ExpectationFailedException) { return $this->original; } diff --git a/src/Support/Coverage.php b/src/Support/Coverage.php index 6d61b68d..525e67e2 100644 --- a/src/Support/Coverage.php +++ b/src/Support/Coverage.php @@ -159,9 +159,11 @@ final class Coverage * ['11', '20..25', '50', '60..80']; * ``` * + * + * @param File $file * @return array */ - public static function getMissingCoverage(File $file): array + public static function getMissingCoverage($file): array { $shouldBeNewLine = true;