ILIAS  release_7 Revision v7.30-3-g800a261c036
UpdateCommandTest.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 UpdateCommandTest extends TestCase
14{
15 public function testBasicFunctionality()
16 {
17 $this->basicFunctionality(false);
18 }
19
21 {
22 $this->basicFunctionality(true);
23 }
24 public function basicFunctionality(bool $is_applicable) : void
25 {
26 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
27
28 $agent = $this->createMock(Setup\AgentCollection::class);
29 $config_reader = $this->createMock(Setup\CLI\ConfigReader::class);
30 $agent_finder = $this->createMock(Setup\AgentFinder::class);
31 $command = new Setup\CLI\UpdateCommand($agent_finder, $config_reader, []);
32
33 $tester = new CommandTester($command);
34
35 $config = $this->createMock(Setup\ConfigCollection::class);
36 $config_file = "config_file";
37 $config_file_content = ["config_file"];
38
39 $objective = $this->createMock(Setup\Objective::class);
40 $env = $this->createMock(Setup\Environment::class);
41
42 $config_reader
43 ->expects($this->once())
44 ->method("readConfigFile")
45 ->with($config_file)
46 ->willReturn($config_file_content);
47
48 $agent_finder
49 ->expects($this->once())
50 ->method("getAgents")
51 ->with()
52 ->willReturn($agent);
53
54 $agent
55 ->expects($this->once())
56 ->method("hasConfig")
57 ->willReturn(true);
58
59 $agent
60 ->expects($this->once())
61 ->method("getArrayToConfigTransformation")
62 ->with()
63 ->willReturn($refinery->custom()->transformation(function ($v) use ($config_file_content, $config) {
64 $this->assertEquals($v, $config_file_content);
65 return $config;
66 }));
67
68 $agent
69 ->expects($this->never())
70 ->method("getInstallObjective")
71 ->with($config)
72 ->willReturn(new Setup\Objective\NullObjective());
73
74 $agent
75 ->expects($this->never())
76 ->method("getBuildArtifactObjective")
77 ->with()
78 ->willReturn(new Setup\Objective\NullObjective());
79
80 $agent
81 ->expects($this->once())
82 ->method("getUpdateObjective")
83 ->with($config)
84 ->willReturn($objective);
85
86 $objective
87 ->expects($this->once())
88 ->method("getPreconditions")
89 ->willReturn([]);
90
91 $expects = $this->never();
92 $return = false;
93
94 if ($is_applicable) {
95 $expects = $this->once();
96 $return = true;
97 }
98
99 $objective
100 ->expects($expects)
101 ->method("achieve")
102 ->willReturn($env);
103
104 $objective
105 ->expects($this->once())
106 ->method("isApplicable")
107 ->willReturn($return);
108
109 $tester->execute([
110 "config" => $config_file
111 ]);
112 }
113}
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...
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...