ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TriggererTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2018 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 require_once("libs/composer/vendor/autoload.php");
6 
9 
11 {
13 
14  public function _appendTriggeredSignal(Component\Signal $signal, $event)
15  {
16  return $this->appendTriggeredSignal($signal, $event);
17  }
18 
19  public function _withTriggeredSignal(Component\Signal $signal, $event)
20  {
21  return $this->withTriggeredSignal($signal, $event);
22  }
23 
24  public function _setTriggeredSignal(Component\Signal $signal, $event)
25  {
26  return $this->setTriggeredSignal($signal, $event);
27  }
28 }
29 
34 {
35  public function setUp()
36  {
37  $this->mock = new TriggererMock();
38  }
39 
40  protected $signal_mock_counter = 0;
41  protected function getSignalMock()
42  {
43  $this->signal_mock_counter++;
44  return $this
45  ->getMockBuilder(Component\Signal::class)
46  ->disableOriginalClone()
47  ->disableArgumentCloning()
48  ->disallowMockingUnknownTypes()
49  ->setMockClassName("Signal_{$this->signal_mock_counter}")
50  ->getMock();
51  }
52 
53  public function testStartEmpty()
54  {
55  $this->assertEquals([], $this->mock->getTriggeredSignals());
56  }
57 
59  {
60  $signal = $this->getSignalMock();
61 
62  $mock = $this->mock->_appendTriggeredSignal($signal, "some_event");
63  $this->assertNotSame($mock, $this->mock);
64  }
65 
66  public function testAppendTriggeredSignal()
67  {
68  $signal1 = $this->getSignalMock();
69  $signal2 = $this->getSignalMock();
70  $signal3 = $this->getSignalMock();
71 
72  $mock = $this->mock->_appendTriggeredSignal($signal1, "some_event");
73  $mock2 = $this->mock
74  ->_appendTriggeredSignal($signal2, "some_event")
75  ->_appendTriggeredSignal($signal3, "some_event");
76 
77  $this->assertEquals([], $this->mock->getTriggeredSignals());
78  $this->assertEquals([new TriggeredSignal($signal1, "some_event")], $mock->getTriggeredSignals());
79  $this->assertEquals([new TriggeredSignal($signal2, "some_event"), new TriggeredSignal($signal3, "some_event")], $mock2->getTriggeredSignals());
80  }
81 
83  {
84  $signal = $this->getSignalMock();
85 
86  $mock = $this->mock->_withTriggeredSignal($signal, "some_event");
87 
88  $this->assertNotSame($mock, $this->mock);
89  }
90 
91  public function testWithTriggeredSignal()
92  {
93  $signal1 = $this->getSignalMock();
94  $signal2 = $this->getSignalMock();
95 
96  $mock = $this->mock->_withTriggeredSignal($signal1, "some_event");
97  $mock2 = $mock->_withTriggeredSignal($signal2, "some_event");
98 
99  $this->assertEquals([new TriggeredSignal($signal1, "some_event")], $mock->getTriggeredSignals());
100  $this->assertEquals([new TriggeredSignal($signal2, "some_event")], $mock2->getTriggeredSignals());
101  }
102 
103  public function testSetTriggeredSignal()
104  {
105  $signal1 = $this->getSignalMock();
106  $signal2 = $this->getSignalMock();
107 
108  $this->mock->_setTriggeredSignal($signal1, "some_event");
109  $this->mock->_setTriggeredSignal($signal2, "some_event");
110 
111  $this->assertEquals([new TriggeredSignal($signal2, "some_event")], $this->mock->getTriggeredSignals());
112  }
113 
115  {
116  $signal = $this->getSignalMock();
117 
118  $mock = $this->mock->withResetTriggeredSignals();
119 
120  $this->assertNotSame($mock, $this->mock);
121  }
122 
124  {
125  $signal1 = $this->getSignalMock();
126  $signal2 = $this->getSignalMock();
127 
128  $mock = $this->mock
129  ->_appendTriggeredSignal($signal1, "some_event")
130  ->_appendTriggeredSignal($signal2, "some_event")
131  ->withResetTriggeredSignals();
132 
133  $this->assertEquals([], $mock->getTriggeredSignals());
134  }
135 
137  {
138  $signals = $this->mock->getTriggeredSignalsFor("some_event");
139  $this->assertEquals([], $signals);
140  }
141 
142  public function testGetTriggeredSignals()
143  {
144  $signal1 = $this->getSignalMock();
145  $signal2 = $this->getSignalMock();
146 
147  $mock = $this->mock
148  ->_appendTriggeredSignal($signal1, "some_event")
149  ->_appendTriggeredSignal($signal2, "some_event");
150 
151  $signals = $mock->getTriggeredSignalsFor("some_event");
152 
153  $this->assertEquals([$signal1, $signal2], $signals);
154  }
155 }
_setTriggeredSignal(Component\Signal $signal, $event)
setTriggeredSignal(Component\Signal $signal, $event)
Add a triggered signal, replacing any othe signals registered on the same event.
Definition: Triggerer.php:65
appendTriggeredSignal(Component\Signal $signal, $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:31
_withTriggeredSignal(Component\Signal $signal, $event)
_appendTriggeredSignal(Component\Signal $signal, $event)
withTriggeredSignal(Component\Signal $signal, $event)
Add a triggered signal, replacing any other signals registered on the same event. ...
Definition: Triggerer.php:48