diff --git a/src/Expectation.php b/src/Expectation.php index 507e6915..f63a4778 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -7,6 +7,7 @@ namespace Pest; use BadMethodCallException; use Closure; use Pest\Arch\Contracts\ArchExpectation; +use Pest\Arch\Expectations\ToBeUsedOn; use Pest\Arch\Expectations\ToDependOn; use Pest\Arch\Expectations\ToDependOnNothing; use Pest\Arch\Expectations\ToOnlyBeUsedOn; @@ -359,11 +360,21 @@ final class Expectation /** * Asserts that the given expectation target depends on the given dependencies. * - * @param array|string $dependencies + * @param array|string $targets */ - public function toDependOn(array|string $dependencies): ArchExpectation + public function toDependOn(array|string $targets): ArchExpectation { - return ToDependOn::make($this, $dependencies); + return ToDependOn::make($this, $targets); + } + + /** + * Asserts that the given expectation target "only" depends on the given dependencies. + * + * @param array|string $targets + */ + public function toOnlyDependOn(array|string $targets): ArchExpectation + { + return ToOnlyDependOn::make($this, $targets); } /** @@ -375,7 +386,17 @@ final class Expectation } /** - * Asserts that the given expectation dependency is only depended on by the given targets. + * Asserts that the given expectation dependency is used by the given targets. + * + * @param array|string $targets + */ + public function toBeUsedOn(array|string $targets): ArchExpectation + { + return ToBeUsedOn::make($this, $targets); + } + + /** + * Asserts that the given expectation dependency is "only" used by the given targets. * * @param array|string $targets */ @@ -383,14 +404,4 @@ final class Expectation { return ToOnlyBeUsedOn::make($this, $targets); } - - /** - * Asserts that the given expectation target does "only" depend on the given dependencies. - * - * @param array|string $targets - */ - public function toOnlyDependOn(array|string $targets): ArchExpectation - { - return ToOnlyDependOn::make($this, $targets); - } } diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index f73b3345..808b5874 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Pest\Expectations; use Pest\Arch\Contracts\ArchExpectation; +use Pest\Arch\Expectations\ToBeUsedOn; use Pest\Arch\Expectations\ToDependOn; use Pest\Arch\GroupArchExpectation; use Pest\Arch\SingleArchExpectation; @@ -58,45 +59,47 @@ final class OppositeExpectation } /** - * Asserts that the given expectation target depends on the given dependencies. - * - * @param array|string $dependencies - */ - public function toDependOn(array|string $dependencies): ArchExpectation - { - return GroupArchExpectation::fromExpectations(array_map(fn (string $target): SingleArchExpectation => ToDependOn::make($this->original, $target)->opposite( - fn () => $this->throwExpectationFailedException('toDependOn', $target), - ), is_string($dependencies) ? [$dependencies] : $dependencies)); - } - - /** - * Asserts that the given expectation dependency is only depended on by the given targets. + * Asserts that the given expectation target does not depend on any of the given dependencies. * * @param array|string $targets */ - public function toOnlyBeUsedOn(array|string $targets): never + public function toDependOn(array|string $targets): ArchExpectation { - throw InvalidExpectation::fromMethods(['not', 'toOnlyBeUsedOn']); + return GroupArchExpectation::fromExpectations($this->original, array_map(fn (string $target): SingleArchExpectation => ToDependOn::make($this->original, $target)->opposite( + fn () => $this->throwExpectationFailedException('toDependOn', $target), + ), is_string($targets) ? [$targets] : $targets)); } /** - * Asserts that the given expectation target does "only" depend on the given dependencies. - * - * @param array|string $dependencies + * @param array|string $targets */ - public function toOnlyDependOn(array|string $dependencies): never + public function toOnlyDependOn(array|string $targets): never { throw InvalidExpectation::fromMethods(['not', 'toOnlyDependOn']); } - /** - * Asserts that the given expectation target does not have any dependencies. - */ public function toDependOnNothing(): never { throw InvalidExpectation::fromMethods(['not', 'toDependOnNothing']); } + /** + * Asserts that the given expectation dependency is not used by any of the given targets. + * + * @param array|string $targets + */ + public function toBeUsedOn(array|string $targets): ArchExpectation + { + return GroupArchExpectation::fromExpectations($this->original, array_map(fn (string $target): GroupArchExpectation => ToBeUsedOn::make($this->original, $target)->opposite( + fn () => $this->throwExpectationFailedException('toBeUsedOn', $target), + ), is_string($targets) ? [$targets] : $targets)); + } + + public function toOnlyBeUsedOn(): never + { + throw InvalidExpectation::fromMethods(['not', 'toOnlyBeUsedOn']); + } + /** * Handle dynamic method calls into the original expectation. *