Juliatzin
Juliatzin

Reputation: 19695

Codeception, Laravel, Acceptance tests

I'm developping an acceptance test with Codeception Laravel 5.

I see in the docs that module Laravel 5 should not be used in acceptance tests.

Now, I would like to use function like: Auth::xxx, factory(User::class)->create(), etc... but those functions are not recognized.

I can use them in my funcional tests, because I include Laravel 5 Module.

Does it mean I will not be able to use them in acceptance test, or is there a trick to do it???

Upvotes: 1

Views: 458

Answers (2)

user2094178
user2094178

Reputation: 9454

When in acceptance testing, you have two instances, yours (codeception) and the app's (website).

This means anything laravel you use in your instance won't work in the app's instance.

Here Auth::check() has no meaning, as acceptance testing must be decoupled from the app. You should assert if you are seeing Log In or Log Out in the rendered html for example.

Eloquent is the only thing you can get away with when in acceptance testing.

Upvotes: 1

Ohgodwhy
Ohgodwhy

Reputation: 50787

The documentation clearly outlines the answer to your question:

You should not use this module for acceptance tests. If you want to use Laravel functionality with your acceptance tests, for example to do test setup, you can initialize the Laravel functionality by adding the following lines of code to your suite _bootstrap.php file:

So this is what you add:

require 'bootstrap/autoload.php';
$app = require 'bootstrap/app.php';
$app->loadEnvironmentFrom('.env.testing');
$app->instance('request', new \Illuminate\Http\Request);
$app->make('Illuminate\Contracts\Http\Kernel')->bootstrap();

This means you can use the Laravel functionality in your Acceptance Tests, however, you can't use the Codeception Laravel 5 module for your Acceptance Tests.

Hopefully this clears things up.

Upvotes: 3

Related Questions