ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
TupleTransformationTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
29 class TupleTransformationTest extends TestCase
30 {
31  private const TUPLE_KEY = 'hello';
32 
37  #[DataProvider('TupleTransformationDataProvider')]
38  public function testTupleTransformation(array $originVal, array $expectedVal): void
39  {
40  $transformation = new TupleTransformation(
41  [
44  ]
45  );
46  $transformedValue = $transformation->transform($originVal);
47  $this->assertIsArray($transformedValue);
48  $this->assertEquals($expectedVal, $transformedValue);
49  }
50 
54  #[DataProvider('TupleFailingTransformationDataProvider')]
55  public function testNewTupleIsIncorrect(array $failingVal): void
56  {
57  $this->expectNotToPerformAssertions();
58  $transformation = new TupleTransformation(
59  [
61  self::TUPLE_KEY => new IntegerTransformation()
62  ]
63  );
64 
65  try {
66  $result = $transformation->transform($failingVal);
67  } catch (ConstraintViolationException $exception) {
68  return;
69  }
70  $this->fail();
71  }
72 
76  #[DataProvider('TupleTooManyValuesDataProvider')]
77  public function testTupleTooManyValues(array $tooManyValues): void
78  {
79  $this->expectNotToPerformAssertions();
80  $transformation = new TupleTransformation(
81  [
84  ]
85  );
86 
87  try {
88  $result = $transformation->transform($tooManyValues);
89  } catch (ConstraintViolationException $exception) {
90  return;
91  }
92  $this->fail();
93  }
94 
95  public static function TupleTooManyValuesDataProvider(): array
96  {
97  return [
98  'too_many_values' => [[1,2,3]]
99  ];
100  }
101 
102  public static function TupleFailingTransformationDataProvider(): array
103  {
104  return [
105  'incorrect_tuple' => [[1, 2]]
106  ];
107  }
108 
109  public static function TupleTransformationDataProvider(): array
110  {
111  return [
112  'array_test01' => [[1, 2], [1, 2]]
113  ];
114  }
115 }