Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
TestbenchExtension: use default config parameters
Browse files Browse the repository at this point in the history
Related PR: #38
  • Loading branch information
mrtnzlml committed Oct 9, 2016
1 parent c7d3793 commit 93b7680
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
14 changes: 6 additions & 8 deletions src/Mocks/DoctrineConnectionMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ public function __testbench_database_setup($connection, \Nette\DI\Container $con

$config = $container->parameters['testbench'];

if (isset($config['sqls'])) {
foreach ($container->parameters['testbench']['sqls'] as $file) {
\Kdyby\Doctrine\Dbal\BatchImport\Helpers::loadFromFile($connection, $file);
}
foreach ($config['sqls'] as $file) {
\Kdyby\Doctrine\Dbal\BatchImport\Helpers::loadFromFile($connection, $file);
}

if (isset($config['migrations']) && $config['migrations'] === TRUE) {
if ($config['migrations'] === TRUE) {
if (class_exists(\Zenify\DoctrineMigrations\Configuration\Configuration::class)) {
/** @var \Zenify\DoctrineMigrations\Configuration\Configuration $migrationsConfig */
$migrationsConfig = $container->getByType(\Zenify\DoctrineMigrations\Configuration\Configuration::class);
Expand Down Expand Up @@ -113,9 +111,9 @@ public function __testbench_database_connect($connection, \Nette\DI\Container $c
{
//connect to an existing database other than $this->_databaseName
if ($databaseName === NULL) {
$config = $container->parameters['testbench'];
if (isset($config['dbname'])) {
$databaseName = $config['dbname'];
$dbname = $container->parameters['testbench']['dbname'];
if ($dbname) {
$databaseName = $dbname;
} elseif ($connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
$databaseName = 'postgres';
} else {
Expand Down
12 changes: 5 additions & 7 deletions src/Mocks/NetteDatabaseConnectionMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ public function __testbench_database_setup($connection, \Nette\DI\Container $con
$this->__testbench_database_drop($connection, $container);
$this->__testbench_database_create($connection, $container);

if (isset($container->parameters['testbench']['sqls'])) {
foreach ($container->parameters['testbench']['sqls'] as $file) {
\Nette\Database\Helpers::loadFromFile($connection, $file);
}
foreach ($container->parameters['testbench']['sqls'] as $file) {
\Nette\Database\Helpers::loadFromFile($connection, $file);
}

register_shutdown_function(function () use ($connection, $container) {
Expand Down Expand Up @@ -85,9 +83,9 @@ public function __testbench_database_connect($connection, \Nette\DI\Container $c
{
//connect to an existing database other than $this->_databaseName
if ($databaseName === NULL) {
$config = $container->parameters['testbench'];
if (isset($config['dbname'])) {
$databaseName = $config['dbname'];
$dbname = $container->parameters['testbench']['dbname'];
if ($dbname) {
$databaseName = $dbname;
} elseif ($connection->getSupplementalDriver() instanceof PgSqlDriver) {
$databaseName = 'postgres';
} else {
Expand Down
14 changes: 8 additions & 6 deletions src/TestbenchExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
class TestbenchExtension extends \Nette\DI\CompilerExtension
{

private $defaults = [
'dbname' => NULL, // custom test database name
'migrations' => FALSE, // set TRUE if you want to use Doctrine migrations
'sqls' => [], // sqls you want to import during new test database creation
'url' => 'http://test.bench/', // fake URL for HTTP request mock
];

public function loadConfiguration()
{
$builder = $this->compiler->getContainerBuilder();
$testbenchConfig = $this->getConfig();
if (!isset($testbenchConfig['url'])) {
$testbenchConfig['url'] = 'http://test.bench/';
}
$builder->parameters[$this->name] = $testbenchConfig;
$builder->parameters[$this->name] = $this->validateConfig($this->defaults);

$this->prepareDoctrine();
$this->prepareNetteDatabase($builder);

//TODO: $builder->addDefinition($this->prefix('applicationRequestMock'))->setClass('Testbench\ApplicationRequestMock');
}

Expand Down

0 comments on commit 93b7680

Please sign in to comment.