Behat-Laravel-Extension icon indicating copy to clipboard operation
Behat-Laravel-Extension copied to clipboard

Application state not refreshed between scenarios

Open ecornelisse opened this issue 6 years ago • 3 comments

The application instance is not refreshed and so singleton services are being reused during different scenarios. This can be a problem if the singelton has some for of state. How can i refresh the application completely on each scenario?

ecornelisse avatar Mar 28 '18 13:03 ecornelisse

you are stating in the readme:

Refresh: Laravel is automatically rebooted after each scenario (so nothing like user sessions will be persisted).

But i guess that's not a complete refresh of the laravel Application?

ecornelisse avatar Mar 29 '18 09:03 ecornelisse

i think i found the problem. The reboot is only being done if the Context if instanceoff KernelAwareContext. Since i use multiple context files that no longer works because the last context file is of a different type. Maybe i can create a pull request with support for multiple context files

ecornelisse avatar Mar 29 '18 11:03 ecornelisse

Got the same problem. To fix that, I have a context extending MinkContext. I have implement the KernelAwareContext and use the trait App:

<?php

use Behat\MinkExtension\Context\MinkContext;
use Laracasts\Behat\Context\App;
use Laracasts\Behat\Context\KernelAwareContext;

class CustomContext extends MinkContext implements KernelAwareContext
{
    use App;
    ....
}

Put your context at the end of the list in the behat configuration file.

CocoJr avatar Jul 16 '21 08:07 CocoJr