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