I want to use a separate sqlite testing database for acceptance testing by PHPunit along with Facebook web driver in Laravel 5.1. I've changed the default database in phpunit.xml. After performing the tests, transactions are done in MySQL database! Because, test data are saved into MySql. (In corresponding functions, model save method is used to save an instance of a model into database).
The following are my configuration and settings related to testing database.
/config/database.php
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('MYSQL_MAIN_HOST', 'localhost'),
'database' => env('MYSQL_MAIN_DATABASE', 'db'),
'username' => env('MYSQL_MAIN_USER', 'root'),
'password' => env('MYSQL_MAIN_PASSWORD', 'secret'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
]
/phpunit.xml
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">app/</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<server name='HTTP_HOST' value='http://localhost:8000' />
<server name='REQUEST_URI' value='http://localhost:8000' />
</php>
</phpunit>
.../tests/TestCase.php
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Artisan;
class TestCase extends Illuminate\Foundation\Testing\TestCase
{
use \Illuminate\Foundation\Testing\DatabaseMigrations;
public function setUp()
{
parent::setUp();
Artisan::call('migrate');
Artisan::call('db:seed');
}
public function tearDown()
{
Artisan::call('migrate:rollback');
parent::tearDown(); // TODO: Change the autogenerated stub
}
}
/.env
APPLICATION_URL=http://localhost:8000
APP_DEBUG=true
APP_ENV = local
CACHE_DRIVER=array
DB_CONNECTION=mysql
I've searched a lot but no success yet. Why are transactions in in-memory Sqlite applied in MySql database? How can I make facebook web driver to use phpunit.xml ?
env
settings working properly? – apokryfosenv
settings defined inphpunit.xml
working properly or are they ignored? – apokryfosenv('DB_CONNECTION', 'mysql')
is in your tests. It may be that it just reads from.env
. Check laracasts.com/index.php/discuss/channels/testing/… for a way to use.env.testing
– apokryfos