2016-01-17 17 views
1

我正在使用codeception進行測試laravel 5.2
這裏是我的codeception.yml文件:在codeception功能測試中,請參閱inDatabase不能從laravel工作

actor: Tester 
paths: 
    tests: tests_codecept 
    log: tests_codecept/_output 
    data: tests_codecept/_data 
    support: tests_codecept/_support 
    envs: tests_codecept/_envs 
settings: 
    bootstrap: _bootstrap.php 
    colors: false 
    memory_limit: 1024M 
extensions: 
    enabled: 
     - Codeception\Extension\RunFailed 
modules: 
    config: 
     Db: 
      dsn: 'mysql:host=localhost;dbname=kartice_test' 
      user: '*******' 
      password: '*******' 
      dump: tests_codecept/_data/dump.sql 
      populate: true 
      cleanup: true 
      reconnect: true 

這裏是functional.suite.yml文件:

class_name: FunctionalTester 
modules: 
    enabled: 
     # add framework module here 
     - \Helper\Functional 
     - Asserts 
     - Laravel5: 
      environment_file: .env.testing 
     - Db 

這裏是我的test method

public function provera_dodavanja_novog_klijenta(FunctionalTester $I) 
{ 

    $this->authenticate($I); 

    $I->amOnPage('/kancelarija/komitenti/create'); 
    $I->see('Kreiranje novog komitenta'); 
    $I->fillField('input[name=komitent_code]', 'kom1'); 
    $I->fillField('input[name=komitent_name]', 'Komitent 1'); 
    $I->click('btnSave'); 
    $I->seeInDatabase('komitenti', ['code' => 'kom1', 'name' => 'Komitent 1']); 
    $I->see('Komitent Komitent 1 je uspešno kreiran.'); 

} 

運行功能測試失敗消息:

Step I see in database "komitenti",{"code":"kom1","name":"Komitent 1"} 
Fail No matching records found for criteria {"code":"kom1","name":"Komitent 1"} in table komitenti 
Failed asserting that 0 is greater than 0. 

我做錯了什麼?

我看過問題Codeception seeInDatabase() doesn't work for me但這並沒有幫助我。

回答

3

您應該使用seeRecord而不是seeInDatabase。我不知道爲什麼,但對我來說,第一個是在工作,第二個是 - 而不是。

+0

你是對的!區別在哪裏? – gandra404

+0

很難說,但在文檔中沒有任何信息表明它無法在Laravel中工作。一年前我浪費了很多時間,解決這個問題,並簡單地改用'seeRecord'方法 –

0

我使用gulp tdd,當測試表單遇到這個錯誤。 請檢查:

  1. 您添加到了請求

    <YourFormRequest>use App\Http\Requests\<YourFormRequest>;

  2. 確保您的表型是質量分配

    protected $fillable = ['tableField1', 'tableField2']

相關問題