php - Database transactions doesn't prevent id incrementation when testing in Laravel -


so, in laravel 5.3 have following test:

class articletest extends testcase {     use databasetransactions;      /** @test */     public function it_fetches_trending_articles()     {         factory(article::class, 3)->create();         factory(article::class)->create(['reads' => 10]);         $mostpopular = factory(article::class)->create(['reads' => 20]);          $articles = article::trending();          $this->assertequals($mostpopular->id, $articles->first()->id);     } } 

what's going on here create 3 articles no 'reads' info, 1 article 10 reads , 1 20 reads. articles, ordered 'reads' , take first 1 , assert it's id equal 1 i'm sure trending. test passes , ok.

the problem, though, databasetransactions trait not work expected. yeah, doesn't save articles database, keeps increasing id count on each test run.

it great if give me advice on how prevent kind of behaviour.

thanks in advance. :)

you'd have use databasemigrations. when transaction reversed, database increments primary key. has to, otherwise might have other issues in app repeating primary keys.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -