Unverified Commit 0241134e authored by Grégoire Paris's avatar Grégoire Paris Committed by Grégoire Paris

Trigger a deprecation on unknown option

I am not sure if there is a rationale behind ignoring extra keys like
this. I was under the impression that something might copy options to
platform specific options, thus leaving options in the original array,
knowing they would be ignored anyway. If it is the case, it would be
best to just move them, otherwise, this commit might help troubleshoot
some mapping issues.
I had to fix some tests that wrongly used that options array (maybe
these options were valid at some point?).
parent 0b00d508
......@@ -21,7 +21,8 @@
"phpunit/phpunit": "^6.3",
"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",
"symfony/phpunit-bridge": "^3.3"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
......
......@@ -37,4 +37,9 @@ class InvalidArgumentException extends DBALException
{
return new self('Empty criteria was used, expected non-empty criteria');
}
public static function fromUnsupportedOption(string $name) : self
{
return new self(sprintf('The "%s" option is not supported', $name));
}
}
......@@ -19,6 +19,7 @@
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\Types\Type;
/**
......@@ -118,9 +119,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: use InvalidArgumentException::fromUnsupportedOption()
@trigger_error(sprintf(
'The "%s" option is not supported,'.
' setting it is deprecated and will cause an exception 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 exception 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