ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 Symfony\Component\Console\Tester\CommandTester;
9use ILIAS\Refinery\Factory as Refinery;
10use ILIAS\Data\Factory as DataFactory;
11
12class ConfigReaderTest extends \PHPUnit\Framework\TestCase
13{
14 public function testReadConfigFile()
15 {
16 $filename = tempnam("/tmp", "ILIAS");
17 $expected = [
18 "some" => [
19 "nested" => "config"
20 ]
21 ];
22 file_put_contents($filename, json_encode($expected));
23
24 $obj = new Setup\CLI\ConfigReader();
25
26 $config = $obj->readConfigFile($filename);
27
28 $this->assertEquals($expected, $config);
29 }
30
31 public function testBaseDir()
32 {
33 $filename = tempnam("/tmp", "ILIAS");
34 $expected = [
35 "some" => [
36 "nested" => "config"
37 ]
38 ];
39 file_put_contents($filename, json_encode($expected));
40
41 $obj = new Setup\CLI\ConfigReader("/tmp");
42
43 $config = $obj->readConfigFile(basename($filename));
44
45 $this->assertEquals($expected, $config);
46 }
47
48 public function testTotalDir()
49 {
50 $filename = tempnam("/tmp", "ILIAS");
51 $expected = [
52 "some" => [
53 "nested" => "config"
54 ]
55 ];
56 file_put_contents($filename, json_encode($expected));
57
58 $obj = new Setup\CLI\ConfigReader("/foo");
59
60 $config = $obj->readConfigFile($filename);
61
62 $this->assertEquals($expected, $config);
63 }
64
65 public function testApplyOverwrites()
66 {
67 $cr = new class() extends Setup\CLI\ConfigReader {
68 public function _applyOverwrites($j, $o)
69 {
70 return $this->applyOverwrites($j, $o);
71 }
72 };
73
74 $array = [
75 "1" => [
76 "1" => "1.1",
77 "2" => [
78 "1" => "1.2.1"
79 ],
80 ],
81 "2" => "2"
82 ];
83 $overwrites = [
84 "1.2.1" => "foo",
85 "2" => "bar"
86 ];
87 $expected = [
88 "1" => [
89 "1" => "1.1",
90 "2" => [
91 "1" => "foo"
92 ],
93 ],
94 "2" => "bar"
95 ];
96
97 $result = $cr->_applyOverwrites($array, $overwrites);
98 $this->assertEquals($expected, $result);
99 }
100}
$result
$filename
Definition: buildRTE.php:89
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
Read a json-formatted config from a file and overwrite some fields.
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68