Unverified Commit cb08c4dd authored by Marco Pivetta's avatar Marco Pivetta Committed by GitHub

Merge pull request #2846 from greg0ire/validate_options

Validate options
parents a4d7acdf e8209e08
...@@ -17,16 +17,20 @@ ...@@ -17,16 +17,20 @@
"doctrine/common": "^2.7.1" "doctrine/common": "^2.7.1"
}, },
"require-dev": { "require-dev": {
"doctrine/coding-standard": "^1.0",
"phpunit/phpunit": "^6.3", "phpunit/phpunit": "^6.3",
"phpunit/phpunit-mock-objects": "!=3.2.4,!=3.2.5", "phpunit/phpunit-mock-objects": "!=3.2.4,!=3.2.5",
"squizlabs/php_codesniffer": "^3.0",
"symfony/console": "2.*||^3.0", "symfony/console": "2.*||^3.0",
"doctrine/coding-standard": "^1.0", "symfony/phpunit-bridge": "^3.3"
"squizlabs/php_codesniffer": "^3.0"
}, },
"suggest": { "suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files." "symfony/console": "For helpful console commands such as SQL execution and import of files."
}, },
"bin": ["bin/doctrine-dbal"], "bin": ["bin/doctrine-dbal"],
"config": {
"sort-packages": true
},
"autoload": { "autoload": {
"psr-0": { "Doctrine\\DBAL\\": "lib/" } "psr-0": { "Doctrine\\DBAL\\": "lib/" }
}, },
......
...@@ -118,9 +118,17 @@ class Column extends AbstractAsset ...@@ -118,9 +118,17 @@ class Column extends AbstractAsset
{ {
foreach ($options as $name => $value) { foreach ($options as $name => $value) {
$method = "set".$name; $method = "set".$name;
if (method_exists($this, $method)) { if ( ! method_exists($this, $method)) {
$this->$method($value); // next major: throw an exception
@trigger_error(sprintf(
'The "%s" option is not supported,'.
' setting it is deprecated and will cause an error in 3.0',
$name
), E_USER_DEPRECATED);
return $this;
} }
$this->$method($value);
} }
return $this; return $this;
......
...@@ -238,7 +238,6 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -238,7 +238,6 @@ class OracleSchemaManager extends AbstractSchemaManager
'comment' => isset($tableColumn['comments']) && '' !== $tableColumn['comments'] 'comment' => isset($tableColumn['comments']) && '' !== $tableColumn['comments']
? $tableColumn['comments'] ? $tableColumn['comments']
: null, : null,
'platformDetails' => [],
]; ];
return new Column($this->getQuotedIdentifierName($tableColumn['column_name']), Type::getType($type), $options); return new Column($this->getQuotedIdentifierName($tableColumn['column_name']), Type::getType($type), $options);
......
...@@ -427,7 +427,6 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -427,7 +427,6 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
'length' => $length, 'length' => $length,
'notnull' => (bool) $tableColumn['isnotnull'], 'notnull' => (bool) $tableColumn['isnotnull'],
'default' => $tableColumn['default'], 'default' => $tableColumn['default'],
'primary' => (bool) ($tableColumn['pri'] == 't'),
'precision' => $precision, 'precision' => $precision,
'scale' => $scale, 'scale' => $scale,
'fixed' => $fixed, 'fixed' => $fixed,
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
<listeners> <listeners>
<listener class="Doctrine\Tests\DbalPerformanceTestListener"/> <listener class="Doctrine\Tests\DbalPerformanceTestListener"/>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners> </listeners>
<groups> <groups>
......
...@@ -132,8 +132,8 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -132,8 +132,8 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
public function testDropPrimaryKeyWithAutoincrementColumn() public function testDropPrimaryKeyWithAutoincrementColumn()
{ {
$table = new Table("drop_primary_key"); $table = new Table("drop_primary_key");
$table->addColumn('id', 'integer', array('primary' => true, 'autoincrement' => true)); $table->addColumn('id', 'integer', array('autoincrement' => true));
$table->addColumn('foo', 'integer', array('primary' => true)); $table->addColumn('foo', 'integer');
$table->setPrimaryKey(array('id', 'foo')); $table->setPrimaryKey(array('id', 'foo'));
$this->_sm->dropAndCreateTable($table); $this->_sm->dropAndCreateTable($table);
......
...@@ -308,7 +308,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -308,7 +308,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{ {
$offlineTable = new Schema\Table('user'); $offlineTable = new Schema\Table('user');
$offlineTable->addColumn('id', 'integer'); $offlineTable->addColumn('id', 'integer');
$offlineTable->addColumn('username', 'string', array('unique' => true)); $offlineTable->addColumn('username', 'string');
$offlineTable->addColumn('fk', 'integer'); $offlineTable->addColumn('fk', 'integer');
$offlineTable->setPrimaryKey(array('id')); $offlineTable->setPrimaryKey(array('id'));
$offlineTable->addForeignKeyConstraint($offlineTable, array('fk'), array('id')); $offlineTable->addForeignKeyConstraint($offlineTable, array('fk'), array('id'));
......
...@@ -738,7 +738,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -738,7 +738,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$tableDiff->fromTable = $table; $tableDiff->fromTable = $table;
$tableDiff->changedColumns['id'] = new \Doctrine\DBAL\Schema\ColumnDiff( $tableDiff->changedColumns['id'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'id', new \Doctrine\DBAL\Schema\Column( 'id', new \Doctrine\DBAL\Schema\Column(
'id', \Doctrine\DBAL\Types\Type::getType('integer'), array('primary' => true) 'id', \Doctrine\DBAL\Types\Type::getType('integer')
), ),
array('comment'), array('comment'),
new \Doctrine\DBAL\Schema\Column( new \Doctrine\DBAL\Schema\Column(
...@@ -948,7 +948,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -948,7 +948,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
public function testColumnDefaultLifecycle() public function testColumnDefaultLifecycle()
{ {
$table = new Table("col_def_lifecycle"); $table = new Table("col_def_lifecycle");
$table->addColumn('id', 'integer', array('primary' => true, 'autoincrement' => true)); $table->addColumn('id', 'integer', array('autoincrement' => true));
$table->addColumn('column1', 'string', array('default' => null)); $table->addColumn('column1', 'string', array('default' => null));
$table->addColumn('column2', 'string', array('default' => false)); $table->addColumn('column2', 'string', array('default' => false));
$table->addColumn('column3', 'string', array('default' => true)); $table->addColumn('column3', 'string', array('default' => true));
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Doctrine\Tests\DBAL\Schema; namespace Doctrine\Tests\DBAL\Schema;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
...@@ -55,6 +56,15 @@ class ColumnTest extends \PHPUnit\Framework\TestCase ...@@ -55,6 +56,15 @@ class ColumnTest extends \PHPUnit\Framework\TestCase
self::assertEquals($expected, $this->createColumn()->toArray()); self::assertEquals($expected, $this->createColumn()->toArray());
} }
/**
* @group legacy
* @expectedDeprecation The "unknown_option" option is not supported, setting it is deprecated and will cause an error in 3.0
*/
public function testSettingUnknownOptionIsStillSupported() : void
{
new Column('foo', $this->createMock(Type::class), ['unknown_option' => 'bar']);
}
/** /**
* @return Column * @return Column
*/ */
......
...@@ -784,15 +784,15 @@ class ComparatorTest extends \PHPUnit\Framework\TestCase ...@@ -784,15 +784,15 @@ class ComparatorTest extends \PHPUnit\Framework\TestCase
{ {
$table = new \Doctrine\DBAL\Schema\Table('twitter_users'); $table = new \Doctrine\DBAL\Schema\Table('twitter_users');
$table->addColumn('id', 'integer', array('autoincrement' => true)); $table->addColumn('id', 'integer', array('autoincrement' => true));
$table->addColumn('twitterId', 'integer', array('nullable' => false)); $table->addColumn('twitterId', 'integer');
$table->addColumn('displayName', 'string', array('nullable' => false)); $table->addColumn('displayName', 'string');
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
$newtable = new \Doctrine\DBAL\Schema\Table('twitter_users'); $newtable = new \Doctrine\DBAL\Schema\Table('twitter_users');
$newtable->addColumn('id', 'integer', array('autoincrement' => true)); $newtable->addColumn('id', 'integer', array('autoincrement' => true));
$newtable->addColumn('twitter_id', 'integer', array('nullable' => false)); $newtable->addColumn('twitter_id', 'integer');
$newtable->addColumn('display_name', 'string', array('nullable' => false)); $newtable->addColumn('display_name', 'string');
$newtable->addColumn('logged_in_at', 'datetime', array('nullable' => true)); $newtable->addColumn('logged_in_at', 'datetime');
$newtable->setPrimaryKey(array('id')); $newtable->setPrimaryKey(array('id'));
$c = new Comparator(); $c = new Comparator();
......
...@@ -32,6 +32,10 @@ ...@@ -32,6 +32,10 @@
</testsuite> </testsuite>
</testsuites> </testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<groups> <groups>
<exclude> <exclude>
<group>performance</group> <group>performance</group>
......
...@@ -30,6 +30,10 @@ ...@@ -30,6 +30,10 @@
</testsuite> </testsuite>
</testsuites> </testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<groups> <groups>
<exclude> <exclude>
<group>performance</group> <group>performance</group>
......
...@@ -30,6 +30,10 @@ ...@@ -30,6 +30,10 @@
</testsuite> </testsuite>
</testsuites> </testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<groups> <groups>
<exclude> <exclude>
<group>performance</group> <group>performance</group>
......
...@@ -30,6 +30,10 @@ ...@@ -30,6 +30,10 @@
</testsuite> </testsuite>
</testsuites> </testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<groups> <groups>
<exclude> <exclude>
<group>performance</group> <group>performance</group>
......
...@@ -30,6 +30,10 @@ ...@@ -30,6 +30,10 @@
</testsuite> </testsuite>
</testsuites> </testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<groups> <groups>
<exclude> <exclude>
<group>performance</group> <group>performance</group>
......
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
</testsuite> </testsuite>
</testsuites> </testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<filter> <filter>
<whitelist> <whitelist>
<directory suffix=".php">./../../lib/Doctrine</directory> <directory suffix=".php">./../../lib/Doctrine</directory>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment