ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ListTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
29 class ListTransformationTest extends TestCase
30 {
31  #[DataProvider('ArrayToListTransformationDataProvider')]
32  public function testListTransformation(mixed $originValue, mixed $expectedValue): void
33  {
34  $transformList = new ListTransformation(new StringTransformation());
35  $transformedValue = $transformList->transform($originValue);
36  $this->assertIsArray($transformedValue);
37  $this->assertEquals($expectedValue, $transformedValue);
38  }
39 
40  #[DataProvider('ArrayFailureDataProvider')]
41  public function testFailingTransformations(mixed $origValue): void
42  {
43  $this->expectException(UnexpectedValueException::class);
44  $transformList = new ListTransformation(new StringTransformation());
45  $transformList->transform($origValue);
46  }
47 
48  public static function ArrayToListTransformationDataProvider(): array
49  {
50  return [
51  'first_arr' => [['hello', 'world'], ['hello', 'world']],
52  'second_arr' => [['hello2', 'world2'], ['hello2', 'world2']],
53  'string_val' => ['hello world', ['hello world']],
54  'empty_array' => [[], []]
55  ];
56  }
57 
58  public static function ArrayFailureDataProvider(): array
59  {
60  return [
61  'null_array' => [[null]],
62  'value_is_no_string' => [['hello', 2]]
63  ];
64  }
65 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null