ILIAS  trunk Revision v11.0_alpha-2658-ge2404539063
FactoryTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 namespace ILIAS\Data\Description;
26 
35 
36 class FactoryTest extends TestCase
37 {
38  protected Factory $f;
39  protected \ILIAS\Data\Text\SimpleDocumentMarkdown $md;
40 
41  public function setUp(): void
42  {
43  $this->f = new Factory();
44  $this->md = $this->createMock(\ILIAS\Data\Text\SimpleDocumentMarkdown::class);
45  }
46 
47  public function testInt(): void
48  {
49  $value = $this->f->int($this->md);
50 
51  $this->assertInstanceOf(Description::class, $value);
52  $this->assertInstanceOf(DValue::class, $value);
53  $this->assertEquals(ValueType::INT, $value->getType());
54  }
55 
56  public function testFloat(): void
57  {
58  $value = $this->f->float($this->md);
59 
60  $this->assertInstanceOf(Description::class, $value);
61  $this->assertInstanceOf(DValue::class, $value);
62  $this->assertEquals(ValueType::FLOAT, $value->getType());
63  }
64 
65  public function testString(): void
66  {
67  $value = $this->f->string($this->md);
68 
69  $this->assertInstanceOf(Description::class, $value);
70  $this->assertInstanceOf(DValue::class, $value);
71  $this->assertEquals(ValueType::STRING, $value->getType());
72  }
73 
74  public function testDateTime(): void
75  {
76  $value = $this->f->datetime($this->md);
77 
78  $this->assertInstanceOf(Description::class, $value);
79  $this->assertInstanceOf(DValue::class, $value);
80  $this->assertEquals(ValueType::DATETIME, $value->getType());
81  }
82 
83  public function testBool(): void
84  {
85  $value = $this->f->bool($this->md);
86 
87  $this->assertInstanceOf(Description::class, $value);
88  $this->assertInstanceOf(DValue::class, $value);
89  $this->assertEquals(ValueType::BOOL, $value->getType());
90  }
91 
92  public function testNull(): void
93  {
94  $value = $this->f->null($this->md);
95 
96  $this->assertInstanceOf(Description::class, $value);
97  $this->assertInstanceOf(DValue::class, $value);
98  $this->assertEquals(ValueType::NULL, $value->getType());
99  }
100 
101  public function testList(): void
102  {
103  $value = $this->f->string($this->md);
104  $list = $this->f->list($this->md, $value);
105 
106  $this->assertInstanceOf(Description::class, $list);
107  $this->assertInstanceOf(DList::class, $list);
108  $this->assertEquals($value, $list->getValueType());
109  }
110 
111  public function testMap(): void
112  {
113  $key = $this->f->string($this->md);
114  $value = $this->f->string($this->md);
115  $map = $this->f->map($this->md, $key, $value);
116 
117  $this->assertInstanceOf(Description::class, $map);
118  $this->assertInstanceOf(DMap::class, $map);
119  $this->assertEquals($key, $map->getKeyType());
120  $this->assertEquals($value, $map->getValueType());
121  }
122 
123  public function testObject(): void
124  {
125  $f1_type = $this->f->int($this->md);
126  $f1_name = "field1";
127  $f2_type = $this->f->float($this->md);
128  $f2_name = "field2";
129  $object = $this->f->object($this->md, [$f1_name => $f1_type, $f2_name => $f2_type]);
130 
131  $this->assertInstanceOf(Description::class, $object);
132  $this->assertInstanceOf(DObject::class, $object);
133  [$f1, $f2] = iterator_to_array($object->getFields());
134  $this->assertEquals($f1_name, $f1->getName());
135  $this->assertEquals($f1_type, $f1->getType());
136  $this->assertEquals($f2_name, $f2->getName());
137  $this->assertEquals($f2_type, $f2->getType());
138  }
139 }
Interface Observer Contains several chained tasks and infos about them.
ILIAS Data Text SimpleDocumentMarkdown $md
Definition: FactoryTest.php:39