Crud\TestSuite\Traits\CrudTestTrait::assertEvents PHP Method

assertEvents() public method

The $expected list do not need to prefix events with Crud. - this is done automatically before comparison
public assertEvents ( array $expected, array | null $actual = null ) : void
$expected array An array of CRUD events we expected to be fired
$actual array | null Can be an Event class, Crud subject or array with event names
return void
    public function assertEvents(array $expected, $actual = null)
    {
        if ($actual === null) {
            $actual = $this->_subject;
        }
        if ($actual instanceof Event) {
            $actual = $actual->subject->getEvents();
        }
        if ($actual instanceof Subject) {
            $actual = $actual->getEvents();
        }
        if (empty($actual)) {
            throw new Exception('assertEvents: Expected actual to be not-empty');
        }
        if (!is_array($actual)) {
            throw new Exception('assertEvents: Expected actual to be an array');
        }
        foreach ($expected as &$key) {
            if (false !== strpos($key, '.')) {
                continue;
            }
            $key = 'Crud.' . $key;
        }
        $this->assertEquals($expected, $actual, 'Not all expected events was fired');
    }