Govind Samrow
Govind Samrow

Reputation: 10187

Rollback database changes after unit test Lumen

We've used Lumen for building API and also created some test cases.

All test cases working fine but We want to revert all the changes that done by test cases.

Is it any way to revert all changes in Lumen.

Test Case Example:

class PostTest extends TestCase
{
    /**
     * Test create post
     *
     * @return void
     */
    public function testBasicExample()
    {
        $this->post('/post', ['post_name' => 'New Post'])
             ->seeJsonEquals([
                'created' => true,
             ]);
    }
}

Note: We don't want to truncate all data, just revert test case changes.

Thanks!

Upvotes: 0

Views: 2833

Answers (1)

user320487
user320487

Reputation:

Laravel has a nice Trait to help with just that. Check out DatabaseTransactions:

https://laravel.com/docs/5.4/database-testing#using-transactions

It will wrap every query your test does and then revert when the test is complete.

Upvotes: 1

Related Questions