feat: adds toBeUsedOnNothing and toBeUsed

This commit is contained in:
Nuno Maduro
2022-12-28 16:27:08 +00:00
parent 174a9ca60b
commit 476f56b617
2 changed files with 32 additions and 0 deletions

View File

@ -8,6 +8,7 @@ use BadMethodCallException;
use Closure;
use Pest\Arch\Contracts\ArchExpectation;
use Pest\Arch\Expectations\ToBeUsedOn;
use Pest\Arch\Expectations\ToBeUsedOnNothing;
use Pest\Arch\Expectations\ToDependOn;
use Pest\Arch\Expectations\ToDependOnNothing;
use Pest\Arch\Expectations\ToOnlyBeUsedOn;
@ -16,6 +17,7 @@ use Pest\Concerns\Extendable;
use Pest\Concerns\Pipeable;
use Pest\Concerns\Retrievable;
use Pest\Exceptions\ExpectationNotFound;
use Pest\Exceptions\InvalidExpectation;
use Pest\Exceptions\InvalidExpectationValue;
use Pest\Expectations\EachExpectation;
use Pest\Expectations\HigherOrderExpectation;
@ -385,6 +387,11 @@ final class Expectation
return ToDependOnNothing::make($this);
}
public function toBeUsed(): never
{
throw InvalidExpectation::fromMethods(['toBeUsed']);
}
/**
* Asserts that the given expectation dependency is used by the given targets.
*
@ -404,4 +411,12 @@ final class Expectation
{
return ToOnlyBeUsedOn::make($this, $targets);
}
/**
* Asserts that the given expectation dependency is not used.
*/
public function toBeUsedOnNothing(): ArchExpectation
{
return ToBeUsedOnNothing::make($this);
}
}

View File

@ -6,6 +6,7 @@ namespace Pest\Expectations;
use Pest\Arch\Contracts\ArchExpectation;
use Pest\Arch\Expectations\ToBeUsedOn;
use Pest\Arch\Expectations\ToBeUsedOnNothing;
use Pest\Arch\Expectations\ToDependOn;
use Pest\Arch\GroupArchExpectation;
use Pest\Arch\SingleArchExpectation;
@ -83,6 +84,14 @@ final class OppositeExpectation
throw InvalidExpectation::fromMethods(['not', 'toDependOnNothing']);
}
/**
* Asserts that the given expectation dependency is not used.
*/
public function toBeUsed(): ArchExpectation
{
return ToBeUsedOnNothing::make($this->original);
}
/**
* Asserts that the given expectation dependency is not used by any of the given targets.
*
@ -100,6 +109,14 @@ final class OppositeExpectation
throw InvalidExpectation::fromMethods(['not', 'toOnlyBeUsedOn']);
}
/**
* Asserts that the given expectation dependency is not used.
*/
public function toBeUsedOnNothing(): ArchExpectation
{
throw InvalidExpectation::fromMethods(['not', 'toBeUsedOnNothing']);
}
/**
* Handle dynamic method calls into the original expectation.
*