ILIAS  release_7 Revision v7.30-3-g800a261c036
ConfigReaderTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
6
8use PHPUnit\Framework\TestCase;
9
10class ConfigReaderTest extends TestCase
11{
12 public function testReadConfigFile() : void
13 {
14 $filename = tempnam("/tmp", "ILIAS");
15 $expected = [
16 "some" => [
17 "nested" => "config"
18 ]
19 ];
20 file_put_contents($filename, json_encode($expected));
21
22 $obj = new Setup\CLI\ConfigReader();
23
24 $config = $obj->readConfigFile($filename);
25
26 $this->assertEquals($expected, $config);
27 }
28
29 public function testBaseDir() : 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
39 $obj = new Setup\CLI\ConfigReader("/tmp");
40
41 $config = $obj->readConfigFile(basename($filename));
42
43 $this->assertEquals($expected, $config);
44 }
45
46 public function testTotalDir() : void
47 {
48 $filename = tempnam("/tmp", "ILIAS");
49 $expected = [
50 "some" => [
51 "nested" => "config"
52 ]
53 ];
54 file_put_contents($filename, json_encode($expected));
55
56 $obj = new Setup\CLI\ConfigReader("/foo");
57
58 $config = $obj->readConfigFile($filename);
59
60 $this->assertEquals($expected, $config);
61 }
62
63 public function testApplyOverwrites() : void
64 {
65 $cr = new class() extends Setup\CLI\ConfigReader {
66 public function _applyOverwrites($j, $o)
67 {
68 return $this->applyOverwrites($j, $o);
69 }
70 };
71
72 $array = [
73 "1" => [
74 "1" => "1.1",
75 "2" => [
76 "1" => "1.2.1"
77 ],
78 ],
79 "2" => "2"
80 ];
81 $overwrites = [
82 "1.2.1" => "foo",
83 "2" => "bar"
84 ];
85 $expected = [
86 "1" => [
87 "1" => "1.1",
88 "2" => [
89 "1" => "foo"
90 ],
91 ],
92 "2" => "bar"
93 ];
94
95 $result = $cr->_applyOverwrites($array, $overwrites);
96 $this->assertEquals($expected, $result);
97 }
98
99 public function testApplyOverwritesToUnsetField() : void
100 {
101 $cr = new class() extends Setup\CLI\ConfigReader {
102 public function _applyOverwrites($j, $o)
103 {
104 return $this->applyOverwrites($j, $o);
105 }
106 };
107
108 $array = [
109 ];
110 $overwrites = [
111 "1.1.1" => "foo",
112 ];
113 $expected = [
114 "1" => [
115 "1" => [
116 "1" => "foo"
117 ],
118 ]
119 ];
120
121 $result = $cr->_applyOverwrites($array, $overwrites);
122 $this->assertEquals($expected, $result);
123 }
124}
$result
$filename
Definition: buildRTE.php:89
An exception for terminatinating execution or to throw for unit testing.
Read a json-formatted config from a file and overwrite some fields.
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...