mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
feat: improves not->toDependOn
This commit is contained in:
25
src/Exceptions/InvalidExpectation.php
Normal file
25
src/Exceptions/InvalidExpectation.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Exceptions;
|
||||
|
||||
use LogicException;
|
||||
use NunoMaduro\Collision\Contracts\RenderlessEditor;
|
||||
use NunoMaduro\Collision\Contracts\RenderlessTrace;
|
||||
use Symfony\Component\Console\Exception\ExceptionInterface;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class InvalidExpectation extends LogicException implements ExceptionInterface, RenderlessEditor, RenderlessTrace
|
||||
{
|
||||
/**
|
||||
* @param array<int, string> $methods
|
||||
* @throws self
|
||||
*/
|
||||
public static function fromMethods(array $methods): never
|
||||
{
|
||||
throw new self(sprintf('Expectation [%s] is not valid.', implode('->', $methods)));
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,7 @@ namespace Pest;
|
||||
|
||||
use BadMethodCallException;
|
||||
use Closure;
|
||||
use Pest\Arch\ArchExpectation;
|
||||
use Pest\Arch\Conctracts\ArchExpectation;
|
||||
use Pest\Arch\Expectations\ToDependOn;
|
||||
use Pest\Arch\Expectations\ToDependOnNothing;
|
||||
use Pest\Arch\Expectations\ToOnlyDependOn;
|
||||
@ -359,7 +359,6 @@ final class Expectation
|
||||
* Asserts that the layer depends (not exclusively) on the given layers.
|
||||
*
|
||||
* @param array<int, string>|string $targets
|
||||
* @return ArchExpectation<string>
|
||||
*/
|
||||
public function toDependOn(array|string $targets): ArchExpectation
|
||||
{
|
||||
@ -370,7 +369,6 @@ final class Expectation
|
||||
* Asserts that the layer only depends on the given layers.
|
||||
*
|
||||
* @param array<int, string>|string $targets
|
||||
* @return ArchExpectation<string>
|
||||
*/
|
||||
public function toOnlyDependOn(array|string $targets): ArchExpectation
|
||||
{
|
||||
@ -379,8 +377,6 @@ final class Expectation
|
||||
|
||||
/**
|
||||
* Asserts that the layer is not allowed to depend on any other layer.
|
||||
*
|
||||
* @return ArchExpectation<string>
|
||||
*/
|
||||
public function toDependOnNothing(): ArchExpectation
|
||||
{
|
||||
|
||||
@ -4,10 +4,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Pest\Expectations;
|
||||
|
||||
use Pest\Arch\ArchExpectation;
|
||||
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;
|
||||
use Pest\Expectation;
|
||||
use Pest\Support\Arr;
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
@ -60,38 +63,32 @@ final class OppositeExpectation
|
||||
* Asserts that the layer does not depend on the given layers.
|
||||
*
|
||||
* @param array<int, string>|string $targets
|
||||
* @return ArchExpectation<string>
|
||||
*/
|
||||
public function toDependOn(array|string $targets): ArchExpectation
|
||||
{
|
||||
return ToDependOn::make($this->original, $targets)->opposite(
|
||||
fn () => $this->throwExpectationFailedException('toDependOn', $targets),
|
||||
);
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the layer does not only depends on the given layers.
|
||||
*
|
||||
* @param array<int, string>|string $targets
|
||||
* @return ArchExpectation<string>
|
||||
*/
|
||||
public function toOnlyDependOn(array|string $targets): ArchExpectation
|
||||
public function toOnlyDependOn(array|string $targets): never
|
||||
{
|
||||
return ToOnlyDependOn::make($this->original, $targets)->opposite(
|
||||
fn () => $this->throwExpectationFailedException('toOnlyDependOn', $targets),
|
||||
);
|
||||
throw InvalidExpectation::fromMethods(['not', 'toOnlyDependOn']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the layer is depends on at least one layer.
|
||||
*
|
||||
* @return ArchExpectation<string>
|
||||
*/
|
||||
public function toDependOnNothing(): ArchExpectation
|
||||
public function toDependOnNothing(): never
|
||||
{
|
||||
return ToDependOnNothing::make($this->original)->opposite(
|
||||
fn () => $this->throwExpectationFailedException('toDependOnNothing'),
|
||||
);
|
||||
throw InvalidExpectation::fromMethods(['not', 'toDependOnNothing']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user