diff --git a/.travis.yml b/.travis.yml index 67a67babb0b..737d310066e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,6 +47,11 @@ env: - TEST_DB_MYSQL_PASSWD="" - TEST_DB_MYSQL_NAME="phalcon_test" - TEST_DB_MYSQL_CHARSET="utf8" + - TEST_DB_POSTGRESQL_HOST="127.0.0.1" + - TEST_DB_POSTGRESQL_PORT="5432" + - TEST_DB_POSTGRESQL_USER="postgres" + - TEST_DB_POSTGRESQL_PASSWD="" + - TEST_DB_POSTGRESQL_NAME="phalcon_test" - TEST_DB_MYSQL_DSN="mysql:host=127.0.0.1;dbname=phalcon_test" - TEST_DB_MONGO_HOST="127.0.0.1" - TEST_DB_MONGO_PORT="27017" diff --git a/CHANGELOG.md b/CHANGELOG.md index a93465f2fb4..f03873bff71 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Fixed `Phalcon\Debug::getVersion` to provide valid link to the latest Phalcon major version [#12215](https://github.com/phalcon/cphalcon/issues/12215) - Fixed `Phalcon\Session\Adapter\Libmemcached::read`, `Phalcon\Session\Adapter\Libmemcached::destroy`, `Phalcon\Session\Adapter\Memcache::read`, `Phalcon\Session\Adapter\Memcache::destroy`, `Phalcon\Session\Adapter\Redis::read` and `Phalcon\Session\Adapter\Redis::destroy` in accordance with the `session_set_save_handler` API [#12206](https://github.com/phalcon/cphalcon/pull/12206) - Fixed `Phalcon\Validation::getValue()` to use filters when having entity +- Fixed `Phalcon\Db\Dialect\Mysql::describeReferences()` and `Phalcon\Db\Dialect\Postgresql::describeReferences()` to return proper sql # [3.0.1](https://github.com/phalcon/cphalcon/releases/tag/v3.0.1) (2016-08-24) diff --git a/phalcon/db/dialect/mysql.zep b/phalcon/db/dialect/mysql.zep index 659b47319c7..2556c8327ac 100644 --- a/phalcon/db/dialect/mysql.zep +++ b/phalcon/db/dialect/mysql.zep @@ -632,7 +632,7 @@ class Mysql extends Dialect */ public function describeReferences(string! table, string schema = null) -> string { - var sql = "SELECT KCU.TABLE_NAME, KCU.COLUMN_NAME, KCU.CONSTRAINT_NAME, KCU.REFERENCED_TABLE_SCHEMA, KCU.REFERENCED_TABLE_NAME, KCU.REFERENCED_COLUMN_NAME, RC.UPDATE_RULE, RC.DELETE_RULE FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC ON RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME WHERE KCU.REFERENCED_TABLE_NAME IS NOT NULL AND "; + var sql = "SELECT DISTINCT KCU.TABLE_NAME, KCU.COLUMN_NAME, KCU.CONSTRAINT_NAME, KCU.REFERENCED_TABLE_SCHEMA, KCU.REFERENCED_TABLE_NAME, KCU.REFERENCED_COLUMN_NAME, RC.UPDATE_RULE, RC.DELETE_RULE FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC ON RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME WHERE KCU.REFERENCED_TABLE_NAME IS NOT NULL AND "; if schema { let sql .= "KCU.CONSTRAINT_SCHEMA = '" . schema . "' AND KCU.TABLE_NAME = '" . table . "'"; } else { diff --git a/phalcon/db/dialect/postgresql.zep b/phalcon/db/dialect/postgresql.zep index a8f72d5a215..17e69eb1732 100644 --- a/phalcon/db/dialect/postgresql.zep +++ b/phalcon/db/dialect/postgresql.zep @@ -614,7 +614,7 @@ class Postgresql extends Dialect */ public function describeReferences(string! table, string schema = null) -> string { - var sql = "SELECT tc.table_name as TABLE_NAME, kcu.column_name as COLUMN_NAME, tc.constraint_name as CONSTRAINT_NAME, tc.table_catalog as REFERENCED_TABLE_SCHEMA, ccu.table_name AS REFERENCED_TABLE_NAME, ccu.column_name AS REFERENCED_COLUMN_NAME FROM information_schema.table_constraints AS tc JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name WHERE constraint_type = 'FOREIGN KEY' AND "; + var sql = "SELECT DISTINCT tc.table_name as TABLE_NAME, kcu.column_name as COLUMN_NAME, tc.constraint_name as CONSTRAINT_NAME, tc.table_catalog as REFERENCED_TABLE_SCHEMA, ccu.table_name AS REFERENCED_TABLE_NAME, ccu.column_name AS REFERENCED_COLUMN_NAME FROM information_schema.table_constraints AS tc JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name WHERE constraint_type = 'FOREIGN KEY' AND "; if schema { let sql .= "tc.table_schema = '" . schema . "' AND tc.table_name='" . table . "'"; diff --git a/tests/_bootstrap.php b/tests/_bootstrap.php index 5f401f47fd5..42d6bec80ac 100644 --- a/tests/_bootstrap.php +++ b/tests/_bootstrap.php @@ -61,6 +61,14 @@ defined('TEST_DB_MYSQL_NAME') || define('TEST_DB_MYSQL_NAME', getenv('TEST_DB_MYSQL_NAME') ?: 'phalcon_test'); defined('TEST_DB_MYSQL_CHARSET') || define('TEST_DB_MYSQL_CHARSET', getenv('TEST_DB_MYSQL_CHARSET') ?: 'utf8'); +// Postgresql +defined('TEST_DB_POSTGRESQL_HOST') || define('TEST_DB_POSTGRESQL_HOST', getenv('TEST_DB_POSTGRESQL_HOST') ?: '127.0.0.1'); +defined('TEST_DB_POSTGRESQL_PORT') || define('TEST_DB_POSTGRESQL_PORT', getenv('TEST_DB_POSTGRESQL_PORT') ?: 5432); +defined('TEST_DB_POSTGRESQL_USER') || define('TEST_DB_POSTGRESQL_USER', getenv('TEST_DB_POSTGRESQL_USER') ?: 'postgres'); +defined('TEST_DB_POSTGRESQL_PASSWD') || define('TEST_DB_POSTGRESQL_PASSWD', getenv('TEST_DB_POSTGRESQL_PASSWD') ?: ''); +defined('TEST_DB_POSTGRESQL_NAME') || define('TEST_DB_POSTGRESQL_NAME', getenv('TEST_DB_POSTGRESQL_NAME') ?: 'phalcon_test'); +defined('TEST_DB_POSTGRESQL_SCHEMA') || define('TEST_DB_POSTGRESQL_SCHEMA', getenv('TEST_DB_POSTGRESQL_SCHEMA') ?: 'public'); + // Mongo defined('TEST_DB_MONGO_HOST') || define('TEST_DB_MONGO_HOST', getenv('TEST_DB_MONGO_HOST') ?: '127.0.0.1'); defined('TEST_DB_MONGO_PORT') || define('TEST_DB_MONGO_PORT', getenv('TEST_DB_MONGO_PORT') ?: 27017); diff --git a/tests/unit/Db/Adapter/Pdo/MysqlTest.php b/tests/unit/Db/Adapter/Pdo/MysqlTest.php index 3aac9b4c8c0..e3d8156db04 100644 --- a/tests/unit/Db/Adapter/Pdo/MysqlTest.php +++ b/tests/unit/Db/Adapter/Pdo/MysqlTest.php @@ -2,6 +2,7 @@ namespace Phalcon\Test\Unit\Db\Adapter\Pdo; +use Phalcon\Db\Reference; use Phalcon\Test\Module\UnitTest; use Phalcon\Db\Adapter\Pdo\Mysql; @@ -87,4 +88,24 @@ function () { } ); } + + /** + * Tests Mysql::describeReferences + * + * @author Wojciechj Ślawski + * @since 2016-09-28 + */ + public function testDescribeReferencesColumnsCount() + { + $this->specify( + 'Mysql::describeReferences return wrong number of columns in Phalcon\Db\Reference', + function() { + $references = $this->connection->describeReferences("robots_parts", TEST_DB_MYSQL_NAME); + /** @var Reference $reference */ + foreach($references as $reference) { + expect($reference->getColumns())->count(1); + } + } + ); + } } diff --git a/tests/unit/Db/Adapter/Pdo/PostgresqlTest.php b/tests/unit/Db/Adapter/Pdo/PostgresqlTest.php new file mode 100644 index 00000000000..43c9109df51 --- /dev/null +++ b/tests/unit/Db/Adapter/Pdo/PostgresqlTest.php @@ -0,0 +1,67 @@ + + * @author Serghei Iakovlev + * @author Wojciech Ślawski + * @package Phalcon\Test\Unit\Db\Adapter\Pdo + * + * The contents of this file are subject to the New BSD License that is + * bundled with this package in the file docs/LICENSE.txt + * + * If you did not receive a copy of the license and are unable to obtain it + * through the world-wide-web, please send an email to license@phalconphp.com + * so that we can send you a copy immediately. + */ +class PostgresqlTest extends UnitTest +{ + /** + * @var Postgresql + */ + protected $connection; + + public function _before() + { + parent::_before(); + + $this->connection = new Postgresql([ + 'host' => TEST_DB_POSTGRESQL_HOST, + 'username' => TEST_DB_POSTGRESQL_USER, + 'password' => TEST_DB_POSTGRESQL_PASSWD, + 'dbname' => TEST_DB_POSTGRESQL_NAME, + 'port' => TEST_DB_POSTGRESQL_PORT, + 'schema' => TEST_DB_POSTGRESQL_SCHEMA + ]); + } + + /** + * Tests Postgresql::describeReferences + * + * @author Wojciech Ślawski + * @since 2016-09-28 + */ + public function testDescribeReferencesColumnsCount() + { + $this->specify( + 'Postgresql::describeReferences return wrong number of columns in Phalcon\Db\Reference', + function() { + $references = $this->connection->describeReferences("robots_parts", TEST_DB_POSTGRESQL_NAME); + /** @var Reference $reference */ + foreach($references as $reference) { + expect($reference->getColumns())->count(1); + } + } + ); + } +} \ No newline at end of file diff --git a/tests/unit/ValidationTest.php b/tests/unit/ValidationTest.php index 1a1e10025c0..19fb17f6f75 100644 --- a/tests/unit/ValidationTest.php +++ b/tests/unit/ValidationTest.php @@ -54,7 +54,7 @@ protected function _before() */ public function testWithEntityAndFilter() { - $this->specify('Tests validate method with entity and filters', function () { + $this->specify('Validation filters are not working with entity', function () { $users = new Users([ 'name' => ' ' ]); @@ -86,7 +86,7 @@ public function testWithEntityAndFilter() */ public function testFilteringEntity() { - $this->specify('Tests if validate method filters entity', function() { + $this->specify('Validation filters are not saving value to entity', function() { $users = new Users([ 'name' => 'SomeName ' ]);