I'm trying to test my CRUD methods, but it failing because laravel TestCase Method assertDatabaseHas() cant compare the fields that uses timestamp o Date as type because it is converted to MongoDB\BSON\UTCDateTime, is there any work arround, coz now i'm excluding the created_at and updated_at fields, but i all so have other models that uses this datatype.
Test Code:
public function testUpdate(){
$data = factory(Product::class)->create();
$data->fill(factory(Product::class)->make()->toArray());
$response = $this->put(route('products.update', $data), $data->toArray());
$response->assertJson($data->toArray());
$this->assertDatabaseHas($data->getTable(), $data->toArray());
}
Result Error:
1) Tests\Feature\ProductControllerTest::testUpdate
Failed asserting that a row in the table [products] matches the attributes {
"name": "CISCO Fire",
"price": 5461.97,
"description": "Ea eligendi qui qui debitis soluta nihil itaque. Quia laborum mollitia voluptatem. Aut corrupti excepturi vel quis ut. Architecto eaque voluptates quia enim in exercitationem nesciunt.",
"updated_at": "2017-07-19 07:38:42",
"created_at": "2017-07-19 07:38:42",
"_id": "596f0c82d1f2d724aa03c11f"
}.
Found: [
{
"_id": {},
"name": "ACER MURPHY",
"price": 10722.72,
"description": "Est ea et omnis nemo. Et iure ea accusamus distinctio omnis exercitationem. Sapiente et dignissimos eveniet et iusto quos explicabo. Tempore inventore corporis minima minus quibusdam.",
"updated_at": {},
"created_at": {}
},
{
"_id": {},
"name": "TOSHIBA Flame",
"price": 1314.84,
"description": "Omnis nisi iusto eum et. Nisi perferendis dolorem sed id et. Odit et sequi corporis necessitatibus error et consequatur.",
"updated_at": {},
"created_at": {}
},
{
"_id": {},
"name": "CISCO Fire",
"price": 5461.97,
"description": "Ea eligendi qui qui debitis soluta nihil itaque. Quia laborum mollitia voluptatem. Aut corrupti excepturi vel quis ut. Architecto eaque voluptates quia enim in exercitationem nesciunt.",
"updated_at": {},
"created_at": {}
}
].
/home/ivan/repos/primo-server/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php:22
/home/ivan/repos/primo-server/tests/Feature/ProductControllerTest.php:40