-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f69bbe
commit d8e35da
Showing
6 changed files
with
170 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<?php | ||
|
||
/** | ||
* @testCase | ||
* @dataProvider ../../../dbals.ini | ||
*/ | ||
|
||
namespace NextrasTests\Migrations; | ||
|
||
use Phalcon\Cli\Dispatcher; | ||
use Tester\Assert; | ||
use Tester\Environment; | ||
use Tester\TestCase; | ||
|
||
|
||
require __DIR__ . '/../../../bootstrap.php'; | ||
|
||
|
||
class PhalconTest extends TestCase | ||
{ | ||
/** @var \Phalcon\Cli\Console */ | ||
private $console; | ||
|
||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
Environment::lock(__CLASS__, __DIR__ . '/../../../temp'); | ||
|
||
$options = Environment::loadData(); | ||
$driversConfig = parse_ini_file(__DIR__ . '/../../../drivers.ini', TRUE); | ||
$dbalOptions = $driversConfig[$options['driver']]; | ||
|
||
// Using the CLI factory default services container | ||
$di = new \Phalcon\Di\FactoryDefault\Cli(); | ||
|
||
// DI services | ||
$di->set( | ||
'config', | ||
new \Phalcon\Config([ | ||
'migrationsDir' => __DIR__ . "/../../../fixtures/$options[driver]", | ||
'host' => $dbalOptions['host'], | ||
'username' => $dbalOptions['database'], | ||
'password' => $dbalOptions['username'], | ||
'dbname' => $dbalOptions['password'], | ||
]) | ||
); | ||
$di->set( | ||
'migrationsDir', | ||
function () { | ||
/** @var \Phalcon\Config $config */ | ||
$config = $this->get('config'); | ||
return $config->migrationsDir; | ||
} | ||
); | ||
$di->set( | ||
'phalconAdapter', | ||
function () { | ||
/** @var \Phalcon\Db\Adapter\Pdo $connection */ | ||
$connection = $this->get('connection'); | ||
return new \Nextras\Migrations\Bridges\Phalcon\PhalconAdapter($connection); | ||
} | ||
); | ||
|
||
if ($options['driver'] === 'mysql') { | ||
$di->set( | ||
'connection', | ||
function () { | ||
/** @var \Phalcon\Config $config */ | ||
$config = $this->get('config'); | ||
return new \Phalcon\Db\Adapter\Pdo\Mysql([ | ||
'host' => $config->database->host, | ||
'username' => $config->database->username, | ||
'password' => $config->database->password, | ||
'dbname' => $config->database->dbname, | ||
'dialectClass' => new \Phalcon\Db\Dialect\Mysql(), | ||
]); | ||
} | ||
); | ||
$di->set( | ||
'driver', | ||
function () { | ||
/** @var \Nextras\Migrations\Bridges\Phalcon\PhalconAdapter $phalconAdapter */ | ||
$phalconAdapter = $this->get('phalconAdapter'); | ||
return new \Nextras\Migrations\Drivers\MySqlDriver($phalconAdapter); | ||
} | ||
); | ||
} else { | ||
$di->set( | ||
'connection', | ||
function () { | ||
/** @var \Phalcon\Config $config */ | ||
$config = $this->get('config'); | ||
return new \Phalcon\Db\Adapter\Pdo\Postgresql([ | ||
'host' => $config->database->host, | ||
'username' => $config->database->username, | ||
'password' => $config->database->password, | ||
'dbname' => $config->database->dbname, | ||
'dialectClass' => new \Phalcon\Db\Dialect\Mysql(), | ||
]); | ||
} | ||
); | ||
$di->set( | ||
'driver', | ||
function () { | ||
/** @var \Nextras\Migrations\Bridges\Phalcon\PhalconAdapter $phalconAdapter */ | ||
$phalconAdapter = $this->get('phalconAdapter'); | ||
return new \Nextras\Migrations\Drivers\PgSqlDriver($phalconAdapter); | ||
} | ||
); | ||
} | ||
|
||
// Configure Task Namespace | ||
/** @var Dispatcher $dispatcher */ | ||
$dispatcher = $di->get('dispatcher'); | ||
$dispatcher->setDefaultNamespace('Nextras\\Migrations\\Bridges\\Phalcon'); | ||
|
||
// Create a console application | ||
$this->console = new \Phalcon\Cli\Console(); | ||
$this->console->setDI($di); | ||
} | ||
|
||
|
||
public function testMigrationsReset() | ||
{ | ||
$arguments['task'] = 'migrations'; | ||
$arguments['action'] = 'main'; | ||
$arguments['params'] = ['reset']; | ||
|
||
Assert::null($this->console->handle($arguments)); | ||
} | ||
|
||
|
||
public function testMigrationsContinue() | ||
{ | ||
$arguments['task'] = 'migrations'; | ||
$arguments['action'] = 'main'; | ||
$arguments['params'] = ['continue']; | ||
|
||
Assert::null($this->console->handle($arguments)); | ||
} | ||
} | ||
|
||
|
||
(new PhalconTest)->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
PHP_VERSION_MIN="50500" | ||
PHP_VERSION_MAX="70299" | ||
COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/dbal:~2.5" | ||
DBAL="doctrine" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
PHP_VERSION_MIN="50500" | ||
PHP_VERSION_MAX="70299" | ||
DBAL="doctrine" | ||
PHALCON="phalcon" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters