ILIAS  release_7 Revision v7.30-3-g800a261c036
InstallCommandTest.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;
9use Symfony\Component\Console\Tester\CommandTester;
10use ILIAS\Refinery\Factory as Refinery;
11use ILIAS\Data\Factory as DataFactory;
12
13class InstallCommandTest extends TestCase
14{
15 public function testBasicFunctionality()
16 {
17 $this->basicFunctionality(false);
18 }
19
21 {
22 $this->basicFunctionality(true);
23 }
24
25 public function basicFunctionality(bool $is_applicable) : void
26 {
27 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
28
29 $agent = $this->createMock(Setup\AgentCollection::class);
30 $config_reader = $this->createMock(Setup\CLI\ConfigReader::class);
31 $agent_finder = $this->createMock(Setup\AgentFinder::class);
32 $command = new Setup\CLI\InstallCommand($agent_finder, $config_reader, []);
33
34 $tester = new CommandTester($command);
35
36 $config = $this->createMock(Setup\ConfigCollection::class);
37 $config_file = "config_file";
38 $config_file_content = ["config_file"];
39
40 $objective = $this->createMock(Setup\Objective::class);
41 $env = $this->createMock(Setup\Environment::class);
42
43 $config_overwrites = [
44 "a.b.c" => "foo",
45 "d.e" => "bar",
46 ];
47
48 $agent
49 ->expects($this->once())
50 ->method("hasConfig")
51 ->willReturn(true);
52
53 $config_reader
54 ->expects($this->once())
55 ->method("readConfigFile")
56 ->with($config_file, $config_overwrites)
57 ->willReturn($config_file_content);
58
60 ->expects($this->once())
61 ->method("getConfig")
62 ->with("common")
63 ->willReturn(new class implements Setup\Config {
64 public function getClientId() : string
65 {
66 return "client_id";
67 }
68 });
69
70 $agent_finder
71 ->expects($this->once())
72 ->method("getAgents")
73 ->with()
74 ->willReturn($agent);
75
76 $agent
77 ->expects($this->once())
78 ->method("getArrayToConfigTransformation")
79 ->with()
80 ->willReturn($refinery->custom()->transformation(function ($v) use ($config_file_content, $config) {
81 $this->assertEquals($v, $config_file_content);
82 return $config;
83 }));
84
85 $agent
86 ->expects($this->once())
87 ->method("getInstallObjective")
88 ->with($config)
89 ->willReturn($objective);
90
91 $agent
92 ->expects($this->never())
93 ->method("getBuildArtifactObjective")
94 ->with()
95 ->willReturn(new Setup\Objective\NullObjective());
96
97 $agent
98 ->expects($this->once())
99 ->method("getUpdateObjective")
100 ->with()
101 ->willReturn(new Setup\Objective\NullObjective());
102
103 $objective
104 ->expects($this->once())
105 ->method("getPreconditions")
106 ->willReturn([]);
107
108 $expects = $this->never();
109 $return = false;
110
111 if ($is_applicable) {
112 $expects = $this->once();
113 $return = true;
114 }
115
116 $objective
117 ->expects($expects)
118 ->method("achieve")
119 ->willReturn($env);
120
121 $objective
122 ->expects($this->once())
123 ->method("isApplicable")
124 ->willReturn($return);
125
126 $tester->execute([
127 "config" => $config_file,
128 "--config" => ["a.b.c=foo", "d.e=bar"]
129 ]);
130 }
131
132 public function testPluginInstallation() : void
133 {
134 $agent = $this->createMock(Setup\AgentCollection::class);
135 $config_reader = $this->createMock(Setup\CLI\ConfigReader::class);
136 $agent_finder = $this->createMock(Setup\AgentFinder::class);
137 $command = new Setup\CLI\InstallCommand($agent_finder, $config_reader, []);
138
139 $tester = new CommandTester($command);
140
141 $objective = $this->createMock(Setup\Objective::class);
142 $env = $this->createMock(Setup\Environment::class);
143
144 $agent
145 ->expects($this->once())
146 ->method("hasConfig")
147 ->willReturn(false);
148
149 $agent_finder
150 ->expects($this->once())
151 ->method("getPluginAgent")
152 ->with("test")
153 ->willReturn($agent);
154
155 $agent
156 ->expects($this->once())
157 ->method("getInstallObjective")
158 ->with(null)
159 ->willReturn($objective);
160
161 $agent
162 ->expects($this->once())
163 ->method("getUpdateObjective")
164 ->with()
165 ->willReturn(new Setup\Objective\NullObjective());
166
167 $objective
168 ->expects($this->once())
169 ->method("getPreconditions")
170 ->willReturn([]);
171
172 $objective
173 ->expects($this->once())
174 ->method("achieve")
175 ->willReturn($env);
176
177 $objective
178 ->expects($this->once())
179 ->method("isApplicable")
180 ->willReturn(true);
181
182 $tester->execute([
183 "--plugin" => "test"
184 ]);
185 }
186}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
A non-objective, nothing to do to achieve it...
getClientId()
A configuration for the setup.
Definition: Config.php:11
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:15
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...