ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
UpdateCommandTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 namespace ILIAS\Tests\Setup\CLI;
22 
23 use ILIAS\Setup;
28 
29 class UpdateCommandTest extends TestCase
30 {
31  public function testBasicFunctionality(): void
32  {
33  $this->basicFunctionality(false);
34  }
35 
36  public function testBasicFunctionalityAlreadyAchieved(): void
37  {
38  $this->basicFunctionality(true);
39  }
40  public function basicFunctionality(bool $is_applicable): void
41  {
42  $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
43 
44  $agent = $this->createMock(Setup\AgentCollection::class);
45  $config_reader = $this->createMock(Setup\CLI\ConfigReader::class);
46  $agent_finder = $this->createMock(Setup\AgentFinder::class);
47  $command = new Setup\CLI\UpdateCommand($agent_finder, $config_reader, []);
48 
49  $tester = new CommandTester($command);
50 
51  $config = $this->createMock(Setup\ConfigCollection::class);
52  $config_file = "config_file";
53  $config_file_content = ["config_file"];
54 
55  $objective = $this->createMock(Setup\Objective::class);
56  $env = $this->createMock(Setup\Environment::class);
57 
58  $config_reader
59  ->expects($this->once())
60  ->method("readConfigFile")
61  ->with($config_file)
62  ->willReturn($config_file_content);
63 
64  $agent_finder
65  ->expects($this->once())
66  ->method("getAgents")
67  ->with()
68  ->willReturn($agent);
69 
70  $agent
71  ->expects($this->once())
72  ->method("hasConfig")
73  ->willReturn(true);
74 
75  $agent
76  ->expects($this->once())
77  ->method("getArrayToConfigTransformation")
78  ->with()
79  ->willReturn($refinery->custom()->transformation(function ($v) use ($config_file_content, $config) {
80  $this->assertEquals($v, $config_file_content);
81  return $config;
82  }));
83 
84  $agent
85  ->expects($this->never())
86  ->method("getInstallObjective")
87  ->with($config)
88  ->willReturn(new Setup\Objective\NullObjective());
89 
90  $agent
91  ->expects($this->never())
92  ->method("getBuildArtifactObjective")
93  ->with()
94  ->willReturn(new Setup\Objective\NullObjective());
95 
96  $agent
97  ->expects($this->once())
98  ->method("getUpdateObjective")
99  ->with($config)
100  ->willReturn($objective);
101 
102  $objective
103  ->expects($this->once())
104  ->method("getPreconditions")
105  ->willReturn([]);
106 
107  $expects = $this->never();
108  $return = false;
109 
110  if ($is_applicable) {
111  $expects = $this->once();
112  $return = true;
113  }
114 
115  $objective
116  ->expects($expects)
117  ->method("achieve")
118  ->willReturn($env);
119 
120  $objective
121  ->expects($this->once())
122  ->method("isApplicable")
123  ->willReturn($return);
124 
125  $tester->execute([
126  "config" => $config_file
127  ]);
128  }
129 }
An objective is a desired state of the system that is supposed to be created by the setup...
Definition: Objective.php:30
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A non-objective, nothing to do to achieve it...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Refinery Factory $refinery