ILIAS  release_8 Revision v8.24
IntegerTransformationTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
26
28{
30
31 protected function setUp(): void
32 {
33 $this->transformation = new IntegerTransformation();
34 }
35
41 public function testIntegerTransformation($originVal, int $expectedVal): void
42 {
43 $transformedValue = $this->transformation->transform($originVal);
44 $this->assertIsInt($transformedValue);
45 $this->assertEquals($expectedVal, $transformedValue);
46 }
47
52 public function testTransformIsInvalid($failingValue): void
53 {
54 $this->expectException(ConstraintViolationException::class);
55 $this->transformation->transform($failingValue);
56 }
57
58 public function IntegerTestDataProvider(): array
59 {
60 return [
61 'pos_bool' => [true, 1],
62 'neg_bool' => [false, 0],
63 'float_val' => [20.5, 21],
64 'float_val_round_up' => [0.51, 1],
65 'float_val_round_down' => [0.49, 0],
66 'string_zero' => ['0', 0],
67 'string_val' => ['4947642', 4947642],
68 'neg_string_val' => ['-4947642', -4947642],
69 'string_val_trimming' => [' 4947642 ', 4947642],
70 'neg_string_val_trimming' => [' -4947642 ', -4947642],
71 ];
72 }
73
74 public function TransformationFailureDataProvider(): array
75 {
76 return [
77 'bigger_than_int_max' => ["9223372036854775808"],
78 'smaller_than_int_min' => ["-9223372036854775809"],
79 'weird_notation' => ["01"],
80 'some_array' => [[]],
81 'mill_delim' => ["1'000"],
82 'null' => [null],
83 'empty' => [""],
84 'written_false' => ['false'],
85 'written_null' => ['null'],
86 'NaN' => [NAN],
87 'written_NaN' => ['NaN'],
88 'INF' => [INF],
89 'neg_INF' => [-INF],
90 'written_INF' => ['INF'],
91 'written_neg_INF' => ['-INF'],
92 ];
93 }
94}
testIntegerTransformation($originVal, int $expectedVal)
@dataProvider IntegerTestDataProvider
testTransformIsInvalid($failingValue)
@dataProvider TransformationFailureDataProvider
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...