/
EventFired.php
55 lines (49 loc) · 1.15 KB
/
EventFired.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Cake\TestSuite\Constraint;
use Cake\Event\EventManager;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Constraint\Constraint;
/**
* EventFired constraint
*/
class EventFired extends Constraint
{
/**
* Array of fired events
*
* @var EventManager
*/
protected $_eventManager;
/**
* Constructor
*
* @param EventManager $eventManager Event manager to check
*/
public function __construct($eventManager)
{
parent::__construct();
$this->_eventManager = $eventManager;
if ($this->_eventManager->getEventList() === null) {
throw new AssertionFailedError('The event manager you are asserting against is not configured to track events.');
}
}
/**
* Checks if event is in fired array
*
* @param mixed $other Constraint check
* @return bool
*/
public function matches($other)
{
return $this->_eventManager->getEventList()->hasEvent($other);
}
/**
* Assertion message string
*
* @return string
*/
public function toString()
{
return 'was fired';
}
}