feat: upgrade phpunit to 12.5
This commit is contained in:
@@ -4,9 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
use Symfony\Component\Validator\ConstraintViolationInterface;
|
||||
use Symfony\Component\Validator\ConstraintViolationList;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\Model\Surcharge;
|
||||
@@ -18,19 +15,26 @@ use App\Form\Model\ParticipantEditDto;
|
||||
use App\Service\BookingPriceCalculator;
|
||||
use App\Service\ParticipantCardAssembler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Validator\ConstraintViolationInterface;
|
||||
use Symfony\Component\Validator\ConstraintViolationList;
|
||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
|
||||
class ParticipantCardAssemblerTest extends TestCase
|
||||
{
|
||||
private ParticipantCardAssembler $service;
|
||||
private ?ParticipantCardAssembler $service = null;
|
||||
private BookingPriceCalculator $priceCalculator;
|
||||
private ValidatorInterface $validator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->priceCalculator = $this->createMock(BookingPriceCalculator::class);
|
||||
$this->validator = $this->createMock(ValidatorInterface::class);
|
||||
$this->service = new ParticipantCardAssembler(
|
||||
$this->priceCalculator = $this->createStub(BookingPriceCalculator::class);
|
||||
$this->validator = $this->createStub(ValidatorInterface::class);
|
||||
}
|
||||
|
||||
private function service(): ParticipantCardAssembler
|
||||
{
|
||||
return $this->service ??= new ParticipantCardAssembler(
|
||||
$this->priceCalculator,
|
||||
$this->validator
|
||||
);
|
||||
@@ -38,6 +42,8 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
|
||||
public function testGetCardDataWithFullParticipantData(): void
|
||||
{
|
||||
$this->priceCalculator = $this->createMock(BookingPriceCalculator::class);
|
||||
|
||||
// Create test room
|
||||
$room = new Room();
|
||||
$room->id = 1;
|
||||
@@ -63,7 +69,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->with($bookingDto)
|
||||
->willReturn([450.50]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
$result = $this->service()->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertSame('Max Mustermann', $result->name);
|
||||
$this->assertSame('Doppelzimmer', $result->roomName);
|
||||
@@ -88,7 +94,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
$result = $this->service()->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertSame('Max', $result->name);
|
||||
}
|
||||
@@ -110,7 +116,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
$result = $this->service()->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertSame('Anmelder:in', $result->name);
|
||||
}
|
||||
@@ -132,7 +138,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
$result = $this->service()->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertSame('Anmelder:in', $result->name);
|
||||
}
|
||||
@@ -154,7 +160,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
$result = $this->service()->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertSame('Kein Zimmer zugewiesen', $result->roomName);
|
||||
}
|
||||
@@ -176,7 +182,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
$result = $this->service()->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertSame('Unbekanntes Zimmer', $result->roomName);
|
||||
}
|
||||
@@ -198,7 +204,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
$result = $this->service()->getCardData($bookingDto, 0);
|
||||
|
||||
// When no room assigned and price is zero, display dash (incomplete configuration)
|
||||
$this->assertNull($result->price->amount);
|
||||
@@ -228,7 +234,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
$result = $this->service()->getCardData($bookingDto, 0);
|
||||
|
||||
// When room is assigned but price is zero, display formatted zero price
|
||||
$this->assertSame(0.0, $result->price->amount);
|
||||
@@ -244,11 +250,13 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Participant at index 0 does not exist');
|
||||
|
||||
$this->service->getCardData($bookingDto, 0);
|
||||
$this->service()->getCardData($bookingDto, 0);
|
||||
}
|
||||
|
||||
public function testGetAllCardsDataWithMultipleParticipants(): void
|
||||
{
|
||||
$this->priceCalculator = $this->createMock(BookingPriceCalculator::class);
|
||||
|
||||
// Create test rooms
|
||||
$room1 = new Room();
|
||||
$room1->id = 1;
|
||||
@@ -287,7 +295,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->with($bookingDto)
|
||||
->willReturn([450.0, 500.0, 480.0]);
|
||||
|
||||
$result = $this->service->getAllCardsData($bookingDto);
|
||||
$result = $this->service()->getAllCardsData($bookingDto);
|
||||
|
||||
$this->assertCount(3, $result);
|
||||
|
||||
@@ -312,6 +320,8 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
|
||||
public function testGetAllCardsDataUsesCanceledSurchargesBeforePrecomputedActivePrices(): void
|
||||
{
|
||||
$this->priceCalculator = $this->createMock(BookingPriceCalculator::class);
|
||||
|
||||
$room = new Room();
|
||||
$room->id = 1;
|
||||
$room->label = 'Doppelzimmer';
|
||||
@@ -347,7 +357,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->with($bookingDto)
|
||||
->willReturn([0 => 450.0, 1 => 999.0]);
|
||||
|
||||
$result = $this->service->getAllCardsData($bookingDto);
|
||||
$result = $this->service()->getAllCardsData($bookingDto);
|
||||
|
||||
$this->assertSame(450.0, $result[0]->price->amount);
|
||||
$this->assertSame(75.0, $result[1]->price->amount);
|
||||
@@ -360,7 +370,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [];
|
||||
|
||||
$result = $this->service->getAllCardsData($bookingDto);
|
||||
$result = $this->service()->getAllCardsData($bookingDto);
|
||||
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
@@ -381,7 +391,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([1234.56]);
|
||||
|
||||
$result = $this->service->getCardData($bookingDto, 0);
|
||||
$result = $this->service()->getCardData($bookingDto, 0);
|
||||
|
||||
$this->assertSame(1234.56, $result->price->amount);
|
||||
$this->assertFalse($result->price->showDash);
|
||||
@@ -403,9 +413,9 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->method('calculateAllParticipantIndividualPrices')
|
||||
->willReturn([0.0, 0.0, 0.0]);
|
||||
|
||||
$result1 = $this->service->getCardData($bookingDto, 0);
|
||||
$result2 = $this->service->getCardData($bookingDto, 1);
|
||||
$result3 = $this->service->getCardData($bookingDto, 2);
|
||||
$result1 = $this->service()->getCardData($bookingDto, 0);
|
||||
$result2 = $this->service()->getCardData($bookingDto, 1);
|
||||
$result3 = $this->service()->getCardData($bookingDto, 2);
|
||||
|
||||
$this->assertSame('Anmelder:in', $result1->name);
|
||||
$this->assertSame('Teilnehmer:in', $result2->name);
|
||||
@@ -414,6 +424,8 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
|
||||
public function testGetCardDataWithValidationReturnsValidCard(): void
|
||||
{
|
||||
$this->validator = $this->createMock(ValidatorInterface::class);
|
||||
|
||||
$room = new Room();
|
||||
$room->id = 1;
|
||||
$room->label = 'Doppelzimmer';
|
||||
@@ -445,7 +457,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->method('validate')
|
||||
->willReturn($violations);
|
||||
|
||||
$result = $this->service->getCardDataWithValidation($bookingDto, 0);
|
||||
$result = $this->service()->getCardDataWithValidation($bookingDto, 0);
|
||||
|
||||
$this->assertSame('Max Mustermann', $result->name);
|
||||
$this->assertSame('Doppelzimmer', $result->roomName);
|
||||
@@ -457,6 +469,8 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
|
||||
public function testGetCardDataWithValidationReturnsInvalidCard(): void
|
||||
{
|
||||
$this->validator = $this->createMock(ValidatorInterface::class);
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->rooms = [];
|
||||
|
||||
@@ -486,7 +500,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->method('validate')
|
||||
->willReturn($violations);
|
||||
|
||||
$result = $this->service->getCardDataWithValidation($bookingDto, 0);
|
||||
$result = $this->service()->getCardDataWithValidation($bookingDto, 0);
|
||||
|
||||
$this->assertSame('Max Mustermann', $result->name);
|
||||
$this->assertFalse($result->isValid);
|
||||
@@ -496,6 +510,9 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
|
||||
public function testGetAllCardsDataWithValidationReturnsAllCards(): void
|
||||
{
|
||||
$this->priceCalculator = $this->createMock(BookingPriceCalculator::class);
|
||||
$this->validator = $this->createMock(ValidatorInterface::class);
|
||||
|
||||
$room = new Room();
|
||||
$room->id = 1;
|
||||
$room->label = 'Doppelzimmer';
|
||||
@@ -534,7 +551,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->method('validate')
|
||||
->willReturn($violations);
|
||||
|
||||
$result = $this->service->getAllCardsDataWithValidation($bookingDto);
|
||||
$result = $this->service()->getAllCardsDataWithValidation($bookingDto);
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertTrue($result[0]->isValid);
|
||||
@@ -545,6 +562,8 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
|
||||
public function testGetCardDataWithValidationCanForceStrictRequiredInEditMode(): void
|
||||
{
|
||||
$this->validator = $this->createMock(ValidatorInterface::class);
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->rooms = [];
|
||||
|
||||
@@ -556,7 +575,7 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->agencyCode = AgencyLoader::INTERNAL_AGENCY_CODE;
|
||||
$bookingDto->booking = new \App\BusProNet\Model\Booking();
|
||||
$bookingDto->booking = new Booking();
|
||||
$bookingDto->participants = [$participant];
|
||||
|
||||
$this->priceCalculator
|
||||
@@ -574,16 +593,15 @@ class ParticipantCardAssemblerTest extends TestCase
|
||||
->expects($this->once())
|
||||
->method('validate')
|
||||
->with(
|
||||
$this->isInstanceOf(\App\Form\Model\ParticipantEditDto::class),
|
||||
$this->isInstanceOf(ParticipantEditDto::class),
|
||||
null,
|
||||
['booking_edit', 'strict_required']
|
||||
)
|
||||
->willReturn($violations);
|
||||
|
||||
$result = $this->service->getCardDataWithValidation($bookingDto, 0, true);
|
||||
$result = $this->service()->getCardDataWithValidation($bookingDto, 0, true);
|
||||
|
||||
$this->assertFalse($result->isValid);
|
||||
$this->assertSame(['Bitte angeben'], $result->errorMessages);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user