ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
FloatTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 
28 class FloatTransformationTest extends TestCase
29 {
31 
32  protected function setUp(): void
33  {
34  $this->transformation = new FloatTransformation();
35  }
36 
37  #[DataProvider('FloatTestDataProvider')]
38  public function testFloatTransformation(mixed $originVal, float $expectedVal): void
39  {
40  $transformedValue = $this->transformation->transform($originVal);
41  $this->assertIsFloat($transformedValue);
42  $this->assertEquals($expectedVal, $transformedValue);
43  }
44 
45  #[DataProvider('FailingTransformationDataProvider')]
46  public function testFailingTransformations(mixed $failingVal): void
47  {
48  $this->expectNotToPerformAssertions();
49  try {
50  $transformedValue = $this->transformation->transform($failingVal);
51  } catch (ConstraintViolationException $exception) {
52  return;
53  }
54  $this->fail();
55  }
56 
57  public static function FailingTransformationDataProvider(): array
58  {
59  return [
60  'null' => [null],
61  'empty' => [""],
62  'written_false' => ['false'],
63  'written_null' => ['null'],
64  'NaN' => [NAN],
65  'written_NaN' => ['NaN'],
66  'INF' => [INF],
67  'neg_INF' => [-INF],
68  'written_INF' => ['INF'],
69  'written_neg_INF' => ['-INF'],
70  'octal_notation1' => ["01"],
71  'octal_notation2' => ["-01"],
72  'mill_delim' => ["1'000"],
73  'leading_dot' => [".5"],
74  'leading_comma' => [",661"]
75  ];
76  }
77 
78  public static function FloatTestDataProvider(): array
79  {
80  return [
81  'some_float' => [1.0, 1.0],
82  'pos_bool' => [true, 1.0],
83  'neg_bool' => [false, 0.0],
84  'string_comma' => ['234,23', 234.23],
85  'neg_string_comma' => ['-234,23', -234.23],
86  'neg_string_comma_trimming' => [' -234,23 ', -234.23],
87  'string_point' => ['234.23', 234.23],
88  'neg_string_point' => ['-234.23', -234.23],
89  'neg_string_point_trimming' => [' -234.23 ', -234.23],
90  'string_e_notation' => ['7E10', 70000000000],
91  'string_e_notation_trimming' => [' 7E10 ', 70000000000],
92  'neg_string_e_notation' => ['-7E10', -70000000000],
93  'neg_string_e_notation_trimming' => [' -7E10 ', -70000000000],
94  'int_val' => [23, 23.0],
95  'neg_int_val' => [-2, -2.0],
96  'zero_int' => [0, 0.0],
97  'zero_string' => ["0", 0.0],
98  'float_st_one' => [0.1, 0.1],
99  'floatstr_st_one' => ['0.1', 0.1],
100  'floatstr_st_one_negative' => ['-0.1', -0.1],
101  'floatstr_st_one_comma' => ['0,1', 0.1],
102  'floatstr_st_one_comma_negative' => ['-0,1', -0.1]
103  ];
104  }
105 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null