ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ReaderTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
35
36class ReaderTest extends TestCase
37{
38 protected function getPath(int $number_of_data): PathInterface
39 {
40 return new class ($number_of_data) extends NullPath {
41 public function __construct(public int $number_of_data)
42 {
43 }
44 };
45 }
46
47 protected function getReader(): Reader
48 {
49 $nav = new class () extends NullNavigatorFactory {
50 public function navigator(
52 ElementInterface $start_element
54 return new class ($path->number_of_data) extends NullNavigator {
55 public function __construct(protected int $number_of_data)
56 {
57 }
58
59 protected function getElement(string $value): ElementInterface
60 {
61 return new class ($value) extends NullElement {
62 public function __construct(protected string $value)
63 {
64 }
65
66 public function getData(): DataInterface
67 {
68 return new class ($this->value) extends NullData {
69 public function __construct(protected string $value)
70 {
71 }
72
73 public function value(): string
74 {
75 return $this->value;
76 }
77 };
78 }
79 };
80 }
81
82 public function elementsAtFinalStep(): \Generator
83 {
84 for ($i = 0; $i < $this->number_of_data; $i++) {
85 yield $this->getElement((string) $i);
86 }
87 }
88 };
89 }
90 };
91
92 return new Reader($nav, new NullSet());
93 }
94
95 public function testAllData(): void
96 {
97 $reader = $this->getReader();
98
99 $this->assertSame(
100 3,
101 count(iterator_to_array($reader->allData($this->getPath(3))))
102 );
103 $this->assertNull($reader->allData($this->getPath(0))->current());
104 }
105
106 public function testFirstData(): void
107 {
108 $reader = $this->getReader();
109
110 $this->assertSame(
111 '0',
112 $reader->firstData($this->getPath(1))->value()
113 );
114 $this->assertSame(
115 '0',
116 $reader->firstData($this->getPath(3))->value()
117 );
118
119 $null_data = $reader->firstData($this->getPath(0));
120 $this->assertSame(
121 '',
122 $null_data->value()
123 );
124 $this->assertSame(
126 $null_data->type()
127 );
128 }
129}
__construct(NavigatorFactoryInterface $navigator_factory, SetInterface $set)
Definition: Reader.php:34
$path
Definition: ltiservices.php:30