ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
DictionaryTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 use stdClass;
29 
30 class DictionaryTransformationTest extends TestCase
31 {
36  #[DataProvider('DictionaryTransformationDataProvider')]
37  public function testDictionaryTransformation(array $originVal, array $expectedVal): void
38  {
39  $transformation = new DictionaryTransformation(new StringTransformation());
40  $transformedValue = $transformation->transform($originVal);
41  $this->assertIsArray($transformedValue);
42  $this->assertEquals($expectedVal, $transformedValue);
43  }
44 
45  #[DataProvider('TransformationFailingDataProvider')]
46  public function testTransformationFailures(mixed $failingVal): void
47  {
48  $this->expectException(ConstraintViolationException::class);
49  $transformation = new DictionaryTransformation(new StringTransformation());
50  $transformation->transform($failingVal);
51  }
52 
53  public static function TransformationFailingDataProvider(): array
54  {
55  return [
56  'from_is_a_string' => ['hello'],
57  'from_is_an_int' => [1],
58  'from_is_an_float' => [3.141],
59  'from_is_null' => [null],
60  'from_is_a_bool' => [true],
61  'from_is_a_resource' => [fopen('php://memory', 'rb')],
62  'from_is_an_object' => [new stdClass()],
63  ];
64  }
65 
66  public static function DictionaryTransformationDataProvider(): array
67  {
68  return [
69  'first_arr' => [['hello' => 'world'], ['hello' => 'world'] ],
70  'second_arr' => [['hi' => 'earth', 'goodbye' => 'world'], ['hi' => 'earth', 'goodbye' => 'world']],
71  'third_arr' => [[22 => "earth", 33 => "world"], [22 => "earth", 33 => "world"]],
72  'empty_array' => [[], []]
73  ];
74  }
75 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null