diff --git a/src/Exception/ParticipantNotFoundException.php b/src/Exception/ParticipantNotFoundException.php new file mode 100644 index 0000000..18e262a --- /dev/null +++ b/src/Exception/ParticipantNotFoundException.php @@ -0,0 +1,22 @@ +participants[$index] ?? null; if (null === $participant) { - throw new \InvalidArgumentException(sprintf('Participant at index %d does not exist', $index)); + throw new ParticipantNotFoundException($index); } return $participant; diff --git a/tests/Service/ParticipantFormSupportServiceTest.php b/tests/Service/ParticipantFormSupportServiceTest.php index 70f8c7e..65575ea 100644 --- a/tests/Service/ParticipantFormSupportServiceTest.php +++ b/tests/Service/ParticipantFormSupportServiceTest.php @@ -6,6 +6,7 @@ namespace App\Tests\Service; use App\BusProNet\Model\Booking; use App\BusProNet\Model\Travel; +use App\Exception\ParticipantNotFoundException; use App\Form\Model\BookingDto; use App\Form\Model\ParticipantDto; use App\Service\ParticipantFormSupportService; @@ -19,7 +20,7 @@ class ParticipantFormSupportServiceTest extends TestCase $service = $this->createService(); $bookingDto = $this->createBookingDto(); - $this->expectException(\InvalidArgumentException::class); + $this->expectException(ParticipantNotFoundException::class); $this->expectExceptionMessage('Participant at index 2 does not exist'); $service->ensureParticipantExists($bookingDto, 2);