ILIAS  release_8 Revision v8.24
DictionaryTransformationTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
27use stdClass;
28
30{
36 public function testDictionaryTransformation(array $originVal, array $expectedVal): void
37 {
38 $transformation = new DictionaryTransformation(new StringTransformation());
39 $transformedValue = $transformation->transform($originVal);
40 $this->assertIsArray($transformedValue);
41 $this->assertEquals($expectedVal, $transformedValue);
42 }
43
48 public function testTransformationFailures($failingVal): void
49 {
50 $this->expectException(ConstraintViolationException::class);
51 $transformation = new DictionaryTransformation(new StringTransformation());
52 $transformation->transform($failingVal);
53 }
54
55 public function TransformationFailingDataProvider(): array
56 {
57 return [
58 'from_is_a_string' => ['hello'],
59 'from_is_an_int' => [1],
60 'from_is_an_float' => [3.141],
61 'from_is_null' => [null],
62 'from_is_a_bool' => [true],
63 'from_is_a_resource' => [fopen('php://memory', 'rb')],
64 'from_is_an_object' => [new stdClass()],
65 ];
66 }
67
68 public function DictionaryTransformationDataProvider(): array
69 {
70 return [
71 'first_arr' => [['hello' => 'world'], ['hello' => 'world'] ],
72 'second_arr' => [['hi' => 'earth', 'goodbye' => 'world'], ['hi' => 'earth', 'goodbye' => 'world']],
73 'third_arr' => [[22 => "earth", 33 => "world"], [22 => "earth", 33 => "world"]],
74 'fourth_arr' => [[22.33 => "earth", 33.44 => "world"], [22 => "earth", 33 => "world"]],// This will result in a float rounding error in PHP >= 8.1
75 'empty_array' => [[], []]
76 ];
77 }
78}
testDictionaryTransformation(array $originVal, array $expectedVal)
@dataProvider DictionaryTransformationDataProvider
testTransformationFailures($failingVal)
@dataProvider TransformationFailingDataProvider
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...