This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
chrisiek
This PluginTestCase class sets the db parameters for the sqlite database for good.
/*
* Store database in memory
*/
$app['config']->set('database.default', 'sqlite');
$app['config']->set('database.connections.sqlite', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => ''
]);
I want to use mysql and I want to change those parameters in extending phpunit test class to not mess in the original class.
How to do it? I have to change those above into these.
$app['config']->set('database.default', 'mysql');
$app['config']->set('database.connections.mysql', [
'driver' => 'mysql',
'host' => 'localhost',
'port' => '3306',
'database' => 'myserver_tests',
'username' => 'test',
'password' => 'mypass',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]);
Last updated
alxy
You can simply extend the PluginTestCase
and override the createApplication()
and change it to fit your needs ;)
chrisiek
Thank you alxy.
I did this and it worked for me
<?php namespace mydevel\UserExt\Tests\Models;
use Event;
use Config;
use TestCase;
use PluginTestCase;
use Cms\Classes\Theme;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class PostTest extends PluginTestCase
{
use DatabaseTransactions;
public function createApplication()
{
$app = parent::createApplication();
$app['config']->set('database.default', 'mysql');
$app['config']->set('database.connections.mysql', [
'driver' => 'mysql',
'host' => 'localhost',
'port' => '3306',
'database' => 'mydevel_tests',
'username' => 'test',
'password' => 'mypass',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]);
return $app;
}
public function testDatabase()
{
// Make call to application...
$this->seeInDatabase('users', ['email' => 'chrisiek@myserver.com']);
}
}
1-3 of 3