ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
NullTransformationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use PHPUnit\Framework\TestCase;
24use PHPUnit\Framework\Attributes\DataProvider;
25
26class NullTransformationTest extends TestCase
27{
29
30 protected function setUp(): void
31 {
32 $this->transformation = new NullTransformation();
33 }
34
35 public static function NullTestDataProvider(): array
36 {
37 return [
38 'empty string' => ['', true],
39 'space' => [' ', true],
40 'spaces' => [' ', true],
41 'null' => [null, true],
42 'string' => ['str', false],
43 'int' => [1, false],
44 'negative int' => [-1, false],
45 'zero' => [0, false],
46 'array' => [[], false],
47 'bool (false)' => [false, false],
48 'bool (true)' => [true, false]
49 ];
50 }
51
52 #[DataProvider('NullTestDataProvider')]
53 public function testNullTransformation(mixed $value, bool $valid): void
54 {
55 if (!$valid) {
56 $this->expectException(ConstraintViolationException::class);
57 }
58 $transformed = $this->transformation->transform($value);
59 $this->assertNull($transformed);
60 }
61}
testNullTransformation(mixed $value, bool $valid)
NullTransformation $transformation
$valid