feat: use normalized checkbox values in field handlers
This commit is contained in:
@@ -37,6 +37,22 @@ class ParticipantParkingFieldHandlerTest extends TestCase
|
||||
$this->assertTrue($this->handler->shouldProcess(['some' => 'data'], BookingDto::MODE_EDIT, 5));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider normalizeCheckboxValueCheckedProvider
|
||||
*/
|
||||
public function testNormalizeCheckboxValueReturnsTrueWhenChecked(mixed $value): void
|
||||
{
|
||||
$this->assertTrue($this->invokeNormalizeCheckboxValue($value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider normalizeCheckboxValueUncheckedProvider
|
||||
*/
|
||||
public function testNormalizeCheckboxValueReturnsFalseWhenUnchecked(mixed $value): void
|
||||
{
|
||||
$this->assertFalse($this->invokeNormalizeCheckboxValue($value));
|
||||
}
|
||||
|
||||
public function testProcessFieldWithoutParticipant(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
@@ -241,6 +257,40 @@ class ParticipantParkingFieldHandlerTest extends TestCase
|
||||
$this->assertNull($participant->parkingService);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{mixed}>
|
||||
*/
|
||||
public static function normalizeCheckboxValueCheckedProvider(): array
|
||||
{
|
||||
return [
|
||||
'true' => [true],
|
||||
'int 1' => [1],
|
||||
'string 1' => ['1'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array{mixed}>
|
||||
*/
|
||||
public static function normalizeCheckboxValueUncheckedProvider(): array
|
||||
{
|
||||
return [
|
||||
'false' => [false],
|
||||
'int 0' => [0],
|
||||
'string 0' => ['0'],
|
||||
'empty string' => [''],
|
||||
'null' => [null],
|
||||
'non-numeric string' => ['off'],
|
||||
];
|
||||
}
|
||||
|
||||
private function invokeNormalizeCheckboxValue(mixed $value): bool
|
||||
{
|
||||
$reflection = new \ReflectionMethod($this->handler, 'normalizeCheckboxValue');
|
||||
|
||||
return $reflection->invoke($this->handler, $value);
|
||||
}
|
||||
|
||||
private function createTransportationService(string $subType): Service
|
||||
{
|
||||
$service = new Service();
|
||||
|
||||
Reference in New Issue
Block a user