PHP code example of cjwind / codeception-yii2-event-tester

1. Go to this page and download the library: Download cjwind/codeception-yii2-event-tester library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cjwind / codeception-yii2-event-tester example snippets


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
        });
    }
}