ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ListTransformationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use PHPUnit\Framework\TestCase;
26use UnexpectedValueException;
27use PHPUnit\Framework\Attributes\DataProvider;
28
29class 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}