ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
DictionaryTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
27 use stdClass;
28 
29 class DictionaryTransformationTest extends TestCase
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 static 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 static 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  'empty_array' => [[], []]
75  ];
76  }
77 }
testDictionaryTransformation(array $originVal, array $expectedVal)
DictionaryTransformationDataProvider
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null