From 4f68efeefa7dd5229ef26a783c419e6e18a281e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zat=C5=99ep=C3=A1lek?= Date: Thu, 24 Jan 2019 10:55:52 +0100 Subject: [PATCH] Test for Phalcon integration --- .travis.yml | 5 + composer.json | 1 + .../integration/phalcon/PhalconTest.phpt | 150 ++++++++++++++++++ tests/matrix/dbal/phalcon-3.4.sh | 5 + .../matrix/phalcon/phalcon-php-5.5-to-7.2.sh | 5 + tests/run-integration.sh | 9 +- 6 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 tests/cases/integration/phalcon/PhalconTest.phpt create mode 100644 tests/matrix/dbal/phalcon-3.4.sh create mode 100644 tests/matrix/phalcon/phalcon-php-5.5-to-7.2.sh diff --git a/.travis.yml b/.travis.yml index 90f471b..7ad0c13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,10 @@ php: - 7.2 - 7.3 +cache: + directories: + - ~/cphalcon + matrix: fast_finish: true @@ -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; fi script: - ./tests/run-unit.sh diff --git a/composer.json b/composer.json index 8005053..20954f4 100644 --- a/composer.json +++ b/composer.json @@ -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": "*" }, diff --git a/tests/cases/integration/phalcon/PhalconTest.phpt b/tests/cases/integration/phalcon/PhalconTest.phpt new file mode 100644 index 0000000..54e23cc --- /dev/null +++ b/tests/cases/integration/phalcon/PhalconTest.phpt @@ -0,0 +1,150 @@ +set( + 'config', + new \Phalcon\Config([ + 'migrationsDir' => __DIR__ . "/../../../fixtures/$options[driver]", + 'host' => $dbalOptions['host'], + 'username' => $dbalOptions['username'], + 'password' => $dbalOptions['password'], + 'dbname' => $dbalOptions['database'], + ]) + ); + $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->host, + 'username' => $config->username, + 'password' => $config->password, + 'dbname' => $config->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->host, + 'username' => $config->username, + 'password' => $config->password, + 'dbname' => $config->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() + { + Assert::noError(function () { + $arguments = []; + $arguments['task'] = 'migrations'; + $arguments['action'] = 'main'; + $arguments['params'] = ['reset']; + $this->console->handle($arguments); + }); + } + + + public function testMigrationsContinue() + { + Assert::noError(function () { + $arguments['task'] = 'migrations'; + $arguments['action'] = 'main'; + $arguments['params'] = ['continue']; + + $this->console->handle($arguments); + }); + } +} + + +(new PhalconTest)->run(); diff --git a/tests/matrix/dbal/phalcon-3.4.sh b/tests/matrix/dbal/phalcon-3.4.sh new file mode 100644 index 0000000..3bc3137 --- /dev/null +++ b/tests/matrix/dbal/phalcon-3.4.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +PHP_VERSION_MIN="50500" +PHP_VERSION_MAX="70399" +COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/dbal:~2.5" +DBAL="doctrine" diff --git a/tests/matrix/phalcon/phalcon-php-5.5-to-7.2.sh b/tests/matrix/phalcon/phalcon-php-5.5-to-7.2.sh new file mode 100644 index 0000000..a9bd477 --- /dev/null +++ b/tests/matrix/phalcon/phalcon-php-5.5-to-7.2.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +PHP_VERSION_MIN="50500" +PHP_VERSION_MAX="70399" +DBAL="doctrine" +PHALCON="phalcon" diff --git a/tests/run-integration.sh b/tests/run-integration.sh index 5fb5476..0adbc05 100755 --- a/tests/run-integration.sh +++ b/tests/run-integration.sh @@ -15,6 +15,7 @@ run() PHP_VERSION_MAX="" COMPOSER_REQUIRE="" DBAL="" + PHALCON="" echo echo @@ -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" @@ -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" @@ -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" >> "$PROJECT_DIR/tests/php.ini" + fi }