1

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???

2 Answers 2

3

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.

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

3 Comments

I already have it in my bootstrap file, but when I dd(Auth::user()) for inst, I get null
So I'm a little bit confused
@JuliatzindelToro Hmm, that is an interesting issue. It would seem as if there's another issue in the Acceptance Test, then.
1

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.

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.