When you say 'it fails' what do you mean?
Jan 4, 2018
5
Level 33
Tests fails with sqlite but works with mysql?
Hi,
I've got a method that looks like this:
protected function saveDescriptions($descriptionsShort, $descriptionsLong, $productId)
{
/*
* Check if product description short already exists
* otherwise create one.
*/
foreach ($descriptionsShort as $description) {
if(! ProductDescriptionModel::where(
'description', $description
)->where(
'product_id', $productId
)->where('type', 'short')->first()) {
/*
* If product description short does not exists create one.
*/
ProductDescriptionModel::create([
'product_id' => $productId,
'description' => $description,
'type' => 'short'
]);
}
}
This is my test:
/** @test */
public function it_creates_product_descriptions_short_correctly()
{
$this->assertDatabaseMissing('product_description', [
"product_id" => 1,
"description" => "Short description...",
"type" => "short"
]);
$this->assertDatabaseMissing('product_description', [
"product_id" => 1,
"description" => "test",
"type" => "short"
]);
$this->saveProducts(__dir__ . '/xml/Descriptions.xml');
$this->assertDatabaseHas('product_description', [
"product_id" => 1,
"description" => "Short description...",
"type" => "short"
]);
$this->assertDatabaseHas('product_description', [
"product_id" => 1,
"description" => "test",
"type" => "short"
]);
}
With this settings in my phpunit.xml file it fails:
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="sqlite" />
<env name="DB_DATABASE" value=":memory:" />
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
but with this it works:
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_DEFAULT" value="sqlite_testing" />
</php>
What could be the problem? Thanks!
Level 67
It looks like the problem is you're searching for "test" when it's stored as "Test" (sqlite is case sensitive by default). So just change your search values in the queries to match those that are actually in the database.
1 like
Please or to participate in this conversation.