ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
BooleanTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
28 class BooleanTransformationTest extends TestCase
29 {
31 
32  protected function setUp(): void
33  {
34  $this->transformation = new BooleanTransformation();
35  }
36 
37  #[DataProvider('BooleanTestDataProvider')]
38  public function testBooleanTransformation(mixed $originVal, bool $expectedVal): void
39  {
40  $transformedValue = $this->transformation->transform($originVal);
41  $this->assertIsBool($transformedValue);
42  $this->assertSame($expectedVal, $transformedValue);
43  }
44 
45  #[DataProvider('TransformationFailureDataProvider')]
46  public function testTransformIsInvalid(mixed $failingValue): void
47  {
48  $this->expectException(ConstraintViolationException::class);
49  $this->transformation->transform($failingValue);
50  }
51 
52  public static function BooleanTestDataProvider(): array
53  {
54  return [
55  'true' => [true, true],
56  'false' => [false, false],
57  'pos_boolean1' => ['true', true],
58  'pos_boolean2' => ['TRUE', true],
59  'pos_boolean3' => ['True', true],
60  'pos_boolean4' => ['tRuE', true],
61  'pos_boolean_number' => [1, true],
62  'pos_boolean_number_string' => ['1', true],
63  'neg_boolean1' => ['false', false],
64  'neg_boolean2' => ['FALSE', false],
65  'neg_boolean3' => ['False', false],
66  'neg_boolean4' => ['fAlSe', false],
67  'neg_boolean_number' => [0, false],
68  'neg_boolean_number_string' => ['0', false]
69  ];
70  }
71 
72  public static function TransformationFailureDataProvider(): array
73  {
74  return [
75  'null' => [null],
76  'null_as_string' => ["null"],
77  'float_zero' => [0.0],
78  'float_one' => [1.0],
79  'two' => [2],
80  'two_as_string' => ["2"],
81  'some_array' => [[]],
82  'some_string' => [""]
83  ];
84  }
85 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null