/var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/TestSuite/Constraint
Edit: /var/www/vhosts/ihelp.ro/_OLD/vendor/cakephp/cakephp/src/TestSuite/Constraint/EventFiredWith.php (2856B)
_eventManager = $eventManager;
$this->_dataKey = $dataKey;
$this->_dataValue = $dataValue;
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
* @throws \PHPUnit\Framework\AssertionFailedError
*/
public function matches($other): bool
{
$firedEvents = [];
$list = $this->_eventManager->getEventList();
if ($list !== null) {
$totalEvents = count($list);
for ($e = 0; $e < $totalEvents; $e++) {
$firedEvents[] = $list[$e];
}
}
$eventGroup = collection($firedEvents)
->groupBy(function (EventInterface $event): string {
return $event->getName();
})
->toArray();
if (!array_key_exists($other, $eventGroup)) {
return false;
}
/** @var \Cake\Event\EventInterface[] $events */
$events = $eventGroup[$other];
if (count($events) > 1) {
throw new AssertionFailedError(sprintf(
'Event "%s" was fired %d times, cannot make data assertion',
$other,
count($events)
));
}
$event = $events[0];
if (array_key_exists($this->_dataKey, (array)$event->getData()) === false) {
return false;
}
return $event->getData($this->_dataKey) === $this->_dataValue;
}
/**
* Assertion message string
*
* @return string
*/
public function toString(): string
{
return 'was fired with ' . $this->_dataKey . ' matching ' . (string)$this->_dataValue;
}
}