私はCodeceptionを使って私のYii2アプリケーションのための簡単なテストを書いた。実際のMySQLデータベースを使用する代わりに、私は什器を使いたいです。ここYii2 + Codeception:治具の使い方は?
コードである:/ PersonTest.php
試験:
namespace app\tests\unit\models;
use tests\fixtures;
use app\controllers;
class PersonTest extends \Codeception\Test\Unit
{
protected $tester;
public $appConfig = '@app/config/main.php';
protected function _before(){ }
protected function _after(){ }
public function _fixtures()
{
return [ 'Person' => fixtures\PersonFixture::className() ];
}
public function testUser(){
$person = Person::findOne([ "id" => 1 ]);
$userId = isset($person->id) ? $person->id : false;
$this->assertEquals(1, $userId);
}
}
テスト/器具/データ/ Person.php
return [
'person1' => [
'id' => 1,
'firstname' => 'Foo',
'lastname' => 'Bar',
],
];
テスト/フィクスチャ/Person.php
私は、テストを実行すると、私はエラーを取得namespace tests\fixtures;
use yii\test\ActiveFixture;
class PersonFixture extends ActiveFixture
{
public $modelClass = 'app\models\Person';
}
:
[エラー]クラスの備品\テストを\ PersonFixture「私は100の異なるものを試してみました
見つけましたが、私はできませんそれを働かせないでください。この単純な例が私のために働くならば、私は本当のテストを作ることができます。
yii2-codeception拡張は推奨されていません:https://github.com/yiisoft/yii2-codeception – yesnik