diff --git a/src/Expectation.php b/src/Expectation.php index cb9b0361..8579da04 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -13,6 +13,7 @@ use Pest\Arch\Expectations\ToOnlyBeUsedIn; use Pest\Arch\Expectations\ToOnlyUse; use Pest\Arch\Expectations\ToUse; use Pest\Arch\Expectations\ToUseNothing; +use Pest\Arch\Expectations\ToUseStrictTypes; use Pest\Concerns\Extendable; use Pest\Concerns\Pipeable; use Pest\Concerns\Retrievable; @@ -369,6 +370,16 @@ final class Expectation return ToUse::make($this, $targets); } + /** + * Asserts that the given expectation target use the "declare(strict_types=1)" declaration. + * + * @param array|string $targets + */ + public function toUseStrictTypes(): ArchExpectation + { + return ToUseStrictTypes::make($this); + } + /** * Asserts that the given expectation target "only" use on the given dependencies. * diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index 327676db..57e0193d 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -5,15 +5,19 @@ declare(strict_types=1); namespace Pest\Expectations; use Pest\Arch\Contracts\ArchExpectation; +use Pest\Arch\Exceptions\ArchExpectationFailedException; +use Pest\Arch\Expectations\NotToUseStrictTypes; use Pest\Arch\Expectations\ToBeUsedIn; use Pest\Arch\Expectations\ToBeUsedInNothing; use Pest\Arch\Expectations\ToUse; +use Pest\Arch\Expectations\ToUseStrictTypes; use Pest\Arch\GroupArchExpectation; use Pest\Arch\SingleArchExpectation; use Pest\Exceptions\InvalidExpectation; use Pest\Expectation; use Pest\Support\Arr; use Pest\Support\Exporter; +use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\ExpectationFailedException; /** @@ -71,6 +75,14 @@ final class OppositeExpectation ), is_string($targets) ? [$targets] : $targets)); } + /** + * Asserts that the given expectation target does not use the "declare(strict_types=1)" declaration. + */ + public function toUseStrictTypes(): ArchExpectation + { + return ToUseStrictTypes::make($this->original, false); + } + /** * @param array|string $targets */ @@ -128,7 +140,7 @@ final class OppositeExpectation try { /* @phpstan-ignore-next-line */ $this->original->{$name}(...$arguments); - } catch (ExpectationFailedException) { + } catch (ExpectationFailedException|AssertionFailedError) { return $this->original; }