ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ConfigReaderTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21namespace ILIAS\Tests\Setup\CLI;
22
23use ILIAS\Setup;
24use PHPUnit\Framework\TestCase;
25use Seld\JsonLint\JsonParser;
26
27class ConfigReaderTest extends TestCase
28{
29 public function testReadConfigFile(): void
30 {
31 $filename = tempnam("/tmp", "ILIAS");
32 $expected = [
33 "some" => [
34 "nested" => "config"
35 ]
36 ];
37 file_put_contents($filename, json_encode($expected));
38 $obj = new Setup\CLI\ConfigReader(new JsonParser());
39
40 $config = $obj->readConfigFile($filename);
41
42 $this->assertEquals($expected, $config);
43 }
44
45 public function testBaseDir(): void
46 {
47 $filename = tempnam("/tmp", "ILIAS");
48 $expected = [
49 "some" => [
50 "nested" => "config"
51 ]
52 ];
53 file_put_contents($filename, json_encode($expected));
54
55 $obj = new Setup\CLI\ConfigReader(new JsonParser(), "/tmp");
56
57 $config = $obj->readConfigFile(basename($filename));
58
59 $this->assertEquals($expected, $config);
60 }
61
62 public function testTotalDir(): void
63 {
64 $filename = tempnam("/tmp", "ILIAS");
65 $expected = [
66 "some" => [
67 "nested" => "config"
68 ]
69 ];
70 file_put_contents($filename, json_encode($expected));
71
72 $obj = new Setup\CLI\ConfigReader(new JsonParser(), "/foo");
73
74 $config = $obj->readConfigFile($filename);
75
76 $this->assertEquals($expected, $config);
77 }
78
79 public function testApplyOverwrites(): void
80 {
81 $cr = new class (new JsonParser()) extends Setup\CLI\ConfigReader {
82 public function _applyOverwrites($j, $o)
83 {
84 return $this->applyOverwrites($j, $o);
85 }
86 };
87
88 $array = [
89 "1" => [
90 "1" => "1.1",
91 "2" => [
92 "1" => "1.2.1"
93 ],
94 ],
95 "2" => "2"
96 ];
97 $overwrites = [
98 "1.2.1" => "foo",
99 "2" => "bar"
100 ];
101 $expected = [
102 "1" => [
103 "1" => "1.1",
104 "2" => [
105 "1" => "foo"
106 ],
107 ],
108 "2" => "bar"
109 ];
110
111 $result = $cr->_applyOverwrites($array, $overwrites);
112 $this->assertEquals($expected, $result);
113 }
114
115 public function testApplyOverwritesToUnsetField(): void
116 {
117 $cr = new class (new JsonParser()) extends Setup\CLI\ConfigReader {
118 public function _applyOverwrites($j, $o)
119 {
120 return $this->applyOverwrites($j, $o);
121 }
122 };
123
124 $array = [
125 ];
126 $overwrites = [
127 "1.1.1" => "foo",
128 ];
129 $expected = [
130 "1" => [
131 "1" => [
132 "1" => "foo"
133 ],
134 ]
135 ];
136
137 $result = $cr->_applyOverwrites($array, $overwrites);
138 $this->assertEquals($expected, $result);
139 }
140}
$filename
Definition: buildRTE.php:78
Read a json-formatted config from a file and overwrite some fields.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...