diff --git a/src/Exceptions/InvalidExpectation.php b/src/Exceptions/InvalidExpectation.php index c13cf1ff..544baac3 100644 --- a/src/Exceptions/InvalidExpectation.php +++ b/src/Exceptions/InvalidExpectation.php @@ -12,10 +12,11 @@ use Symfony\Component\Console\Exception\ExceptionInterface; /** * @internal */ -final class InvalidExpectation extends LogicException implements ExceptionInterface, RenderlessEditor, RenderlessTrace +final class InvalidExpectation extends LogicException implements ExceptionInterface, RenderlessEditor, RenderlessTrace { /** * @param array $methods + * * @throws self */ public static function fromMethods(array $methods): never diff --git a/src/Expectation.php b/src/Expectation.php index 8283a870..507e6915 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -9,6 +9,7 @@ use Closure; use Pest\Arch\Contracts\ArchExpectation; use Pest\Arch\Expectations\ToDependOn; use Pest\Arch\Expectations\ToDependOnNothing; +use Pest\Arch\Expectations\ToOnlyBeUsedOn; use Pest\Arch\Expectations\ToOnlyDependOn; use Pest\Concerns\Extendable; use Pest\Concerns\Pipeable; @@ -356,17 +357,35 @@ final class Expectation } /** - * Asserts that the layer depends (not exclusively) on the given layers. + * Asserts that the given expectation target depends on the given dependencies. * - * @param array|string $targets + * @param array|string $dependencies */ - public function toDependOn(array|string $targets): ArchExpectation + public function toDependOn(array|string $dependencies): ArchExpectation { - return ToDependOn::make($this, $targets); + return ToDependOn::make($this, $dependencies); } /** - * Asserts that the layer only depends on the given layers. + * Asserts that the given expectation target does not have any dependencies. + */ + public function toDependOnNothing(): ArchExpectation + { + return ToDependOnNothing::make($this); + } + + /** + * Asserts that the given expectation dependency is only depended on by the given targets. + * + * @param array|string $targets + */ + public function toOnlyBeUsedOn(array|string $targets): ArchExpectation + { + return ToOnlyBeUsedOn::make($this, $targets); + } + + /** + * Asserts that the given expectation target does "only" depend on the given dependencies. * * @param array|string $targets */ @@ -374,12 +393,4 @@ final class Expectation { return ToOnlyDependOn::make($this, $targets); } - - /** - * Asserts that the layer is not allowed to depend on any other layer. - */ - public function toDependOnNothing(): ArchExpectation - { - return ToDependOnNothing::make($this); - } } diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index c45ced4e..f73b3345 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -6,8 +6,6 @@ namespace Pest\Expectations; use Pest\Arch\Contracts\ArchExpectation; use Pest\Arch\Expectations\ToDependOn; -use Pest\Arch\Expectations\ToDependOnNothing; -use Pest\Arch\Expectations\ToOnlyDependOn; use Pest\Arch\GroupArchExpectation; use Pest\Arch\SingleArchExpectation; use Pest\Exceptions\InvalidExpectation; @@ -60,31 +58,39 @@ final class OppositeExpectation } /** - * Asserts that the layer does not depend on the given layers. + * Asserts that the given expectation target depends on the given dependencies. * - * @param array|string $targets + * @param array|string $dependencies */ - public function toDependOn(array|string $targets): ArchExpectation + public function toDependOn(array|string $dependencies): ArchExpectation { - return GroupArchExpectation::fromExpectations(array_map(function (string $target) : SingleArchExpectation { - return ToDependOn::make($this->original, $target)->opposite( - fn () => $this->throwExpectationFailedException('toDependOn', $target), - ); - }, is_string($targets) ? [$targets] : $targets)); + 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 layer does not only depends on the given layers. + * Asserts that the given expectation dependency is only depended on by the given targets. * * @param array|string $targets */ - public function toOnlyDependOn(array|string $targets): never + public function toOnlyBeUsedOn(array|string $targets): never + { + throw InvalidExpectation::fromMethods(['not', 'toOnlyBeUsedOn']); + } + + /** + * Asserts that the given expectation target does "only" depend on the given dependencies. + * + * @param array|string $dependencies + */ + public function toOnlyDependOn(array|string $dependencies): never { throw InvalidExpectation::fromMethods(['not', 'toOnlyDependOn']); } /** - * Asserts that the layer is depends on at least one layer. + * Asserts that the given expectation target does not have any dependencies. */ public function toDependOnNothing(): never {