Answer the question
In order to leave comments, you need to log in
How to execute methods before running tests?
I use dusk for testing. I need to execute a method before running the test. I tried calling the method in the constructor.
class browserTest extends DuskTestCase
{
public function __construct($name = null, array $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);
$this->foo();
}
protected function foo()
{
//code
}
PHP Fatal error: Uncaught RuntimeException: A facade root has not been set. in vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:218
Answer the question
In order to leave comments, you need to log in
Public function setUp() or you can move it to the base class and extend tests from it
DuskTestCase also has a special prepare method to run before tests.
Well, in general, to fence some kind of logic and it’s not clear why such calls in tests are such a solution.
From the preparation for the test, there should be nothing but connecting to the database and rolling the migration.
If you need to do something, then do it in the tests themselves. Why not call this method in the test?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question