ILIAS  release_7 Revision v7.30-3-g800a261c036
AchieveCommandTest.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
3/* Copyright (c) 2021 - Daniel Weise <daniel.weise@concepts-and-training.de> - Extended GPL, see 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;
12use Symfony\Component\Console\Input\InputInterface;
15
16class TestConfig implements Config
17{
18 public function getConfig(string $name)
19 {
20 return ["a" => "b"];
21 }
22
23 public function getKeys()
24 {
25 return ["a"];
26 }
27}
28
30{
31 public function readAgentConfig(Agent $agent, InputInterface $input) : ?Config
32 {
33 return new Setup\ConfigCollection(["Test" => new TestConfig()]);
34 }
35}
36
37class AchieveCommandTest extends TestCase
38{
42 protected $config_reader;
43
47 protected $agent_finder;
48
52 protected $refinery;
53
57 protected $command;
58
59 public function setUp() : void
60 {
61 $this->config_reader = $this->createMock(Setup\CLI\ConfigReader::class);
62 $this->agent_finder = $this->createMock(Setup\AgentFinder::class);
63 $this->refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
64 $this->command = new Setup\CLI\AchieveCommand($this->agent_finder, $this->config_reader, [], $this->refinery);
65 }
66
67 public function testBasicFunctionality() : void
68 {
69 $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
70
71 $agent = $this->createMock(Setup\AgentCollection::class);
72 $config_reader = $this->createMock(Setup\CLI\ConfigReader::class);
73 $agent_finder = $this->createMock(Setup\AgentFinder::class);
75
76 $tester = new CommandTester($command);
77
78 $config = $this->createMock(Setup\ConfigCollection::class);
79 $config_file = "config_file";
80 $config_file_content = ["config_file"];
81 $objective_name = "my.objective";
82
83 $objective = $this->createMock(Setup\Objective::class);
84 $env = $this->createMock(Setup\Environment::class);
85
87 ->expects($this->once())
88 ->method("readConfigFile")
89 ->with($config_file)
90 ->willReturn($config_file_content);
91
93 ->expects($this->once())
94 ->method("getAgents")
95 ->with()
96 ->willReturn($agent);
97
98 $agent
99 ->expects($this->once())
100 ->method("hasConfig")
101 ->willReturn(true);
102
103 $agent
104 ->expects($this->once())
105 ->method("getArrayToConfigTransformation")
106 ->with()
107 ->willReturn($refinery->custom()->transformation(function ($v) use ($config_file_content, $config) {
108 $this->assertEquals($v, $config_file_content);
109 return $config;
110 }));
111
112 $agent
113 ->expects($this->once())
114 ->method("getNamedObjective")
115 ->with($objective_name, $config)
116 ->willReturn($objective);
117
118 $objective
119 ->expects($this->once())
120 ->method("getPreconditions")
121 ->willReturn([]);
122
123 $objective
124 ->method("isApplicable")
125 ->willReturn(true);
126
127 $objective
128 ->expects($this->once())
129 ->method("achieve")
130 ->willReturn($env);
131
132 $tester->execute([
133 "config" => $config_file,
134 "objective" => $objective_name
135 ]);
136 }
137}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
Achieves an objective.
A collection of some configurations.
readAgentConfig(Agent $agent, InputInterface $input)
A agent is some component that performs part of the setup process.
Definition: Agent.php:14
A configuration for the setup.
Definition: Config.php:11
if($format !==null) $name
Definition: metadata.php:230
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...