cjwind / codeception-yii2-event-tester
Codeception module for test yii2 event.
v0.1.2
2019-04-15 14:19 UTC
Requires (Dev)
- phpunit/phpunit: ^6.5
- yiisoft/yii2: ^2.0
This package is auto-updated.
Last update: 2025-03-27 21:44:57 UTC
README
Codeception module which test whether yii2 event is triggered.
Installation
$ composer require cjwind/codeception-yii2-event-tester
Usage
Configure
Enable module in suite configuration. For example, enable module in unit.suite.yml
:
class_name: UnitTester modules: enabled: - Asserts - Yii2: part: [orm, email, fixtures] - cjwind\Yii2EventTester\Yii2EventTester
Use in test
namespace tests\unit\models; use app\models\EventTestedClass; class EventTestedClassTest extends \Codeception\Test\Unit { /** * @var \UnitTester */ protected $tester; public function testEventTrigger() { $obj = new EventTestedClass; $this->tester->assertEventTriggered($obj, EventTestedClass::EVENT_FOO, function() use ($obj) { $obj->bar(); // Function should trigger event }); $this->tester->assertEventTriggered(EventTestedClass::class, EventTestedClass::EVENT_BAR, function() { // Do sth. should trigger EventTestedClass::EVENT_BAR }); } }
Class-level Event
Because object's trigger() also invokes class-level handler, trigger assertion of class-level event will pass when the event is triggered by an object.
License
MIT