ILIAS  release_7 Revision v7.30-3-g800a261c036
BooleanTransformationTest.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 BooleanTransformation();
20 }
21
27 public function testBooleanTransformation($originVal, $expectedVal)
28 {
29 $transformedValue = $this->transformation->transform($originVal);
30 $this->assertIsBool($transformedValue);
31 $this->assertSame($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 BooleanTestDataProvider()
45 {
46 return [
47 'true' => [true, true],
48 'false' => [false, false],
49 'pos_boolean1' => ['true', true],
50 'pos_boolean2' => ['TRUE', true],
51 'pos_boolean3' => ['True', true],
52 'pos_boolean4' => ['tRuE', true],
53 'pos_boolean_number' => [1, true],
54 'pos_boolean_number_string' => ['1', true],
55 'neg_boolean1' => ['false', false],
56 'neg_boolean2' => ['FALSE', false],
57 'neg_boolean3' => ['False', false],
58 'neg_boolean4' => ['fAlSe', false],
59 'neg_boolean_number' => [0, false],
60 'neg_boolean_number_string' => ['0', false]
61 ];
62 }
63
64
66 {
67 return [
68 'null' => [null],
69 'null_as_string' => ["null"],
70 'float_zero' => [0.0],
71 'float_one' => [1.0],
72 'two' => [2],
73 'two_as_string' => ["2"],
74 'some_array' => [[]],
75 'some_string' => [""]
76 ];
77 }
78}
An exception for terminatinating execution or to throw for unit testing.
testTransformIsInvalid($failingValue)
@dataProvider TransformationFailureDataProvider
testBooleanTransformation($originVal, $expectedVal)
@dataProvider BooleanTestDataProvider