diff --git a/src/Expectation.php b/src/Expectation.php index f63a4778..ddca5bda 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -8,6 +8,7 @@ use BadMethodCallException; use Closure; use Pest\Arch\Contracts\ArchExpectation; use Pest\Arch\Expectations\ToBeUsedOn; +use Pest\Arch\Expectations\ToBeUsedOnNothing; use Pest\Arch\Expectations\ToDependOn; use Pest\Arch\Expectations\ToDependOnNothing; use Pest\Arch\Expectations\ToOnlyBeUsedOn; @@ -16,6 +17,7 @@ use Pest\Concerns\Extendable; use Pest\Concerns\Pipeable; use Pest\Concerns\Retrievable; use Pest\Exceptions\ExpectationNotFound; +use Pest\Exceptions\InvalidExpectation; use Pest\Exceptions\InvalidExpectationValue; use Pest\Expectations\EachExpectation; use Pest\Expectations\HigherOrderExpectation; @@ -385,6 +387,11 @@ final class Expectation return ToDependOnNothing::make($this); } + public function toBeUsed(): never + { + throw InvalidExpectation::fromMethods(['toBeUsed']); + } + /** * Asserts that the given expectation dependency is used by the given targets. * @@ -404,4 +411,12 @@ final class Expectation { return ToOnlyBeUsedOn::make($this, $targets); } + + /** + * Asserts that the given expectation dependency is not used. + */ + public function toBeUsedOnNothing(): ArchExpectation + { + return ToBeUsedOnNothing::make($this); + } } diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index 808b5874..67d47994 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -6,6 +6,7 @@ namespace Pest\Expectations; use Pest\Arch\Contracts\ArchExpectation; use Pest\Arch\Expectations\ToBeUsedOn; +use Pest\Arch\Expectations\ToBeUsedOnNothing; use Pest\Arch\Expectations\ToDependOn; use Pest\Arch\GroupArchExpectation; use Pest\Arch\SingleArchExpectation; @@ -83,6 +84,14 @@ final class OppositeExpectation throw InvalidExpectation::fromMethods(['not', 'toDependOnNothing']); } + /** + * Asserts that the given expectation dependency is not used. + */ + public function toBeUsed(): ArchExpectation + { + return ToBeUsedOnNothing::make($this->original); + } + /** * Asserts that the given expectation dependency is not used by any of the given targets. * @@ -100,6 +109,14 @@ final class OppositeExpectation throw InvalidExpectation::fromMethods(['not', 'toOnlyBeUsedOn']); } + /** + * Asserts that the given expectation dependency is not used. + */ + public function toBeUsedOnNothing(): ArchExpectation + { + throw InvalidExpectation::fromMethods(['not', 'toBeUsedOnNothing']); + } + /** * Handle dynamic method calls into the original expectation. *