-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12263 from sergeyklay/db/column/has_default
Fixed Column::hasDefault
- Loading branch information
Showing
7 changed files
with
181 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,13 @@ | |
|
||
namespace Phalcon\Test\Unit\Db\Adapter\Pdo; | ||
|
||
use Phalcon\Db\Adapter\Pdo\Postgresql; | ||
use Phalcon\Db\Column; | ||
use Phalcon\Db\Reference; | ||
use Phalcon\Test\Module\UnitTest; | ||
use Phalcon\Db\Adapter\Pdo\Postgresql; | ||
|
||
/** | ||
* \Phalcon\Test\Unit\Db\Adapter\Pdo\Postgresql | ||
* \Phalcon\Test\Unit\Db\Adapter\Pdo\PostgresqlTest | ||
* Tests the \Phalcon\Db\Adapter\Pdo\Postgresql component | ||
* | ||
* @copyright (c) 2011-2016 Phalcon Team | ||
|
@@ -54,14 +55,73 @@ public function _before() | |
public function testDescribeReferencesColumnsCount() | ||
{ | ||
$this->specify( | ||
'Postgresql::describeReferences return wrong number of columns in Phalcon\Db\Reference', | ||
'The table references list contains wrong number of columns', | ||
function() { | ||
$references = $this->connection->describeReferences("robots_parts", TEST_DB_POSTGRESQL_NAME); | ||
$references = $this->connection->describeReferences('robots_parts', TEST_DB_POSTGRESQL_SCHEMA); | ||
expect($references)->count(2); | ||
|
||
/** @var Reference $reference */ | ||
foreach($references as $reference) { | ||
expect($reference->getColumns())->count(1); | ||
} | ||
} | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Tests Postgresql::describeColumns for Postgresql autoincrement column | ||
* | ||
* @issue https://github.com/phalcon/phalcon-devtools/issues/853 | ||
* @author Serghei Iakovlev <[email protected]> | ||
* @since 2016-09-28 | ||
*/ | ||
public function testDescribeAutoIncrementColumns() | ||
{ | ||
$this->specify( | ||
'The table columns array contains incorrect initialized objects', | ||
function () { | ||
$columns = [ | ||
Column::__set_state([ | ||
'_columnName' => 'id', | ||
'_schemaName' => null, | ||
'_type' => 14, | ||
'_typeReference' => -1, | ||
'_typeValues' => null, | ||
'_isNumeric' => true, | ||
'_size' => 0, | ||
'_scale' => 0, | ||
'_default' => "nextval('images_id_seq'::regclass)", | ||
'_unsigned' => false, | ||
'_notNull' => true, | ||
'_primary' => false, | ||
'_autoIncrement' => true, | ||
'_first' => true, | ||
'_after' => null, | ||
'_bindType' => 1, | ||
]), | ||
Column::__set_state([ | ||
'_columnName' => 'base64', | ||
'_schemaName' => null, | ||
'_type' => 6, | ||
'_typeReference' => -1, | ||
'_typeValues' => null, | ||
'_isNumeric' => false, | ||
'_size' => null, | ||
'_scale' => 0, | ||
'_default' => null, | ||
'_unsigned' => false, | ||
'_notNull' => false, | ||
'_primary' => false, | ||
'_autoIncrement' => false, | ||
'_first' => false, | ||
'_after' => 'id', | ||
'_bindType' => 2, | ||
]), | ||
]; | ||
|
||
expect($this->connection->describeColumns('images', null))->equals($columns); | ||
expect($this->connection->describeColumns('images', TEST_DB_POSTGRESQL_SCHEMA))->equals($columns); | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Phalcon\Test\Unit\Db\Column; | ||
|
||
use Phalcon\Db\Column; | ||
use Phalcon\Test\Module\UnitTest; | ||
|
||
/** | ||
* \Phalcon\Test\Unit\Db\Column\PostgresqlTest | ||
* Tests the \Phalcon\Db\Column component | ||
* | ||
* @copyright (c) 2011-2016 Phalcon Team | ||
* @link https://www.phalconphp.com | ||
* @author Andres Gutierrez <[email protected]> | ||
* @author Serghei Iakovlev <[email protected]> | ||
* @package Phalcon\Test\Unit\Db\Column | ||
* | ||
* 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 [email protected] | ||
* so that we can send you a copy immediately. | ||
*/ | ||
class PostgresqlTest extends UnitTest | ||
{ | ||
/** | ||
* Tests Postgresql::hasDefault for autoincrement fields | ||
* | ||
* @issue https://github.com/phalcon/phalcon-devtools/issues/853 | ||
* @author Serghei Iakovlev <[email protected]> | ||
* @since 2016-09-28 | ||
*/ | ||
public function testHasAutoIncrementDefault() | ||
{ | ||
$this->specify( | ||
'The autoincrement column has default value', | ||
function () { | ||
$column = Column::__set_state([ | ||
'_columnName' => 'id', | ||
'_schemaName' => null, | ||
'_type' => 14, | ||
'_typeReference' => -1, | ||
'_typeValues' => null, | ||
'_isNumeric' => true, | ||
'_size' => 0, | ||
'_scale' => 0, | ||
'_default' => "nextval('images_id_seq'::regclass)", | ||
'_unsigned' => false, | ||
'_notNull' => true, | ||
'_primary' => false, | ||
'_autoIncrement' => true, | ||
'_first' => true, | ||
'_after' => null, | ||
'_bindType' => 1, | ||
]); | ||
|
||
expect($column->hasDefault())->false(); | ||
expect($column->isAutoIncrement())->true(); | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters