Fajnie jak wszystko pracuje bez błędów, gorzej jak nie chce …

Tutaj walczyłem z unit testami oraz testami systemowymi w Yii2 i … nie chce działać. Wysypuje się aż miło, a wypisuje tylko „Internal Server Error”, w końcu się udało.

Ponieważ stosuję inny układ katalogów w projekcie niż domyślny w Yii2, to Codeception nie potrafił zaimportować poprawnie plików php. Teoretycznie powinien wywalić błędem, ale „nie bo nie” ma mnie w nosie i pół dnia stracone …

Poniżej działający przykład, testu w Yii2 i Codeception, inne podejście do zastosowanie własnego loadera – spl_autoload_register().

<?php
 
use \yii\codeception\TestCase;
 
use app\models\SomeModel;
use app\ utils\SomeUtils;
 
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'debug');
 
//
// Include framework autoloader
//
require __DIR__."/../../../framework/vendor/autoload.php";
require __DIR__."/../../../framework/vendor/yiisoft/yii2/Yii.php";
 
//
// Include application files
//
require __DIR__."/../../../app/models/SomeModel.php";
require __DIR__."/../../../app/models/OtherModel.php ";
require __DIR__."/../../../app/utils/UtilClass.php";
 
class UtilClassTest extends TestCase{
 
    public $appConfig;
    
    protected function _before(){
        // SetUp test config file
        this->appConfig = __DIR__."/../../config/console.php";
    }
 
    protected function _after(){
    }
 
    public function testSomeTest(){
    
        $value = null;
        $this->assertEquals(null, $value);
        $this->assertNotEquals("true", true);
    }
 
    public function test SomeModel (){
    
        $model = SomeModel::findOne(['id' => 1]);
        $this->assertNotEquals(null, $ model);        
        $this->assertEquals($model ->id, 1);
    }
 
    public function testUtilClass(){
 
        $model = SomeModel::findOne(['id' => 1]);
        $this->assertNotEquals(null, $ model);
        $this->assertEquals($model ->id, 1);
 
        $ otherModel = OtherModel::findOne(['id' => 1]);
        $this->assertNotEquals(null, $ otherModel);
        $this->assertEquals($otherModel ->id, 1);
 
        $result= UtilClass ::processData($model, $ otherModel);
        $this->assertNotEquals(null, $ result);
        // … test code …
    }
}