mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 10:17:23 +01:00
feat: adds arch related expectations
This commit is contained in:
@ -51,6 +51,7 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"pestphp/pest-dev-tools": "^2.1.0",
|
"pestphp/pest-dev-tools": "^2.1.0",
|
||||||
|
"pestphp/pest-plugin-arch": "^2.0.0",
|
||||||
"symfony/process": "^6.2.0"
|
"symfony/process": "^6.2.0"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
|
|||||||
@ -6,6 +6,10 @@ namespace Pest;
|
|||||||
|
|
||||||
use BadMethodCallException;
|
use BadMethodCallException;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use Pest\Arch\ArchExpectation;
|
||||||
|
use Pest\Arch\Expectations\ToDependOn;
|
||||||
|
use Pest\Arch\Expectations\ToDependOnNothing;
|
||||||
|
use Pest\Arch\Expectations\ToOnlyDependOn;
|
||||||
use Pest\Concerns\Extendable;
|
use Pest\Concerns\Extendable;
|
||||||
use Pest\Concerns\Pipeable;
|
use Pest\Concerns\Pipeable;
|
||||||
use Pest\Concerns\Retrievable;
|
use Pest\Concerns\Retrievable;
|
||||||
@ -24,7 +28,7 @@ use PHPUnit\Framework\ExpectationFailedException;
|
|||||||
*
|
*
|
||||||
* @template TValue
|
* @template TValue
|
||||||
*
|
*
|
||||||
* @property Expectation $not Creates the opposite expectation.
|
* @property OppositeExpectation $not Creates the opposite expectation.
|
||||||
* @property EachExpectation $each Creates an expectation on each element on the traversable value.
|
* @property EachExpectation $each Creates an expectation on each element on the traversable value.
|
||||||
*
|
*
|
||||||
* @mixin Mixins\Expectation<TValue>
|
* @mixin Mixins\Expectation<TValue>
|
||||||
@ -286,11 +290,15 @@ final class Expectation
|
|||||||
return new HigherOrderExpectation($this, call_user_func_array($this->value->$method(...), $parameters));
|
return new HigherOrderExpectation($this, call_user_func_array($this->value->$method(...), $parameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpectationPipeline::for($this->getExpectationClosure($method))
|
$result = ExpectationPipeline::for($this->getExpectationClosure($method))
|
||||||
->send(...$parameters)
|
->send(...$parameters)
|
||||||
->through($this->pipes($method, $this, Expectation::class))
|
->through($this->pipes($method, $this, Expectation::class))
|
||||||
->run();
|
->run();
|
||||||
|
|
||||||
|
if ($result !== null) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,4 +358,37 @@ final class Expectation
|
|||||||
{
|
{
|
||||||
return new Any();
|
return new Any();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the layer depends (not exclusively) on the given layers.
|
||||||
|
*
|
||||||
|
* @param array<int, string>|string $targets
|
||||||
|
* @return ArchExpectation<TValue>
|
||||||
|
*/
|
||||||
|
public function toDependOn(array|string $targets): ArchExpectation
|
||||||
|
{
|
||||||
|
return ToDependOn::make($this, $targets);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the layer only depends on the given layers.
|
||||||
|
*
|
||||||
|
* @param array<int, string>|string $targets
|
||||||
|
* @return ArchExpectation<TValue>
|
||||||
|
*/
|
||||||
|
public function toOnlyDependOn(array|string $targets): ArchExpectation
|
||||||
|
{
|
||||||
|
return ToOnlyDependOn::make($this, $targets);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the layer is not allowed to depend on any other layer.
|
||||||
|
*
|
||||||
|
* @param array<int, string>|string $targets
|
||||||
|
* @return ArchExpectation<TValue>
|
||||||
|
*/
|
||||||
|
public function toDependOnNothing(): ArchExpectation
|
||||||
|
{
|
||||||
|
return ToDependOnNothing::make($this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,10 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Expectations;
|
namespace Pest\Expectations;
|
||||||
|
|
||||||
|
use Pest\Arch\ArchExpectation;
|
||||||
|
use Pest\Arch\Expectations\ToDependOn;
|
||||||
|
use Pest\Arch\Expectations\ToDependOnNothing;
|
||||||
|
use Pest\Arch\Expectations\ToOnlyDependOn;
|
||||||
use Pest\Expectation;
|
use Pest\Expectation;
|
||||||
use Pest\Support\Arr;
|
use Pest\Support\Arr;
|
||||||
use PHPUnit\Framework\ExpectationFailedException;
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
@ -52,6 +56,44 @@ final class OppositeExpectation
|
|||||||
return $this->original;
|
return $this->original;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the layer does not depend on the given layers.
|
||||||
|
*
|
||||||
|
* @param array<int, string>|string $targets
|
||||||
|
* @return ArchExpectation<TValue>
|
||||||
|
*/
|
||||||
|
public function toDependOn(array|string $targets): ArchExpectation
|
||||||
|
{
|
||||||
|
return ToDependOn::make($this->original, $targets)->opposite(
|
||||||
|
fn () => $this->throwExpectationFailedException('toDependOn', $targets),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the layer does not only depends on the given layers.
|
||||||
|
*
|
||||||
|
* @param array<int, string>|string $targets
|
||||||
|
* @return ArchExpectation<TValue>
|
||||||
|
*/
|
||||||
|
public function toOnlyDependOn(array|string $targets): ArchExpectation
|
||||||
|
{
|
||||||
|
return ToOnlyDependOn::make($this->original, $targets)->opposite(
|
||||||
|
fn () => $this->throwExpectationFailedException('toOnlyDependOn', $targets),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the layer is depends on at least one layer.
|
||||||
|
*
|
||||||
|
* @return ArchExpectation<TValue>
|
||||||
|
*/
|
||||||
|
public function toDependOnNothing(): ArchExpectation
|
||||||
|
{
|
||||||
|
return ToDependOnNothing::make($this->original)->opposite(
|
||||||
|
fn () => $this->throwExpectationFailedException('toDependOnNothing'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle dynamic method calls into the original expectation.
|
* Handle dynamic method calls into the original expectation.
|
||||||
*
|
*
|
||||||
@ -91,7 +133,7 @@ final class OppositeExpectation
|
|||||||
*
|
*
|
||||||
* @param array<int, mixed> $arguments
|
* @param array<int, mixed> $arguments
|
||||||
*/
|
*/
|
||||||
private function throwExpectationFailedException(string $name, array $arguments = []): never
|
public function throwExpectationFailedException(string $name, array $arguments = []): never
|
||||||
{
|
{
|
||||||
$exporter = new Exporter();
|
$exporter = new Exporter();
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,10 @@ use BadMethodCallException;
|
|||||||
use Closure;
|
use Closure;
|
||||||
use Error;
|
use Error;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
|
use Pest\Arch\ArchExpectation;
|
||||||
|
use Pest\Arch\Expectations\ToDependOn;
|
||||||
|
use Pest\Arch\Expectations\ToDependOnNothing;
|
||||||
|
use Pest\Arch\Expectations\ToOnlyDependOn;
|
||||||
use Pest\Exceptions\InvalidExpectationValue;
|
use Pest\Exceptions\InvalidExpectationValue;
|
||||||
use Pest\Matchers\Any;
|
use Pest\Matchers\Any;
|
||||||
use Pest\Support\Arr;
|
use Pest\Support\Arr;
|
||||||
|
|||||||
Reference in New Issue
Block a user