Monday 15 May 2017

Moodle & PHPUnit: Capture events

Hello,

If you want to tests events in Moodle using PHPUnit, the best method is:

public function test_creationg_event() {
        $this->resetAfterTest();
        $event_sink = $this->redirectEvents();

        $course = $this->getDataGenerator()->create_course();

        $events = $event_sink->get_events();
        $event_sink->close();
        $event = $events[0];
        $this->assertInstanceOf('\core\event\course_created', $event);
}

Best regards!

No comments:

Post a Comment