#Run laravel dusk tests on Github Actions

1 messages · Page 1 of 1 (latest)

tawdry edge
#

I'm having a hell of a time running getting my laravel dusk test to connect to the db correctly on Github Actions.

  • I've tried both sqlite and mysql for the dusk test job.
  • My normal php unit integration tests that don't involve a browser driver work fine.
  • I can use a factory to create a dummy user in the dusk test cases and assert the user is added correctly to the db.
  • I'm able to get my pdo connection from inside my dusk test cases.
  • When I dump my config from inside the test, it all lines up.

HOWEVER, when I dump the config from the login controller I'm trying to test, the db name is wrong - laravel, rather than testing. It seems like php artisan serve isn't getting the correct database associated with it.

What could cause this?

vital trout
tawdry edge
#

Hmm - I have a .env.dusk.local file for running these locally - what would dusk on github actions use?

vital trout
#

In that example it sets configuration values as actual environment variables instead of messing about with .env files.

#

You should use environment variables proper where you can.

#

.env files are just to aid local development where it’s difficult to set environment variables, or where you’re running multiple projects so can’t set machine-wide environment variables for configuration.

tawdry edge
#

thanks @vital trout !

#

now I'm finding that it looks like my stripe webhooks aren't being handled properly, so assertions like this

        $activeSubs = $user->subscriptions()->active()->get();

        $this->assertTrue($activeSubs->containsOneItem());

End up failing.

I have this to set up the test case

public function setUp(): void
    {
        parent::setUp();

        $secret = env('STRIPE_SECRET');

        $this->process = new Process(['stripe', 'listen', '--api-key', $secret, '--forward-to', sprintf('%s/stripe/webhook', env('APP_URL'))]);
        $this->process->start();

        Stripe::setApiKey($secret);
    }

And it works locally, but not on github actions 🫤

Any ideas?

vital trout
#

I don’t send “real” requests in tests at all.

#

Makes my test suite useless if I’m on a train with bad WiFi or no WiFi whatsoever.

tawdry edge
#

Yeah, I guess that's usually the best practice... I'm using stripe checkout, so I'm already reliant on an internet connection there.

vital trout
#

I use Stripe Checkout in my own apps. A have a service class that i mock to return a fake checkout URL, and then assert the redirect in my feature test.