ILIAS  release_8 Revision v8.24
BooleanTransformationTest.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 BooleanTransformation();
34 }
35
41 public function testBooleanTransformation($originVal, bool $expectedVal): void
42 {
43 $transformedValue = $this->transformation->transform($originVal);
44 $this->assertIsBool($transformedValue);
45 $this->assertSame($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 BooleanTestDataProvider(): array
59 {
60 return [
61 'true' => [true, true],
62 'false' => [false, false],
63 'pos_boolean1' => ['true', true],
64 'pos_boolean2' => ['TRUE', true],
65 'pos_boolean3' => ['True', true],
66 'pos_boolean4' => ['tRuE', true],
67 'pos_boolean_number' => [1, true],
68 'pos_boolean_number_string' => ['1', true],
69 'neg_boolean1' => ['false', false],
70 'neg_boolean2' => ['FALSE', false],
71 'neg_boolean3' => ['False', false],
72 'neg_boolean4' => ['fAlSe', false],
73 'neg_boolean_number' => [0, false],
74 'neg_boolean_number_string' => ['0', false]
75 ];
76 }
77
78 public function TransformationFailureDataProvider(): array
79 {
80 return [
81 'null' => [null],
82 'null_as_string' => ["null"],
83 'float_zero' => [0.0],
84 'float_one' => [1.0],
85 'two' => [2],
86 'two_as_string' => ["2"],
87 'some_array' => [[]],
88 'some_string' => [""]
89 ];
90 }
91}
testBooleanTransformation($originVal, bool $expectedVal)
@dataProvider BooleanTestDataProvider
testTransformIsInvalid($failingValue)
@dataProvider TransformationFailureDataProvider
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...