mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
feat: adds toBeUsedOn
This commit is contained in:
@ -7,6 +7,7 @@ namespace Pest;
|
|||||||
use BadMethodCallException;
|
use BadMethodCallException;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Pest\Arch\Contracts\ArchExpectation;
|
use Pest\Arch\Contracts\ArchExpectation;
|
||||||
|
use Pest\Arch\Expectations\ToBeUsedOn;
|
||||||
use Pest\Arch\Expectations\ToDependOn;
|
use Pest\Arch\Expectations\ToDependOn;
|
||||||
use Pest\Arch\Expectations\ToDependOnNothing;
|
use Pest\Arch\Expectations\ToDependOnNothing;
|
||||||
use Pest\Arch\Expectations\ToOnlyBeUsedOn;
|
use Pest\Arch\Expectations\ToOnlyBeUsedOn;
|
||||||
@ -359,11 +360,21 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Asserts that the given expectation target depends on the given dependencies.
|
* Asserts that the given expectation target depends on the given dependencies.
|
||||||
*
|
*
|
||||||
* @param array<int, string>|string $dependencies
|
* @param array<int, string>|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<int, string>|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<int, string>|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<int, string>|string $targets
|
* @param array<int, string>|string $targets
|
||||||
*/
|
*/
|
||||||
@ -383,14 +404,4 @@ final class Expectation
|
|||||||
{
|
{
|
||||||
return ToOnlyBeUsedOn::make($this, $targets);
|
return ToOnlyBeUsedOn::make($this, $targets);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the given expectation target does "only" depend on the given dependencies.
|
|
||||||
*
|
|
||||||
* @param array<int, string>|string $targets
|
|
||||||
*/
|
|
||||||
public function toOnlyDependOn(array|string $targets): ArchExpectation
|
|
||||||
{
|
|
||||||
return ToOnlyDependOn::make($this, $targets);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Expectations;
|
namespace Pest\Expectations;
|
||||||
|
|
||||||
use Pest\Arch\Contracts\ArchExpectation;
|
use Pest\Arch\Contracts\ArchExpectation;
|
||||||
|
use Pest\Arch\Expectations\ToBeUsedOn;
|
||||||
use Pest\Arch\Expectations\ToDependOn;
|
use Pest\Arch\Expectations\ToDependOn;
|
||||||
use Pest\Arch\GroupArchExpectation;
|
use Pest\Arch\GroupArchExpectation;
|
||||||
use Pest\Arch\SingleArchExpectation;
|
use Pest\Arch\SingleArchExpectation;
|
||||||
@ -58,45 +59,47 @@ final class OppositeExpectation
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that the given expectation target depends on the given dependencies.
|
* Asserts that the given expectation target does not depend on any of 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.
|
|
||||||
*
|
*
|
||||||
* @param array<int, string>|string $targets
|
* @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 $targets
|
||||||
*
|
|
||||||
* @param array<int, string>|string $dependencies
|
|
||||||
*/
|
*/
|
||||||
public function toOnlyDependOn(array|string $dependencies): never
|
public function toOnlyDependOn(array|string $targets): never
|
||||||
{
|
{
|
||||||
throw InvalidExpectation::fromMethods(['not', 'toOnlyDependOn']);
|
throw InvalidExpectation::fromMethods(['not', 'toOnlyDependOn']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Asserts that the given expectation target does not have any dependencies.
|
|
||||||
*/
|
|
||||||
public function toDependOnNothing(): never
|
public function toDependOnNothing(): never
|
||||||
{
|
{
|
||||||
throw InvalidExpectation::fromMethods(['not', 'toDependOnNothing']);
|
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.
|
* Handle dynamic method calls into the original expectation.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user