From 04e15be75f2c9caf6b827f3486adca041a978a04 Mon Sep 17 00:00:00 2001 From: Nick Harin Date: Wed, 8 Jul 2026 00:55:28 +0500 Subject: [PATCH] Convert exception tests to fluent throws() Matches the family fluent style; behaviour and coverage unchanged. --- ...ssertCompositeEntityExistValidatorTest.php | 19 ++++++++----------- tests/AssertEntityExistValidatorTest.php | 10 +++++----- tests/AssertEntityNotExistValidatorTest.php | 10 +++++----- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/tests/AssertCompositeEntityExistValidatorTest.php b/tests/AssertCompositeEntityExistValidatorTest.php index e18c707..563ec94 100644 --- a/tests/AssertCompositeEntityExistValidatorTest.php +++ b/tests/AssertCompositeEntityExistValidatorTest.php @@ -18,6 +18,8 @@ use Symfony\Component\Validator\Exception\UnexpectedValueException; use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface; +use function K2gl\PHPUnitFluentAssertions\fact; + class AssertCompositeEntityExistValidatorTest extends TestCase { private MockObject $entityManager; @@ -42,23 +44,18 @@ protected function setUp(): void public function testValidateWithWrongConstraint(): void { - // assert - $this->expectException(UnexpectedTypeException::class); - - // act - $this->assertCompositeEntityExistValidator->validate(new class () {}, new NotNull); + // act + assert + fact(fn () => $this->assertCompositeEntityExistValidator->validate(new class () {}, new NotNull)) + ->throws(UnexpectedTypeException::class); } public function testValidateWithNonObjectValue(): void { - // assert - $this->expectException(UnexpectedValueException::class); - - // act - $this->assertCompositeEntityExistValidator->validate( + // act + assert + fact(fn () => $this->assertCompositeEntityExistValidator->validate( 'foo', new AssertCompositeEntityExist(entity: 'App\Entity\WarehouseItem', fields: ['warehouseId', 'companyId']), - ); + ))->throws(UnexpectedValueException::class); } public function testValidateSkipsIfValueNull(): void diff --git a/tests/AssertEntityExistValidatorTest.php b/tests/AssertEntityExistValidatorTest.php index 1e42e60..25b3fe1 100644 --- a/tests/AssertEntityExistValidatorTest.php +++ b/tests/AssertEntityExistValidatorTest.php @@ -17,6 +17,8 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface; +use function K2gl\PHPUnitFluentAssertions\fact; + class AssertEntityExistValidatorTest extends TestCase { private MockObject $entityManager; @@ -41,11 +43,9 @@ protected function setUp(): void public function testValidateWithWrongConstraint(): void { - // assert - $this->expectException(UnexpectedTypeException::class); - - // act - $this->assertEntityExistValidator->validate('foo', new NotNull); + // act + assert + fact(fn () => $this->assertEntityExistValidator->validate('foo', new NotNull)) + ->throws(UnexpectedTypeException::class); } public function testValidateValidEntity(): void diff --git a/tests/AssertEntityNotExistValidatorTest.php b/tests/AssertEntityNotExistValidatorTest.php index 395d9f8..d0c33f9 100644 --- a/tests/AssertEntityNotExistValidatorTest.php +++ b/tests/AssertEntityNotExistValidatorTest.php @@ -17,6 +17,8 @@ use Symfony\Component\Validator\Exception\UnexpectedTypeException; use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface; +use function K2gl\PHPUnitFluentAssertions\fact; + class AssertEntityNotExistValidatorTest extends TestCase { private MockObject $entityManager; @@ -41,11 +43,9 @@ protected function setUp(): void public function testValidateWithWrongConstraint(): void { - // assert - $this->expectException(UnexpectedTypeException::class); - - // act - $this->assertEntityNotExistValidator->validate('foo', new NotNull); + // act + assert + fact(fn () => $this->assertEntityNotExistValidator->validate('foo', new NotNull)) + ->throws(UnexpectedTypeException::class); } public function testValidateValidEntity(): void