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 @@
"doctrine/common": "^2.7.1"
},
"require-dev": {
"doctrine/coding-standard": "^1.0",
"phpunit/phpunit": "^6.3",
"phpunit/phpunit-mock-objects": "!=3.2.4,!=3.2.5",
"squizlabs/php_codesniffer": "^3.0",
"symfony/console": "2.*||^3.0",
"doctrine/coding-standard": "^1.0",
"squizlabs/php_codesniffer": "^3.0"
"symfony/phpunit-bridge": "^3.3"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
},
"bin": ["bin/doctrine-dbal"],
"config": {
"sort-packages": true
},
"autoload": {
"psr-0": { "Doctrine\\DBAL\\": "lib/" }
},
......
......@@ -118,9 +118,17 @@ class Column extends AbstractAsset
{
foreach ($options as $name => $value) {
$method = "set".$name;
if (method_exists($this, $method)) {
$this->$method($value);
if ( ! method_exists($this, $method)) {
// 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;
......
......@@ -238,7 +238,6 @@ class OracleSchemaManager extends AbstractSchemaManager
'comment' => isset($tableColumn['comments']) && '' !== $tableColumn['comments']
? $tableColumn['comments']
: null,
'platformDetails' => [],
];
return new Column($this->getQuotedIdentifierName($tableColumn['column_name']), Type::getType($type), $options);
......
......@@ -427,7 +427,6 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
'length' => $length,
'notnull' => (bool) $tableColumn['isnotnull'],
'default' => $tableColumn['default'],
'primary' => (bool) ($tableColumn['pri'] == 't'),
'precision' => $precision,
'scale' => $scale,
'fixed' => $fixed,
......
......@@ -54,6 +54,7 @@
<listeners>
<listener class="Doctrine\Tests\DbalPerformanceTestListener"/>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<groups>
......
......@@ -132,8 +132,8 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
public function testDropPrimaryKeyWithAutoincrementColumn()
{
$table = new Table("drop_primary_key");
$table->addColumn('id', 'integer', array('primary' => true, 'autoincrement' => true));
$table->addColumn('foo', 'integer', array('primary' => true));
$table->addColumn('id', 'integer', array('autoincrement' => true));
$table->addColumn('foo', 'integer');
$table->setPrimaryKey(array('id', 'foo'));
$this->_sm->dropAndCreateTable($table);
......
......@@ -308,7 +308,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
{
$offlineTable = new Schema\Table('user');
$offlineTable->addColumn('id', 'integer');
$offlineTable->addColumn('username', 'string', array('unique' => true));
$offlineTable->addColumn('username', 'string');
$offlineTable->addColumn('fk', 'integer');
$offlineTable->setPrimaryKey(array('id'));
$offlineTable->addForeignKeyConstraint($offlineTable, array('fk'), array('id'));
......
......@@ -738,7 +738,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$tableDiff->fromTable = $table;
$tableDiff->changedColumns['id'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'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'),
new \Doctrine\DBAL\Schema\Column(
......@@ -948,7 +948,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
public function testColumnDefaultLifecycle()
{
$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('column2', 'string', array('default' => false));
$table->addColumn('column3', 'string', array('default' => true));
......
......@@ -2,6 +2,7 @@
namespace Doctrine\Tests\DBAL\Schema;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Types\Type;
......@@ -55,6 +56,15 @@ class ColumnTest extends \PHPUnit\Framework\TestCase
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
*/
......
......@@ -784,15 +784,15 @@ class ComparatorTest extends \PHPUnit\Framework\TestCase
{
$table = new \Doctrine\DBAL\Schema\Table('twitter_users');
$table->addColumn('id', 'integer', array('autoincrement' => true));
$table->addColumn('twitterId', 'integer', array('nullable' => false));
$table->addColumn('displayName', 'string', array('nullable' => false));
$table->addColumn('twitterId', 'integer');
$table->addColumn('displayName', 'string');
$table->setPrimaryKey(array('id'));
$newtable = new \Doctrine\DBAL\Schema\Table('twitter_users');
$newtable->addColumn('id', 'integer', array('autoincrement' => true));
$newtable->addColumn('twitter_id', 'integer', array('nullable' => false));
$newtable->addColumn('display_name', 'string', array('nullable' => false));
$newtable->addColumn('logged_in_at', 'datetime', array('nullable' => true));
$newtable->addColumn('twitter_id', 'integer');
$newtable->addColumn('display_name', 'string');
$newtable->addColumn('logged_in_at', 'datetime');
$newtable->setPrimaryKey(array('id'));
$c = new Comparator();
......
......@@ -32,6 +32,10 @@
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<groups>
<exclude>
<group>performance</group>
......
......@@ -30,6 +30,10 @@
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<groups>
<exclude>
<group>performance</group>
......
......@@ -30,6 +30,10 @@
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<groups>
<exclude>
<group>performance</group>
......
......@@ -30,6 +30,10 @@
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<groups>
<exclude>
<group>performance</group>
......
......@@ -30,6 +30,10 @@
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<groups>
<exclude>
<group>performance</group>
......
......@@ -17,6 +17,10 @@
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
<filter>
<whitelist>
<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