Skip to content

Commit d8e35da

Browse files
Test for Phalcon integration
1 parent 4f69bbe commit d8e35da

File tree

6 files changed

+170
-1
lines changed

6 files changed

+170
-1
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ php:
1010
- 7.2
1111
- 7.3
1212

13+
cache:
14+
directories:
15+
- ~/cphalcon
16+
1317
matrix:
1418
fast_finish: true
1519

@@ -23,6 +27,7 @@ before_script:
2327

2428
- composer self-update
2529
- composer install --no-interaction --no-progress
30+
- if [[ $TRAVIS_PHP_VERSION == "5.5" ]] || [[ $TRAVIS_PHP_VERSION == "5.6" ]] || [[ $TRAVIS_PHP_VERSION == "7.0" ]] || [[ $TRAVIS_PHP_VERSION == "7.1" ]] || [[ $TRAVIS_PHP_VERSION == "7.2" ]]; then vendor/bin/install-phalcon.sh 3.4.x; fi
2631

2732
script:
2833
- ./tests/run-unit.sh

composer.json

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

tests/matrix/dbal/phalcon-3.4.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
PHP_VERSION_MIN="50500"
3+
PHP_VERSION_MAX="70299"
4+
COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/dbal:~2.5"
5+
DBAL="doctrine"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
PHP_VERSION_MIN="50500"
3+
PHP_VERSION_MAX="70299"
4+
DBAL="doctrine"
5+
PHALCON="phalcon"

tests/run-integration.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ run()
1515
PHP_VERSION_MAX=""
1616
COMPOSER_REQUIRE=""
1717
DBAL=""
18+
PHALCON=""
1819

1920
echo
2021
echo
@@ -33,7 +34,7 @@ run()
3334
return 0
3435
fi
3536

36-
create_dbals_ini "$DBAL"
37+
create_dbals_ini "$DBAL" "$PHALCON"
3738

3839
composer_prepare_dependencies "$COMPOSER_REQUIRE" ""
3940
tester_run_integration_group "$INTEGRATION_GROUP"
@@ -51,9 +52,11 @@ run()
5152
create_dbals_ini()
5253
{
5354
DBAL="$1"
55+
PHALCON="$2"
5456
INI_PATH="$PROJECT_DIR/tests/dbals.ini"
5557

5658
rm --force "$INI_PATH"
59+
5760
if [[ ! -z "$DBAL" ]]; then
5861
echo "[$DBAL.mysql]" >> "$INI_PATH"
5962
echo "dbal = $DBAL" >> "$INI_PATH"
@@ -63,6 +66,10 @@ create_dbals_ini()
6366
echo "dbal = $DBAL" >> "$INI_PATH"
6467
echo "driver = pgsql" >> "$INI_PATH"
6568
fi
69+
70+
if [[ ! -z "$PHALCON" ]]; then
71+
echo "extension=phalcon.so" >> "$PROJECT_DIR/tests/php.ini"
72+
fi
6673
}
6774

6875

0 commit comments

Comments
 (0)