ILIAS  trunk Revision v11.0_alpha-1831-g8615d53dadb
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\Tests\Setup\CLI\AchieveCommandTest Class Reference
+ Inheritance diagram for ILIAS\Tests\Setup\CLI\AchieveCommandTest:
+ Collaboration diagram for ILIAS\Tests\Setup\CLI\AchieveCommandTest:

Public Member Functions

 setUp ()
 
 testBasicFunctionality ()
 
 testAchieveObjective ()
 

Protected Attributes

 $config_reader
 
 $agent_finder
 
 $refinery
 
 $command
 

Detailed Description

Definition at line 63 of file AchieveCommandTest.php.

Member Function Documentation

◆ setUp()

ILIAS\Tests\Setup\CLI\AchieveCommandTest::setUp ( )

Definition at line 85 of file AchieveCommandTest.php.

References ILIAS\Repository\refinery().

85  : void
86  {
87  $this->config_reader = $this->createMock(Setup\CLI\ConfigReader::class);
88  $this->agent_finder = $this->createMock(Setup\AgentFinder::class);
89  $this->refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
90  $this->command = new Setup\CLI\AchieveCommand($this->agent_finder, $this->config_reader, [], $this->refinery);
91  }
+ Here is the call graph for this function:

◆ testAchieveObjective()

ILIAS\Tests\Setup\CLI\AchieveCommandTest::testAchieveObjective ( )

Definition at line 176 of file AchieveCommandTest.php.

References ILIAS\UI\examples\Layout\Page\Standard\$refinery, and null.

176  : void
177  {
178  $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
179 
180  $agent = $this->createMock(Setup\AgentCollection::class);
181  $config_reader = $this->createMock(Setup\CLI\ConfigReader::class);
182  $agent_finder = $this->createMock(Setup\AgentFinder::class);
183  $command = new Setup\CLI\AchieveCommand($agent_finder, $config_reader, [], $refinery);
184 
185  $tester = new CommandTester($command);
186 
187  $config = $this->createMock(Setup\ConfigCollection::class);
188  $config_file = "config_file";
189  $config_file_content = ["config_file"];
190  $objective_name = "my.objective";
191 
192  $objective = $this->createMock(Setup\Objective::class);
193  $env = $this->createMock(Setup\Environment::class);
194 
196  ->expects($this->once())
197  ->method("readConfigFile")
198  ->with($config_file)
199  ->willReturn($config_file_content);
200 
202  ->expects($this->once())
203  ->method("getAgents")
204  ->with()
205  ->willReturn($agent);
206 
207  $agent
208  ->expects($this->once())
209  ->method("hasConfig")
210  ->willReturn(true);
211 
212  $agent
213  ->expects($this->once())
214  ->method("getArrayToConfigTransformation")
215  ->with()
216  ->willReturn($refinery->custom()->transformation(function ($v) use ($config_file_content, $config) {
217  $this->assertEquals($v, $config_file_content);
218  return $config;
219  }));
220 
221 
222  $seen_config = null;
223  $agent
224  ->expects($this->once())
225  ->method("getNamedObjectives")
226  ->will($this->returnCallback(function ($config) use (&$seen_config, $objective) {
227  $seen_config = $config;
228  return [
229  "my.objective" => new Setup\ObjectiveConstructor(
230  "My Objective",
231  static function () use ($objective): Setup\Objective {
232  return $objective;
233  }
234  )
235  ];
236  }));
237 
238  $objective
239  ->expects($this->once())
240  ->method("getPreconditions")
241  ->willReturn([]);
242 
243  $objective
244  ->method("isApplicable")
245  ->willReturn(true);
246 
247  $objective
248  ->expects($this->once())
249  ->method("achieve")
250  ->willReturn($env);
251 
252  $tester->execute([
253  "config" => $config_file,
254  "objective" => $objective_name
255  ]);
256 
257  $this->assertSame($seen_config, $config);
258  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ testBasicFunctionality()

ILIAS\Tests\Setup\CLI\AchieveCommandTest::testBasicFunctionality ( )

Definition at line 93 of file AchieveCommandTest.php.

References ILIAS\UI\examples\Layout\Page\Standard\$refinery.

93  : void
94  {
95  $refinery = new Refinery($this->createMock(DataFactory::class), $this->createMock(\ilLanguage::class));
96 
97  $agent = $this->createMock(Setup\AgentCollection::class);
98  $config_reader = $this->createMock(Setup\CLI\ConfigReader::class);
99  $agent_finder = $this->createMock(Setup\AgentFinder::class);
100  $command = new Setup\CLI\AchieveCommand($agent_finder, $config_reader, [], $refinery);
101 
102  $tester = new CommandTester($command);
103 
104  $config = $this->createMock(Setup\ConfigCollection::class);
105  $config_file = "config_file";
106  $config_file_content = ["config_file"];
107  $objective_name = "my.objective";
108 
109  $objective = $this->createMock(Setup\Objective::class);
110  $env = $this->createMock(Setup\Environment::class);
111 
113  ->expects($this->once())
114  ->method("readConfigFile")
115  ->with($config_file)
116  ->willReturn($config_file_content);
117 
119  ->expects($this->once())
120  ->method("getAgents")
121  ->with()
122  ->willReturn($agent);
123 
124  $agent
125  ->expects($this->once())
126  ->method("hasConfig")
127  ->willReturn(true);
128 
129  $agent
130  ->expects($this->once())
131  ->method("getArrayToConfigTransformation")
132  ->with()
133  ->willReturn($refinery->custom()->transformation(function ($v) use ($config_file_content, $config) {
134  $this->assertEquals($v, $config_file_content);
135  return $config;
136  }));
137 
138  $namedObjectives = [
139  "my.objective" => new Setup\ObjectiveConstructor(
140  "My Objective",
141  static function () use ($objective): Setup\Objective {
142  return new Setup\ObjectiveCollection(
143  "My Objective",
144  false,
145  $objective
146  );
147  }
148  )
149  ];
150 
151  $agent
152  ->expects($this->once())
153  ->method("getNamedObjectives")
154  ->willReturn($namedObjectives);
155 
156  $objective
157  ->expects($this->once())
158  ->method("getPreconditions")
159  ->willReturn([]);
160 
161  $objective
162  ->method("isApplicable")
163  ->willReturn(true);
164 
165  $objective
166  ->expects($this->once())
167  ->method("achieve")
168  ->willReturn($env);
169 
170  $tester->execute([
171  "config" => $config_file,
172  "objective" => $objective_name
173  ]);
174  }

Field Documentation

◆ $agent_finder

ILIAS\Tests\Setup\CLI\AchieveCommandTest::$agent_finder
protected

Definition at line 73 of file AchieveCommandTest.php.

◆ $command

ILIAS\Tests\Setup\CLI\AchieveCommandTest::$command
protected

Definition at line 83 of file AchieveCommandTest.php.

◆ $config_reader

ILIAS\Tests\Setup\CLI\AchieveCommandTest::$config_reader
protected

Definition at line 68 of file AchieveCommandTest.php.

◆ $refinery

ILIAS\Tests\Setup\CLI\AchieveCommandTest::$refinery
protected

Definition at line 78 of file AchieveCommandTest.php.


The documentation for this class was generated from the following file: