问题
I am really stuck with this acceptance test.
My code is this
$I->click('Submit');
$I->see('Client Added');
$I->seeInDatabase('customers',[
'afm'=>'111'
]);
Everything passes until the line with "seeInDatabase". Log gives me this error "ALERT: No matching records found Failed asserting that '0' is greater than 0.".
I checked the database settings
modules:
config:
Db:
dsn: 'mysql:host=localhost;dbname=dbtesting'
user: 'test'
password: 'test'
dump: app/tests/_data/dump.sql
populate: true
cleanup: true
Seems fine to me. I double checked with seeInDatabase() with a row that I know its there and yeah, Its working just fine. ( not a PDO issue or anything like that then)
So I forced the creation in my controller after the "POST" of the form just to make sure
public function store(){
\Customer::create(['afm'=>111]);
return \Redirect::route('customers.index')->with('successMsg',Client Added');
}
Again, I couldn't verify this new row. Any idea how to solve this?
//// UPDATE /////
When I am replacing Eloquent Insert with vanilla PDO code, everything is ok. How to fix this? (Full info here )
回答1:
I just hit the same issue and apparently we have "seeRecord" helper method available in Laravel4 module to check records. Works like a charm.
$I->seeRecord('customers', ['afm' => '111']);
回答2:
According the documentation
cleanup: true - all db queries will be run in transaction, which will be rolled back at the end of test.
So normally something like this should work (functional.suite.yml)
class_name: TestGuy
modules:
enabled: [Filesystem, TestHelper, Laravel4, Db]
config:
Laravel4:
cleanup:false
But in my case didn't solve anything. So I forced it by altering line 59 in /Module/Laravel4.php
cleanup = true
TO
cleanup = false
And finally, I have a fix for this issue, although its not the ideal because of composer updates.
来源:https://stackoverflow.com/questions/22492531/codeception-seeindatabase-doesnt-work-for-me