ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Data\DMapTest Class Reference
+ Inheritance diagram for ILIAS\Data\DMapTest:
+ Collaboration diagram for ILIAS\Data\DMapTest:

Public Member Functions

 setUp ()
 
 testObviouslyNotMatching ($data)
 @dataProvider obviousNoMatchProvider More...
 
 testEmptyMatches ()
 
 testForwardsToSubDescriptions ()
 
 testFailsOnKeyFailure ()
 
 testFailsOnValueFailure ()
 

Static Public Member Functions

static obviousNoMatchProvider ()
 

Protected Attributes

DMap $m
 
DValue $k
 
Description $v
 

Detailed Description

Definition at line 32 of file DMapTest.php.

Member Function Documentation

◆ obviousNoMatchProvider()

static ILIAS\Data\DMapTest::obviousNoMatchProvider ( )
static

Definition at line 62 of file DMapTest.php.

62 : array
63 {
64 return [
65 [1], ["1"], [null], [true], [new \StdClass()], [new \DateTimeImmutable()]
66 ];
67 }

◆ setUp()

ILIAS\Data\DMapTest::setUp ( )

Definition at line 38 of file DMapTest.php.

38 : void
39 {
40 $this->k = $this->createMock(DValue::class);
41 $this->v = $this->createMock(Description::class);
42 $this->m = new DMap(
43 $this->createMock(\ILIAS\Data\Text\SimpleDocumentMarkdown::class),
44 $this->k,
45 $this->v
46 );
47 }
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.

◆ testEmptyMatches()

ILIAS\Data\DMapTest::testEmptyMatches ( )

Definition at line 69 of file DMapTest.php.

69 : void
70 {
71 $res = $this->m->getPrimitiveRepresentation([]);
72
73 $this->assertEquals([], $res);
74 }
$res
Definition: ltiservices.php:69

References $res.

◆ testFailsOnKeyFailure()

ILIAS\Data\DMapTest::testFailsOnKeyFailure ( )

Definition at line 111 of file DMapTest.php.

111 : void
112 {
113 $data = ["a" => 1];
114
115 $this->v
116 ->method("getPrimitiveRepresentation")
117 ->willReturn(1);
118
119 $this->k
120 ->method("getPrimitiveRepresentation")
121 ->willReturn(fn() => yield "FAILURE");
122
123 $res = $this->m->getPrimitiveRepresentation($data);
124
125 $this->assertInstanceOf(\Closure::class, $res);
126 $errors = iterator_to_array($res());
127 $this->assertCount(1, $errors);
128 $this->assertTrue(is_string($errors[0]));
129 $this->assertTrue(str_contains($errors[0], "FAILURE"));
130 }

References $data, and $res.

◆ testFailsOnValueFailure()

ILIAS\Data\DMapTest::testFailsOnValueFailure ( )

Definition at line 132 of file DMapTest.php.

132 : void
133 {
134 $data = ["a" => 1];
135
136 $this->v
137 ->method("getPrimitiveRepresentation")
138 ->willReturn(fn() => yield "FAILURE");
139
140 $this->k
141 ->method("getPrimitiveRepresentation")
142 ->willReturn("a");
143
144 $res = $this->m->getPrimitiveRepresentation($data);
145
146 $this->assertInstanceOf(\Closure::class, $res);
147 $errors = iterator_to_array($res());
148 $this->assertCount(1, $errors);
149 $this->assertTrue(is_string($errors[0]));
150 $this->assertTrue(str_contains($errors[0], "FAILURE"));
151 }

References $data, and $res.

◆ testForwardsToSubDescriptions()

ILIAS\Data\DMapTest::testForwardsToSubDescriptions ( )

Definition at line 76 of file DMapTest.php.

76 : void
77 {
78 $data = [
79 "a" => 1,
80 "b" => 2
81 ];
82
83 $keys = ["c", "d"];
84 $this->k->expects($this->exactly(2))
85 ->method("getPrimitiveRepresentation")
86 ->willReturnCallback(function ($v) use (&$keys) {
87 array_push($keys, $v);
88 return array_shift($keys);
89 });
90
91 $values = [3, 4];
92 $this->v->expects($this->exactly(2))
93 ->method("getPrimitiveRepresentation")
94 ->willReturnCallback(function ($v) use (&$values) {
95 array_push($values, $v);
96 return array_shift($values);
97 });
98
99 $expected = [
100 "c" => 3,
101 "d" => 4
102 ];
103
104 $res = $this->m->getPrimitiveRepresentation($data);
105
106 $this->assertEquals($expected, $res);
107 $this->assertEquals(["a", "b"], $keys);
108 $this->assertEquals([1, 2], $values);
109 }
Description $v
Definition: DMapTest.php:36

References $data, $res, and ILIAS\Data\DMapTest\$v.

◆ testObviouslyNotMatching()

ILIAS\Data\DMapTest::testObviouslyNotMatching (   $data)

@dataProvider obviousNoMatchProvider

Definition at line 52 of file DMapTest.php.

52 : void
53 {
54 $res = $this->m->getPrimitiveRepresentation($data);
55
56 $this->assertInstanceOf(\Closure::class, $res);
57 $errors = iterator_to_array($res());
58 $this->assertCount(1, $errors);
59 $this->assertTrue(is_string($errors[0]));
60 }

References $data, and $res.

Field Documentation

◆ $k

DValue ILIAS\Data\DMapTest::$k
protected

Definition at line 35 of file DMapTest.php.

◆ $m

DMap ILIAS\Data\DMapTest::$m
protected

Definition at line 34 of file DMapTest.php.

◆ $v

Description ILIAS\Data\DMapTest::$v
protected

Definition at line 36 of file DMapTest.php.

Referenced by ILIAS\Data\DMapTest\testForwardsToSubDescriptions().


The documentation for this class was generated from the following file: