-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Selenium not using the phpunit.xml mysql connection #29
Comments
Thanks for reporting! I'm looking into it. |
For me, this was solved by adding all details in phpunit file <env name="DB_CONNECTION" value="testing"/>
<env name="DB_HOST" value="127.0.0.1"/>
<env name="DB_PORT" value="3306"/>
<env name="DB_DATABASE" value="your_db_name"/>
<env name="DB_USERNAME" value="root"/>
<env name="DB_PASSWORD" value="root"/> and for database transaction, you can try #31 |
it doesn't solve the problem for me. |
i have fixed it by creating Testing Middleware that changes the default database connection on every request middleware <?php
namespace App\Http\Middleware;
use Closure;
class Testing
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
config(['database.default' => 'testing']);
return $next($request);
}
} and i have added it to Http Kernel to: protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\App\Http\Middleware\Testing::class,
]; then just comment it out when you push it to production. |
Okay, so my solution will not work when an actual browser is open. Recently someone raised a similar issue related to .env on Laravel and env repo. Right now I'm not able to get exact issue link. So for a quick solution, your middleware stuff will solve it but you can also go with Feel free to submit a PR so that we can at least give a temp and reliable solution to overcome this problem. |
ok. i have created fork with the TestingMiddleware and created PR. |
When running a test the factory method does create the record in the 'testing' database, but when selenium hits the page its using the default db connection and when i try to login the just created user it gets credentials don't match message and test fails.
also the laravel DatabaseTransactions doesn't work either.
my phpunit.xml
i have 'testing' connection setup.
my test
I tried to put
putenv('DB_CONNECTION=testing');
in the Application trait createApplication method inside the package but that didn't work either.Any ideas why it doesn't work? and how to make it work?
The text was updated successfully, but these errors were encountered: