ILIAS  trunk Revision v12.0_alpha-1540-g00f839d5fa1
DValueTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26
29use PHPUnit\Framework\TestCase;
30use PHPUnit\Framework\Attributes\DataProvider;
31
32class DDValueTest extends TestCase
33{
34 #[DataProvider('casesProvider')]
35 public function testIntRepresentation(ValueType $type, $value, $is_match): void
36 {
37 $desc = new DValue(
38 $this->createMock(\ILIAS\Data\Text\SimpleDocumentMarkdown::class),
39 $type
40 );
41
42 $res = $desc->getPrimitiveRepresentation($value);
43
44 if ($is_match) {
45 $this->assertEquals($value, $res);
46 } else {
47 $this->assertInstanceOf(\Closure::class, $res);
48 $errors = iterator_to_array($res());
49 $this->assertCount(1, $errors);
50 $this->assertTrue(is_string($errors[0]));
51 }
52 }
53
54 public static function casesProvider(): array
55 {
56 return [
57 [ValueType::INT, 42, true],
58 [ValueType::INT, "foo", false],
59 [ValueType::FLOAT, 2.3, true],
60 [ValueType::FLOAT, "foo", false],
61 [ValueType::STRING, "foo", true],
62 [ValueType::STRING, 2, false],
63 [ValueType::DATETIME, new \DateTimeImmutable(), true],
64 [ValueType::DATETIME, "foo", false],
65 [ValueType::BOOL, true, true],
66 [ValueType::BOOL, false, true],
67 [ValueType::BOOL, "true", false],
68 [ValueType::BOOL, 1, false],
69 [ValueType::BOOL, null, false],
70 [ValueType::NULL, null, true],
71 [ValueType::NULL, false, false],
72 ];
73 }
74}
testIntRepresentation(ValueType $type, $value, $is_match)
Definition: DValueTest.php:35
$res
Definition: ltiservices.php:69
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.