feat: replace dropdowns with individual fields for body dimensions
This commit is contained in:
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Exception\TimeoutException;
|
||||
use App\BusProNet\Model\Booking;
|
||||
@@ -28,7 +27,7 @@ use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
class BookingEditSubmitterTest extends TestCase
|
||||
{
|
||||
public function testHandleSubmissionReturnsResultWhenFreshBookingDataCannotBeLoaded(): void
|
||||
public function testHandleSubmissionReturnsRedirectWhenFreshBookingDataCannotBeLoaded(): void
|
||||
{
|
||||
$request = $this->createRequestWithSession();
|
||||
$user = $this->createUser();
|
||||
@@ -50,13 +49,14 @@ class BookingEditSubmitterTest extends TestCase
|
||||
$result = $service->handleSubmission($request, $bookingDto, 42, $user);
|
||||
|
||||
$this->assertSame(BookingEditSubmissionResult::STATUS_BOOKING_DATA_RELOAD_FAILED, $result->status);
|
||||
$this->assertNull($result->message);
|
||||
$this->assertFalse($result->immutableChangesReverted);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider updateFailureProvider
|
||||
*/
|
||||
public function testHandleSubmissionReturnsResultWhenUpdateThrows(
|
||||
public function testHandleSubmissionReturnsRedirectWhenUpdateThrows(
|
||||
\Throwable $exception,
|
||||
string $expectedStatus,
|
||||
): void {
|
||||
@@ -88,7 +88,7 @@ class BookingEditSubmitterTest extends TestCase
|
||||
->with($bookingDto, $freshBookingData)
|
||||
->willReturn(false);
|
||||
|
||||
$apiClient = $this->createMock(ApiClient::class);
|
||||
$apiClient = $this->createMock(\App\BusProNet\ApiClient::class);
|
||||
$apiClient->expects($this->once())
|
||||
->method('updateBooking')
|
||||
->with($bookingDto, true)
|
||||
@@ -108,7 +108,7 @@ class BookingEditSubmitterTest extends TestCase
|
||||
$this->assertFalse($result->immutableChangesReverted);
|
||||
}
|
||||
|
||||
public function testHandleSubmissionReturnsResultWhenUpdateIsUnsuccessful(): void
|
||||
public function testHandleSubmissionReturnsRedirectWhenUpdateIsUnsuccessful(): void
|
||||
{
|
||||
$request = $this->createRequestWithSession();
|
||||
$user = $this->createUser();
|
||||
@@ -138,7 +138,7 @@ class BookingEditSubmitterTest extends TestCase
|
||||
->with($bookingDto, $freshBookingData)
|
||||
->willReturn(false);
|
||||
|
||||
$apiClient = $this->createMock(ApiClient::class);
|
||||
$apiClient = $this->createMock(\App\BusProNet\ApiClient::class);
|
||||
$bookingUpdate = new BookingUpdate();
|
||||
$bookingUpdate->success = false;
|
||||
$bookingUpdate->status = 'BPN-FAIL';
|
||||
@@ -163,12 +163,12 @@ class BookingEditSubmitterTest extends TestCase
|
||||
|
||||
public function testHandleSubmissionStoresInfoForNonErrorNotification(): void
|
||||
{
|
||||
$this->assertNotificationResult(new Notification(650, 'Alles gut'), 'info');
|
||||
$this->assertNotificationResult(new Notification(650, 'Alles gut'));
|
||||
}
|
||||
|
||||
public function testHandleSubmissionStoresErrorForErrorNotification(): void
|
||||
{
|
||||
$this->assertNotificationResult(new Notification(500, 'Kaputt'), 'error');
|
||||
$this->assertNotificationResult(new Notification(500, 'Kaputt'));
|
||||
}
|
||||
|
||||
public function testHandleSubmissionClearsSessionAndDraftOnSuccessfulUpdate(): void
|
||||
@@ -201,7 +201,7 @@ class BookingEditSubmitterTest extends TestCase
|
||||
->with($bookingDto, $freshBookingData)
|
||||
->willReturn(false);
|
||||
|
||||
$apiClient = $this->createMock(ApiClient::class);
|
||||
$apiClient = $this->createMock(\App\BusProNet\ApiClient::class);
|
||||
$bookingUpdate = new BookingUpdate();
|
||||
$bookingUpdate->success = true;
|
||||
$apiClient->expects($this->once())
|
||||
@@ -233,6 +233,7 @@ class BookingEditSubmitterTest extends TestCase
|
||||
$result = $service->handleSubmission($request, $bookingDto, 42, $user);
|
||||
|
||||
$this->assertSame(BookingEditSubmissionResult::STATUS_SUCCESS, $result->status);
|
||||
$this->assertNull($result->message);
|
||||
$this->assertFalse($result->immutableChangesReverted);
|
||||
$this->assertSame($freshBookingData, $bookingDto->booking);
|
||||
}
|
||||
@@ -267,7 +268,7 @@ class BookingEditSubmitterTest extends TestCase
|
||||
->with($bookingDto, $freshBookingData)
|
||||
->willReturn(true);
|
||||
|
||||
$apiClient = $this->createMock(ApiClient::class);
|
||||
$apiClient = $this->createMock(\App\BusProNet\ApiClient::class);
|
||||
$bookingUpdate = new BookingUpdate();
|
||||
$bookingUpdate->success = true;
|
||||
$apiClient->expects($this->once())
|
||||
@@ -300,15 +301,16 @@ class BookingEditSubmitterTest extends TestCase
|
||||
$result = $service->handleSubmission($request, $bookingDto, 42, $user);
|
||||
|
||||
$this->assertSame(BookingEditSubmissionResult::STATUS_SUCCESS, $result->status);
|
||||
$this->assertNull($result->message);
|
||||
$this->assertTrue($result->immutableChangesReverted);
|
||||
}
|
||||
|
||||
public function testHandleSubmissionReturnsResultOnTimeout(): void
|
||||
public function testHandleSubmissionReturnsRedirectOnTimeout(): void
|
||||
{
|
||||
$this->assertExceptionResult(new TimeoutException('slow'), BookingEditSubmissionResult::STATUS_TIMEOUT);
|
||||
}
|
||||
|
||||
public function testHandleSubmissionReturnsResultOnApiClientException(): void
|
||||
public function testHandleSubmissionReturnsRedirectOnApiClientException(): void
|
||||
{
|
||||
$this->assertExceptionResult(new ApiClientException('boom'), BookingEditSubmissionResult::STATUS_API_CLIENT_ERROR);
|
||||
}
|
||||
@@ -321,7 +323,7 @@ class BookingEditSubmitterTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
private function assertNotificationResult(Notification $notification, string $expectedType): void
|
||||
private function assertNotificationResult(Notification $notification): void
|
||||
{
|
||||
$request = $this->createRequestWithSession();
|
||||
$user = $this->createUser();
|
||||
@@ -351,7 +353,7 @@ class BookingEditSubmitterTest extends TestCase
|
||||
->with($bookingDto, $freshBookingData)
|
||||
->willReturn(false);
|
||||
|
||||
$apiClient = $this->createMock(ApiClient::class);
|
||||
$apiClient = $this->createMock(\App\BusProNet\ApiClient::class);
|
||||
$apiClient->expects($this->once())
|
||||
->method('updateBooking')
|
||||
->with($bookingDto, true)
|
||||
@@ -366,7 +368,12 @@ class BookingEditSubmitterTest extends TestCase
|
||||
|
||||
$result = $service->handleSubmission($request, $bookingDto, 42, $user);
|
||||
|
||||
$this->assertSame($this->resolveExpectedStatus($expectedType), $result->status);
|
||||
$this->assertSame(
|
||||
true === $notification->isError()
|
||||
? BookingEditSubmissionResult::STATUS_NOTIFICATION_ERROR
|
||||
: BookingEditSubmissionResult::STATUS_NOTIFICATION_INFO,
|
||||
$result->status,
|
||||
);
|
||||
$this->assertSame($notification->message, $result->message);
|
||||
$this->assertFalse($result->immutableChangesReverted);
|
||||
}
|
||||
@@ -401,7 +408,7 @@ class BookingEditSubmitterTest extends TestCase
|
||||
->with($bookingDto, $freshBookingData)
|
||||
->willReturn(false);
|
||||
|
||||
$apiClient = $this->createMock(ApiClient::class);
|
||||
$apiClient = $this->createMock(\App\BusProNet\ApiClient::class);
|
||||
$apiClient->expects($this->once())
|
||||
->method('updateBooking')
|
||||
->with($bookingDto, true)
|
||||
@@ -422,7 +429,7 @@ class BookingEditSubmitterTest extends TestCase
|
||||
}
|
||||
|
||||
private function createService(
|
||||
?ApiClient $apiClient = null,
|
||||
?\App\BusProNet\ApiClient $apiClient = null,
|
||||
?BookingEditDataLoader $dataLoader = null,
|
||||
?BookingEditDraftManager $draftService = null,
|
||||
?TravelDataProvider $travelDataService = null,
|
||||
@@ -430,7 +437,7 @@ class BookingEditSubmitterTest extends TestCase
|
||||
?BookingSessionManager $bookingSessionService = null,
|
||||
): BookingEditSubmitter {
|
||||
return new BookingEditSubmitter(
|
||||
$apiClient ?? $this->createMock(ApiClient::class),
|
||||
$apiClient ?? $this->createMock(\App\BusProNet\ApiClient::class),
|
||||
$dataLoader ?? $this->createMock(BookingEditDataLoader::class),
|
||||
$draftService ?? $this->createMock(BookingEditDraftManager::class),
|
||||
$travelDataService ?? $this->createMock(TravelDataProvider::class),
|
||||
@@ -469,13 +476,4 @@ class BookingEditSubmitterTest extends TestCase
|
||||
return $request;
|
||||
}
|
||||
|
||||
private function resolveExpectedStatus(string $expectedType): string
|
||||
{
|
||||
return match ($expectedType) {
|
||||
'error' => BookingEditSubmissionResult::STATUS_NOTIFICATION_ERROR,
|
||||
'info' => BookingEditSubmissionResult::STATUS_NOTIFICATION_INFO,
|
||||
default => $expectedType,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Service\ParticipantFormSupport;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
|
||||
class ParticipantFormSupportTest extends TestCase
|
||||
{
|
||||
@@ -61,34 +60,40 @@ class ParticipantFormSupportTest extends TestCase
|
||||
|
||||
public function testGetParticipantFormOptionsIncludesValidationToggle(): void
|
||||
{
|
||||
$parameterBag = $this->createMock(ParameterBagInterface::class);
|
||||
$parameterBag->expects($this->exactly(4))
|
||||
->method('get')
|
||||
->willReturnMap([
|
||||
['body_dimensions.height_choices', ['bis 148cm' => '-148']],
|
||||
['body_dimensions.weight_choices', ['42 - 48kg' => '42-48']],
|
||||
['body_dimensions.shoe_size_min', 36],
|
||||
['body_dimensions.shoe_size_max', 48],
|
||||
]);
|
||||
$bodyDimensionRanges = [
|
||||
'height_min' => 145,
|
||||
'height_max' => 210,
|
||||
'weight_min' => 40,
|
||||
'weight_max' => 120,
|
||||
'shoe_size_min' => 35,
|
||||
'shoe_size_max' => 50,
|
||||
];
|
||||
|
||||
$service = $this->createService(parameterBag: $parameterBag);
|
||||
$service = $this->createService(bodyDimensionRanges: $bodyDimensionRanges);
|
||||
$bookingDto = $this->createBookingDto();
|
||||
|
||||
$options = $service->getParticipantFormOptions($bookingDto, true);
|
||||
|
||||
$this->assertSame($bookingDto, $options['booking_context']);
|
||||
$this->assertSame(['bis 148cm' => '-148'], $options['height_choices']);
|
||||
$this->assertSame(['42 - 48kg' => '42-48'], $options['weight_choices']);
|
||||
$this->assertSame(36, $options['shoe_size_min']);
|
||||
$this->assertSame(48, $options['shoe_size_max']);
|
||||
$this->assertFalse($options['validation_groups']);
|
||||
$this->assertSame($bodyDimensionRanges, $options['body_dimension_ranges']);
|
||||
$this->assertContains('validation_groups', array_keys($options));
|
||||
}
|
||||
|
||||
private function createService(?ParameterBagInterface $parameterBag = null): ParticipantFormSupport
|
||||
/**
|
||||
* array<string, int>|null $bodyDimensionRanges
|
||||
*/
|
||||
private function createService(?array $bodyDimensionRanges = null): ParticipantFormSupport
|
||||
{
|
||||
$parameterBag ??= $this->createMock(ParameterBagInterface::class);
|
||||
$bodyDimensionRanges ??= [
|
||||
'height_min' => 145,
|
||||
'height_max' => 210,
|
||||
'weight_min' => 40,
|
||||
'weight_max' => 120,
|
||||
'shoe_size_min' => 35,
|
||||
'shoe_size_max' => 50,
|
||||
];
|
||||
|
||||
return new ParticipantFormSupport($parameterBag);
|
||||
return new ParticipantFormSupport($bodyDimensionRanges);
|
||||
}
|
||||
|
||||
private function createBookingDto(): BookingDto
|
||||
|
||||
Reference in New Issue
Block a user