mercredi 23 janvier 2019

seeInDatabase fails sometimes because of updated_at fields 1sec later

I have a test in Laravel 5.7 that pass 90% of the time.

sometimes, it fails, and it is because there is a second between created_at and updated_at:

In DB:

"created_at" => "2019-01-23 18:27:36"
"updated_at" => "2019-01-23 18:27:37"

Inside local setting $setting:

"created_at" => "2019-01-23 18:27:36"
"updated_at" => "2019-01-23 18:27:36"

my test:

/** @test */
    public function it_update_setting_for_championship()
    {
        $tournament = factory(Tournament::class)->create();
        $championship = factory(Championship::class)->create(['tournament_id' => $tournament->id, 'category_id' => 2]);
        $setting = factory(ChampionshipSettings::class)->create(['championship_id' => $championship->id]);

        $this->call('PUT', '/championships/' . $championship->id . '/settings/' . $setting->id, $setting->toArray());
        $this->assertResponseOk();
        $this->seeInDatabase('championship_settings', $setting->toArray());
    }

Of course, I could put $setting->toArray() into a variable and unset created_at and updated_at but it feels wrong...

Why doesn't it happen always ?

Anybody has a better solution?

Aucun commentaire:

Enregistrer un commentaire