Skip to content

Commit

Permalink
[WIP] Phalcon testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tzatrepalek-inwk committed Jan 25, 2019
1 parent 4f69bbe commit 33e155b
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ php:
- 7.2
- 7.3

cache:
directories:
- ~/cphalcon

matrix:
fast_finish: true

Expand All @@ -23,6 +27,7 @@ before_script:

- composer self-update
- composer install --no-interaction --no-progress
- 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

script:
- ./tests/run-unit.sh
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"symfony/console": "~2.6 | ~3.0 | ~4.0",
"symfony/dependency-injection": "~2.6 | ~3.0 | ~4.0",
"symfony/http-kernel": "~2.6 | ~3.0 | ~4.0",
"techpivot/phalcon-ci-installer": "~1.0",
"tracy/tracy": "^2.2",
"ext-openssl": "*"
},
Expand Down
140 changes: 140 additions & 0 deletions tests/cases/integration/phalcon/PhalconTest.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php

/**
* @testCase
* @dataProvider ../../../dbals.ini
*/

namespace NextrasTests\Migrations;

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);
}
);
}

// Create a console application
$this->console = new \Phalcon\Cli\Console();
$this->console->setDI($di);
}


public function testMigrationsReset()
{
$arguments['task'] = 'main';
$arguments['action'] = 'reset';
$arguments['params'] = ['reset'];

Assert::null($this->console->handle($arguments));
}


public function testMigrationsContinue()
{
$arguments['task'] = 'main';
$arguments['action'] = 'main';
$arguments['params'] = ['continue'];

Assert::null($this->console->handle($arguments));
}
}


(new PhalconTest)->run();
5 changes: 5 additions & 0 deletions tests/matrix/dbal/phalcon-3.4.sh
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"
5 changes: 5 additions & 0 deletions tests/matrix/phalcon/phalcon-php-5.5-to-7.2.sh
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=true
9 changes: 8 additions & 1 deletion tests/run-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ run()
PHP_VERSION_MAX=""
COMPOSER_REQUIRE=""
DBAL=""
PHALCON=""

echo
echo
Expand All @@ -33,7 +34,7 @@ run()
return 0
fi

create_dbals_ini "$DBAL"
create_dbals_ini "$DBAL" "$PHALCON"

composer_prepare_dependencies "$COMPOSER_REQUIRE" ""
tester_run_integration_group "$INTEGRATION_GROUP"
Expand All @@ -51,9 +52,11 @@ run()
create_dbals_ini()
{
DBAL="$1"
PHALCON="$2"
INI_PATH="$PROJECT_DIR/tests/dbals.ini"

rm --force "$INI_PATH"

if [[ ! -z "$DBAL" ]]; then
echo "[$DBAL.mysql]" >> "$INI_PATH"
echo "dbal = $DBAL" >> "$INI_PATH"
Expand All @@ -63,6 +66,10 @@ create_dbals_ini()
echo "dbal = $DBAL" >> "$INI_PATH"
echo "driver = pgsql" >> "$INI_PATH"
fi

if [[ ! -z "$PHALCON" ]]; then
echo "extension=phalcon.so" >> "$INI_PATH"
fi
}


Expand Down

0 comments on commit 33e155b

Please sign in to comment.