c:\basic>composer global require "codeception/codeception" c:\basic>composer global require "codeception/specify" c:\basic>composer global require "codeception/verify"
c:\basic>composer global status
export PATH = $PATH:~/.composer/vendor/bin
C:\basic\tests>codeception/bin/yii migrate
資料庫組態可以在這裡找到:tests/codeception/config/config.php.
C:\basic\tests>codecept build
fixtures 的主要目的是建立環境處於未知狀態,這樣測試就可以按照預期的方式執行。 Yii提供一個接近固定的框架。在Yii fixture框架中的一個關鍵概念是 fixture 物件。它代表了測試環境的特定方面。fixture 物件是 yii\test\Fixture 類的一個範例。
<?php namespace app\tests\codeception\fixtures; use yii\test\ActiveFixture; class ExampleFixture extends ActiveFixture { public $modelClass = 'app/models/MyUser'; } ?>
<?php namespace tests\codeception\unit\models; use app\models\MyUser; use yii\codeception\TestCase; class ExampleTest extends TestCase { public function testCreateMyUser() { $m = new MyUser(); $m->name = "myuser"; $m->email = "[email protected]"; $this->assertTrue($m->save()); } public function testUpdateMyUser() { $m = new MyUser(); $m->name = "myuser2"; $m->email = "[email protected]"; $this->assertTrue($m->save()); $this->assertEquals("myuser2", $m->name); } public function testDeleteMyUser() { $m = MyUser::findOne(['name' => 'myuser2']); $this->assertNotNull($m); MyUser::deleteAll(['name' => $m->name]); $m = MyUser::findOne(['name' => 'myuser2']); $this->assertNull($m); } } ?>
C:\basic\tests>codecept run unit models/ExampleTest
c:\basic\tests>codecept generate:cept functional AboutPageCept
<?php $I = new FunctionalTester($scenario); $I->wantTo('perform actions and see result'); $I->amOnPage('site/about'); $I->see('about'); $I->dontSee('apple'); ?>
run functional AboutPageCept