mercredi 13 décembre 2017

How to test that a Yii2 application service exists and was initialized successfully

I wrote a service that I would call Yii::$app->myService. The problem is, I want to test that it was created and was initialized with required parameters. But my tests fails every time even though I can access the service from my application. Here is my code:

class MyServiceTest extends \Codeception\Test\Unit
{
    protected $app;

    protected function _before() {
        $config = require(Yii::getAlias('@app') . '/config/test.php');
        $this->app = new \yii\web\Application($config);
    }

    public function testMyServiceExists() {
        $this->assertObjectHasAttribute('myService', Yii::$app);
    }
}

Aucun commentaire:

Enregistrer un commentaire