ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
HasAgentTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 namespace ILIAS\Tests\Setup\CLI;
22 
28 
29 class 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 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getRelevantAgent(InputInterface $input)
Definition: HasAgent.php:40
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:62
trait HasAgent
Add this to an Command that has an agent.
Definition: HasAgent.php:30
$i
Definition: metadata.php:41