|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * @testCase |
| 5 | + * @dataProvider ../../../dbals.ini |
| 6 | + */ |
| 7 | + |
| 8 | +namespace NextrasTests\Migrations; |
| 9 | + |
| 10 | +use Tester\Assert; |
| 11 | +use Tester\Environment; |
| 12 | +use Tester\TestCase; |
| 13 | + |
| 14 | + |
| 15 | +require __DIR__ . '/../../../bootstrap.php'; |
| 16 | + |
| 17 | + |
| 18 | +class PhalconTest extends TestCase |
| 19 | +{ |
| 20 | + /** @var \Phalcon\Cli\Console */ |
| 21 | + private $console; |
| 22 | + |
| 23 | + |
| 24 | + protected function setUp() |
| 25 | + { |
| 26 | + parent::setUp(); |
| 27 | + |
| 28 | + Environment::lock(__CLASS__, __DIR__ . '/../../../temp'); |
| 29 | + |
| 30 | + $options = Environment::loadData(); |
| 31 | + $driversConfig = parse_ini_file(__DIR__ . '/../../../drivers.ini', TRUE); |
| 32 | + $dbalOptions = $driversConfig[$options['driver']]; |
| 33 | + |
| 34 | + // Using the CLI factory default services container |
| 35 | + $di = new \Phalcon\Di\FactoryDefault\Cli(); |
| 36 | + |
| 37 | + // DI services |
| 38 | + $di->set( |
| 39 | + 'config', |
| 40 | + new \Phalcon\Config([ |
| 41 | + 'migrationsDir' => __DIR__ . "/../../../fixtures/$options[driver]", |
| 42 | + 'host' => $dbalOptions['host'], |
| 43 | + 'username' => $dbalOptions['database'], |
| 44 | + 'password' => $dbalOptions['username'], |
| 45 | + 'dbname' => $dbalOptions['password'], |
| 46 | + ]) |
| 47 | + ); |
| 48 | + $di->set( |
| 49 | + 'migrationsDir', |
| 50 | + function () { |
| 51 | + /** @var \Phalcon\Config $config */ |
| 52 | + $config = $this->get('config'); |
| 53 | + return $config->migrationsDir; |
| 54 | + } |
| 55 | + ); |
| 56 | + $di->set( |
| 57 | + 'phalconAdapter', |
| 58 | + function () { |
| 59 | + /** @var \Phalcon\Db\Adapter\Pdo $connection */ |
| 60 | + $connection = $this->get('connection'); |
| 61 | + return new \Nextras\Migrations\Bridges\Phalcon\PhalconAdapter($connection); |
| 62 | + } |
| 63 | + ); |
| 64 | + |
| 65 | + if ($options['driver'] === 'mysql') { |
| 66 | + $di->set( |
| 67 | + 'connection', |
| 68 | + function () { |
| 69 | + /** @var \Phalcon\Config $config */ |
| 70 | + $config = $this->get('config'); |
| 71 | + return new \Phalcon\Db\Adapter\Pdo\Mysql([ |
| 72 | + 'host' => $config->database->host, |
| 73 | + 'username' => $config->database->username, |
| 74 | + 'password' => $config->database->password, |
| 75 | + 'dbname' => $config->database->dbname, |
| 76 | + 'dialectClass' => new \Phalcon\Db\Dialect\Mysql(), |
| 77 | + ]); |
| 78 | + } |
| 79 | + ); |
| 80 | + $di->set( |
| 81 | + 'driver', |
| 82 | + function () { |
| 83 | + /** @var \Nextras\Migrations\Bridges\Phalcon\PhalconAdapter $phalconAdapter */ |
| 84 | + $phalconAdapter = $this->get('phalconAdapter'); |
| 85 | + return new \Nextras\Migrations\Drivers\MySqlDriver($phalconAdapter); |
| 86 | + } |
| 87 | + ); |
| 88 | + } else { |
| 89 | + $di->set( |
| 90 | + 'connection', |
| 91 | + function () { |
| 92 | + /** @var \Phalcon\Config $config */ |
| 93 | + $config = $this->get('config'); |
| 94 | + return new \Phalcon\Db\Adapter\Pdo\Postgresql([ |
| 95 | + 'host' => $config->database->host, |
| 96 | + 'username' => $config->database->username, |
| 97 | + 'password' => $config->database->password, |
| 98 | + 'dbname' => $config->database->dbname, |
| 99 | + 'dialectClass' => new \Phalcon\Db\Dialect\Mysql(), |
| 100 | + ]); |
| 101 | + } |
| 102 | + ); |
| 103 | + $di->set( |
| 104 | + 'driver', |
| 105 | + function () { |
| 106 | + /** @var \Nextras\Migrations\Bridges\Phalcon\PhalconAdapter $phalconAdapter */ |
| 107 | + $phalconAdapter = $this->get('phalconAdapter'); |
| 108 | + return new \Nextras\Migrations\Drivers\PgSqlDriver($phalconAdapter); |
| 109 | + } |
| 110 | + ); |
| 111 | + } |
| 112 | + |
| 113 | + // Create a console application |
| 114 | + $this->console = new \Phalcon\Cli\Console(); |
| 115 | + $this->console->setDI($di); |
| 116 | + } |
| 117 | + |
| 118 | + |
| 119 | + public function testMigrationsReset() |
| 120 | + { |
| 121 | + $arguments['task'] = 'main'; |
| 122 | + $arguments['action'] = 'reset'; |
| 123 | + $arguments['params'] = ['reset']; |
| 124 | + |
| 125 | + Assert::null($this->console->handle($arguments)); |
| 126 | + } |
| 127 | + |
| 128 | + |
| 129 | + public function testMigrationsContinue() |
| 130 | + { |
| 131 | + $arguments['task'] = 'main'; |
| 132 | + $arguments['action'] = 'main'; |
| 133 | + $arguments['params'] = ['continue']; |
| 134 | + |
| 135 | + Assert::null($this->console->handle($arguments)); |
| 136 | + } |
| 137 | +} |
| 138 | + |
| 139 | + |
| 140 | +(new PhalconTest)->run(); |
0 commit comments