ILIAS  release_8 Revision v8.24
HasAgentTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21namespace ILIAS\Tests\Setup\CLI;
22
26use PHPUnit\Framework\TestCase;
27use Symfony\Component\Console\Input\InputInterface;
28
29class HasAgentTest extends TestCase
30{
31 public function setUp(): void
32 {
33 $this->agent_finder = $this->createMock(AgentFinder::class);
34 $this->has_agent = new class ($this->agent_finder) {
35 use HasAgent;
36 public function __construct($af)
37 {
38 $this->agent_finder = $af;
39 }
40
41 public function _getRelevantAgent($i)
42 {
43 return $this->getRelevantAgent($i);
44 }
45 };
46 }
47
48 public function testGetRelevantAgentWithoutOption(): void
49 {
50 $ii = $this->createMock(InputInterface::class);
51 $ac = $this->createMock(AgentCollection::class);
52
53 $ii
54 ->method("getOption")
55 ->willReturn(null);
56
57 $this->agent_finder
58 ->expects($this->once())
59 ->method("getAgents")
60 ->with()
61 ->willReturn($ac);
62
63 $agent = $this->has_agent->_getRelevantAgent($ii);
64
65 $this->assertEquals($ac, $agent);
66 }
67
69 {
70 $ii = $this->createMock(InputInterface::class);
71 $ac = $this->createMock(AgentCollection::class);
72
73 $ii
74 ->method("hasOption")
75 ->willReturn(true);
76
77 $ii
78 ->method("getOption")
79 ->will($this->returnValueMap([
80 ["no-plugins", true],
81 ["skip", null]
82 ]));
83
84 $this->agent_finder
85 ->expects($this->once())
86 ->method("getCoreAgents")
87 ->with()
88 ->willReturn($ac);
89
90 $agent = $this->has_agent->_getRelevantAgent($ii);
91
92 $this->assertEquals($ac, $agent);
93 }
94
96 {
97 $ii = $this->createMock(InputInterface::class);
98 $ac = $this->createMock(AgentCollection::class);
99
100
101 $ii
102 ->method("hasOption")
103 ->willReturn(true);
104
105 $ii
106 ->method("getOption")
107 ->will($this->returnValueMap([
108 ["no-plugins", null],
109 ["plugin", "foobar"],
110 ["skip", null]
111 ]));
112
113 $this->agent_finder
114 ->expects($this->once())
115 ->method("getPluginAgent")
116 ->with("foobar")
117 ->willReturn($ac);
118
119 $agent = $this->has_agent->_getRelevantAgent($ii);
120
121 $this->assertEquals($ac, $agent);
122 }
123}
An agent that is just a collection of some other agents.
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:62
$i
Definition: metadata.php:41
trait HasAgent
Add this to an Command that has an agent.
Definition: HasAgent.php:30
getRelevantAgent(InputInterface $input)
Definition: HasAgent.php:40
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...