ILIAS  release_7 Revision v7.30-3-g800a261c036
IntegerTransformationTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2020 Luka K. A. Stocker, Extended GPL, see docs/LICENSE */
3
5
9
14{
16
17 public function setUp() : void
18 {
19 $this->transformation = new IntegerTransformation();
20 }
21
27 public function testIntegerTransformation($originVal, $expectedVal)
28 {
29 $transformedValue = $this->transformation->transform($originVal);
30 $this->assertIsInt($transformedValue);
31 $this->assertEquals($expectedVal, $transformedValue);
32 }
33
38 public function testTransformIsInvalid($failingValue)
39 {
40 $this->expectException(ConstraintViolationException::class);
41 $this->transformation->transform($failingValue);
42 }
43
44 public function IntegerTestDataProvider()
45 {
46 return [
47 'pos_bool' => [true, (int) 1],
48 'neg_bool' => [false, (int) 0],
49 'float_val' => [20.5, 21],
50 'float_val_round_up' => [0.51, 1],
51 'float_val_round_down' => [0.49, 0],
52 'string_zero' => ['0', 0],
53 'string_val' => ['4947642', 4947642],
54 'neg_string_val' => ['-4947642', -4947642],
55 'string_val_trimming' => [' 4947642 ', 4947642],
56 'neg_string_val_trimming' => [' -4947642 ', -4947642],
57 ];
58 }
59
61 {
62 return [
63 'bigger_than_int_max' => ["9223372036854775808"],
64 'smaller_than_int_min' => ["-9223372036854775809"],
65 'weird_notation' => ["01"],
66 'some_array' => [[]],
67 'mill_delim' => ["1'000"],
68 'null' => [null],
69 'empty' => [""],
70 'written_false' => ['false'],
71 'written_null' => ['null'],
72 'NaN' => [NAN],
73 'written_NaN' => ['NaN'],
74 'INF' => [INF],
75 'neg_INF' => [-INF],
76 'written_INF' => ['INF'],
77 'written_neg_INF' => ['-INF'],
78 ];
79 }
80}
An exception for terminatinating execution or to throw for unit testing.
testIntegerTransformation($originVal, $expectedVal)
@dataProvider IntegerTestDataProvider
testTransformIsInvalid($failingValue)
@dataProvider TransformationFailureDataProvider