ILIAS  release_7 Revision v7.30-3-g800a261c036
HasAgentTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
6
10use PHPUnit\Framework\TestCase;
11use Symfony\Component\Console\Input\InputInterface;
12
13class HasAgentTest extends TestCase
14{
15 public function setUp() : void
16 {
17 $this->agent_finder = $this->createMock(AgentFinder::class);
18 $this->has_agent = new class($this->agent_finder) {
19 use HasAgent;
20 public function __construct($af)
21 {
22 $this->agent_finder = $af;
23 }
24
25 public function _getRelevantAgent($i)
26 {
27 return $this->getRelevantAgent($i);
28 }
29 };
30 }
31
33 {
34 $ii = $this->createMock(InputInterface::class);
35 $ac = $this->createMock(AgentCollection::class);
36
37 $ii
38 ->method("getOption")
39 ->willReturn(null);
40
41 $this->agent_finder
42 ->expects($this->once())
43 ->method("getAgents")
44 ->with()
45 ->willReturn($ac);
46
47 $agent = $this->has_agent->_getRelevantAgent($ii);
48
49 $this->assertEquals($ac, $agent);
50 }
51
53 {
54 $ii = $this->createMock(InputInterface::class);
55 $ac = $this->createMock(AgentCollection::class);
56
57 $ii
58 ->method("hasOption")
59 ->willReturn(true);
60
61 $ii
62 ->method("getOption")
63 ->will($this->returnValueMap([
64 ["no-plugins", true],
65 ["skip", null]
66 ]));
67
68 $this->agent_finder
69 ->expects($this->once())
70 ->method("getCoreAgents")
71 ->with()
72 ->willReturn($ac);
73
74 $agent = $this->has_agent->_getRelevantAgent($ii);
75
76 $this->assertEquals($ac, $agent);
77 }
78
80 {
81 $ii = $this->createMock(InputInterface::class);
82 $ac = $this->createMock(AgentCollection::class);
83
84
85 $ii
86 ->method("hasOption")
87 ->willReturn(true);
88
89 $ii
90 ->method("getOption")
91 ->will($this->returnValueMap([
92 ["no-plugins", null],
93 ["plugin", "foobar"],
94 ["skip", null]
95 ]));
96
97 $this->agent_finder
98 ->expects($this->once())
99 ->method("getPluginAgent")
100 ->with("foobar")
101 ->willReturn($ac);
102
103 $agent = $this->has_agent->_getRelevantAgent($ii);
104
105 $this->assertEquals($ac, $agent);
106 }
107}
An exception for terminatinating execution or to throw for unit testing.
An agent that is just a collection of some other agents.
__construct($a_client_id=0)
Constructor setup ILIAS global object @access public.
$i
Definition: metadata.php:24
trait HasAgent
Add this to an Command that has an agent.
Definition: HasAgent.php:15
getRelevantAgent(InputInterface $input)
Definition: HasAgent.php:28