Skip to content

Commit 33e155b

Browse files
[WIP] Phalcon testing
1 parent 4f69bbe commit 33e155b

File tree

6 files changed

+164
-1
lines changed

6 files changed

+164
-1
lines changed

.travis.yml

+5
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 && echo "Phalcon version " && php --ri phalcon && php -r 'var_dump(class_exists(\Phalcon\Di\FactoryDefault\Cli::class));'; fi
2631

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

composer.json

+1
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
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
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();

tests/matrix/dbal/phalcon-3.4.sh

+5
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"
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=true

tests/run-integration.sh

+8-1
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" >> "$INI_PATH"
72+
fi
6673
}
6774

6875

0 commit comments

Comments
 (0)