ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
HasAgentTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Tests\Setup\CLI;
22 
28 
29 class HasAgentTest extends TestCase
30 {
32  protected $has_agent;
33 
34  public function setUp(): void
35  {
36  $this->agent_finder = $this->createMock(AgentFinder::class);
37  $this->has_agent = new class ($this->agent_finder) {
38  use HasAgent;
39  public function __construct($af)
40  {
41  $this->agent_finder = $af;
42  }
43 
44  public function _getRelevantAgent($i)
45  {
46  return $this->getRelevantAgent($i);
47  }
48  };
49  }
50 
51  public function testGetRelevantAgentWithoutOption(): void
52  {
53  $ii = $this->createMock(InputInterface::class);
54  $ac = $this->createMock(AgentCollection::class);
55 
56  $ii
57  ->method("getOption")
58  ->willReturn(null);
59 
60  $this->agent_finder
61  ->expects($this->once())
62  ->method("getAgents")
63  ->with()
64  ->willReturn($ac);
65 
66  $agent = $this->has_agent->_getRelevantAgent($ii);
67 
68  $this->assertEquals($ac, $agent);
69  }
70 
72  {
73  $ii = $this->createMock(InputInterface::class);
74  $ac = $this->createMock(AgentCollection::class);
75 
76  $ii
77  ->method("hasOption")
78  ->willReturn(true);
79 
80  $ii
81  ->method("getOption")
82  ->will($this->returnValueMap([
83  ["no-legacy-plugins", true],
84  ["skip-legacy-plugin", null]
85  ]));
86 
87  $this->agent_finder
88  ->expects($this->once())
89  ->method("getComponentAgents")
90  ->with()
91  ->willReturn($ac);
92 
93  $agent = $this->has_agent->_getRelevantAgent($ii);
94 
95  $this->assertEquals($ac, $agent);
96  }
97 
99  {
100  $ii = $this->createMock(InputInterface::class);
101  $ac = $this->createMock(AgentCollection::class);
102 
103 
104  $ii
105  ->method("hasOption")
106  ->willReturn(true);
107 
108  $ii
109  ->method("getOption")
110  ->will($this->returnValueMap([
111  ["no-legacy-plugins", null],
112  ["legacy-plugin", "foobar"],
113  ["skip-legacy-plugin", null]
114  ]));
115 
116  $this->agent_finder
117  ->expects($this->once())
118  ->method("getPluginAgent")
119  ->with("foobar")
120  ->willReturn($ac);
121 
122  $agent = $this->has_agent->_getRelevantAgent($ii);
123 
124  $this->assertEquals($ac, $agent);
125  }
126 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getRelevantAgent(InputInterface $input)
Definition: HasAgent.php:40
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76
trait HasAgent
Add this to an Command that has an agent.
Definition: HasAgent.php:30