feat: adds toBeUsedOn

This commit is contained in:
Nuno Maduro
2022-12-28 16:09:47 +00:00
parent 406fcf72ae
commit 174a9ca60b
2 changed files with 50 additions and 36 deletions

View File

@ -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<int, string>|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<int, string>|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<int, string>|string $dependencies
* @param array<int, string>|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<int, string>|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.
*