0

in Laravel I need to run MY CUSTOM COMMAND after refreshdatabase and db:seed

  • new database
  • migration
  • seed
  • MY COMMAND

this test finish successfully when i run all these steps manually

I write this test code.

class ExampleTest extends TestCase
{

    use RefreshDatabase;

    
    public function testDbSeed()
    {
        Artisan::call('db:seed');
        $resultAsText = Artisan::output();
        $this->assertTrue(true);
    }

all tables deleted and then run all my migrations successfully.

My question is How to run my CUSTOM command after seed?

php artisan permission:sync

    public function testPermissionSync()
    {
        Artisan::call('permission:sync');
        $resultAsText = Artisan::output();
        $this->assertTrue(true);
    }

after this command we can open main page in ourlocalsite.local/

    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {

        $response = $this->get('/');

        $response->assertStatus(200);
    }

but this test not passed and assert error is 403

(when i do these steps manually this command run)

1 Answer 1

2

you can use setUp() method that triggered before any test begins.

but don not forget to call the parent setup

public function setUp(): void
    {
        parent::setUp();
        Artisan::call('db:seed');
    }

there is also tearDown() function that triggered after test ended

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.