ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
IntegerTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
28 class IntegerTransformationTest extends TestCase
29 {
31 
32  protected function setUp(): void
33  {
34  $this->transformation = new IntegerTransformation();
35  }
36 
37  #[DataProvider('IntegerTestDataProvider')]
38  public function testIntegerTransformation(mixed $originVal, int $expectedVal): void
39  {
40  $transformedValue = $this->transformation->transform($originVal);
41  $this->assertIsInt($transformedValue);
42  $this->assertEquals($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 IntegerTestDataProvider(): array
53  {
54  return [
55  'pos_bool' => [true, 1],
56  'neg_bool' => [false, 0],
57  'float_val' => [20.5, 21],
58  'float_val_round_up' => [0.51, 1],
59  'float_val_round_down' => [0.49, 0],
60  'string_zero' => ['0', 0],
61  'string_val' => ['4947642', 4947642],
62  'neg_string_val' => ['-4947642', -4947642],
63  'string_val_trimming' => [' 4947642 ', 4947642],
64  'neg_string_val_trimming' => [' -4947642 ', -4947642],
65  ];
66  }
67 
68  public static function TransformationFailureDataProvider(): array
69  {
70  return [
71  'bigger_than_int_max' => ["9223372036854775808"],
72  'smaller_than_int_min' => ["-9223372036854775809"],
73  'weird_notation' => ["01"],
74  'some_array' => [[]],
75  'mill_delim' => ["1'000"],
76  'null' => [null],
77  'empty' => [""],
78  'written_false' => ['false'],
79  'written_null' => ['null'],
80  'NaN' => [NAN],
81  'written_NaN' => ['NaN'],
82  'INF' => [INF],
83  'neg_INF' => [-INF],
84  'written_INF' => ['INF'],
85  'written_neg_INF' => ['-INF'],
86  ];
87  }
88 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null