Unverified Commit 6ed32a9a authored by Michael Moravec's avatar Michael Moravec Committed by Sergei Morozov

Remove deprecated json_array type

parent d89cf163
# Upgrade to 3.0 # Upgrade to 3.0
## BC BREAK Removed previously deprecated features
* Removed `json_array` type and all associated hacks.
## BC BREAK changes the `Driver::connect()` signature ## BC BREAK changes the `Driver::connect()` signature
The method no longer accepts the `$username`, `$password` and `$driverOptions` arguments. The corresponding values are expected to be passed as the "user", "password" and "driver_options" keys of the `$params` argument respectively. The method no longer accepts the `$username`, `$password` and `$driverOptions` arguments. The corresponding values are expected to be passed as the "user", "password" and "driver_options" keys of the `$params` argument respectively.
......
...@@ -9,7 +9,6 @@ use function array_key_exists; ...@@ -9,7 +9,6 @@ use function array_key_exists;
use function array_keys; use function array_keys;
use function array_map; use function array_map;
use function array_merge; use function array_merge;
use function array_shift;
use function array_unique; use function array_unique;
use function assert; use function assert;
use function count; use function count;
...@@ -440,13 +439,6 @@ class Comparator ...@@ -440,13 +439,6 @@ class Comparator
$changedProperties[] = $property; $changedProperties[] = $property;
} }
// This is a very nasty hack to make comparator work with the legacy json_array type, which should be killed in v3
if ($this->isALegacyJsonComparison($properties1['type'], $properties2['type'])) {
array_shift($changedProperties);
$changedProperties[] = 'comment';
}
// Null values need to be checked additionally as they tell whether to create or drop a default value. // Null values need to be checked additionally as they tell whether to create or drop a default value.
// null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation. // null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation.
if ( if (
...@@ -514,21 +506,6 @@ class Comparator ...@@ -514,21 +506,6 @@ class Comparator
return array_unique($changedProperties); return array_unique($changedProperties);
} }
/**
* TODO: kill with fire on v3.0
*
* @deprecated
*/
private function isALegacyJsonComparison(Types\Type $one, Types\Type $other): bool
{
if (! $one instanceof Types\JsonType || ! $other instanceof Types\JsonType) {
return false;
}
return ( ! $one instanceof Types\JsonArrayType && $other instanceof Types\JsonArrayType)
|| ( ! $other instanceof Types\JsonArrayType && $one instanceof Types\JsonArrayType);
}
/** /**
* Finds the difference between the indexes $index1 and $index2. * Finds the difference between the indexes $index1 and $index2.
* *
......
...@@ -497,7 +497,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -497,7 +497,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$column->setPlatformOption('collation', $tableColumn['collation']); $column->setPlatformOption('collation', $tableColumn['collation']);
} }
if (in_array($column->getType()->getName(), [Types::JSON_ARRAY, Types::JSON], true)) { if ($column->getType()->getName() === Types::JSON) {
$column->setPlatformOption('jsonb', $jsonb); $column->setPlatformOption('jsonb', $jsonb);
} }
......
<?php
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use function is_resource;
use function json_decode;
use function stream_get_contents;
/**
* Array Type which can be used to generate json arrays.
*
* @deprecated Use JsonType instead
*/
class JsonArrayType extends JsonType
{
/**
* {@inheritdoc}
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null || $value === '') {
return [];
}
$value = is_resource($value) ? stream_get_contents($value) : $value;
return json_decode($value, true);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return Types::JSON_ARRAY;
}
/**
* {@inheritdoc}
*/
public function requiresSQLCommentHint(AbstractPlatform $platform)
{
return true;
}
}
...@@ -67,9 +67,6 @@ abstract class Type ...@@ -67,9 +67,6 @@ abstract class Type
/** @deprecated Use {@see Types::JSON} instead. */ /** @deprecated Use {@see Types::JSON} instead. */
public const JSON = Types::JSON; public const JSON = Types::JSON;
/** @deprecated Use {@see Types::JSON_ARRAY} instead. */
public const JSON_ARRAY = Types::JSON_ARRAY;
/** @deprecated Use {@see Types::OBJECT} instead. */ /** @deprecated Use {@see Types::OBJECT} instead. */
public const OBJECT = Types::OBJECT; public const OBJECT = Types::OBJECT;
...@@ -115,7 +112,6 @@ abstract class Type ...@@ -115,7 +112,6 @@ abstract class Type
Types::GUID => GuidType::class, Types::GUID => GuidType::class,
Types::INTEGER => IntegerType::class, Types::INTEGER => IntegerType::class,
Types::JSON => JsonType::class, Types::JSON => JsonType::class,
Types::JSON_ARRAY => JsonArrayType::class,
Types::OBJECT => ObjectType::class, Types::OBJECT => ObjectType::class,
Types::SIMPLE_ARRAY => SimpleArrayType::class, Types::SIMPLE_ARRAY => SimpleArrayType::class,
Types::SMALLINT => SmallIntType::class, Types::SMALLINT => SmallIntType::class,
......
...@@ -403,10 +403,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -403,10 +403,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self::assertSame('(id IS NULL)', $onlineTable->getIndex('simple_partial_index')->getOption('where')); self::assertSame('(id IS NULL)', $onlineTable->getIndex('simple_partial_index')->getOption('where'));
} }
/** public function testJsonbColumn(): void
* @dataProvider jsonbColumnTypeProvider
*/
public function testJsonbColumn(string $type): void
{ {
if (! $this->schemaManager->getDatabasePlatform() instanceof PostgreSQL94Platform) { if (! $this->schemaManager->getDatabasePlatform() instanceof PostgreSQL94Platform) {
$this->markTestSkipped('Requires PostgresSQL 9.4+'); $this->markTestSkipped('Requires PostgresSQL 9.4+');
...@@ -415,26 +412,15 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -415,26 +412,15 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
} }
$table = new Schema\Table('test_jsonb'); $table = new Schema\Table('test_jsonb');
$table->addColumn('foo', $type)->setPlatformOption('jsonb', true); $table->addColumn('foo', Types::JSON)->setPlatformOption('jsonb', true);
$this->schemaManager->dropAndCreateTable($table); $this->schemaManager->dropAndCreateTable($table);
$columns = $this->schemaManager->listTableColumns('test_jsonb'); $columns = $this->schemaManager->listTableColumns('test_jsonb');
self::assertSame($type, $columns['foo']->getType()->getName()); self::assertSame(Types::JSON, $columns['foo']->getType()->getName());
self::assertTrue(true, $columns['foo']->getPlatformOption('jsonb')); self::assertTrue(true, $columns['foo']->getPlatformOption('jsonb'));
} }
/**
* @return mixed[][]
*/
public function jsonbColumnTypeProvider(): array
{
return [
[Types::JSON],
[Types::JSON_ARRAY],
];
}
/** /**
* @group DBAL-2427 * @group DBAL-2427
*/ */
......
...@@ -1309,129 +1309,6 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase ...@@ -1309,129 +1309,6 @@ abstract class SchemaManagerFunctionalTestCase extends FunctionalTestCase
self::assertArrayHasKey('idx_3d6c147fdc58d6c', $indexes); self::assertArrayHasKey('idx_3d6c147fdc58d6c', $indexes);
} }
/**
* @after
*/
public function removeJsonArrayTable(): void
{
if (! $this->schemaManager->tablesExist(['json_array_test'])) {
return;
}
$this->schemaManager->dropTable('json_array_test');
}
/**
* @group 2782
* @group 6654
*/
public function testComparatorShouldReturnFalseWhenLegacyJsonArrayColumnHasComment(): void
{
$table = new Table('json_array_test');
$table->addColumn('parameters', 'json_array');
$this->schemaManager->createTable($table);
$comparator = new Comparator();
$tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table);
self::assertFalse($tableDiff);
}
/**
* @group 2782
* @group 6654
*/
public function testComparatorShouldModifyOnlyTheCommentWhenUpdatingFromJsonArrayTypeOnLegacyPlatforms(): void
{
if ($this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) {
$this->markTestSkipped('This test is only supported on platforms that do not have native JSON type.');
}
$table = new Table('json_array_test');
$table->addColumn('parameters', 'json_array');
$this->schemaManager->createTable($table);
$table = new Table('json_array_test');
$table->addColumn('parameters', 'json');
$comparator = new Comparator();
$tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table);
self::assertInstanceOf(TableDiff::class, $tableDiff);
$changedColumn = $tableDiff->changedColumns['parameters'] ?? $tableDiff->changedColumns['PARAMETERS'];
self::assertSame(['comment'], $changedColumn->changedProperties);
}
/**
* @group 2782
* @group 6654
*/
public function testComparatorShouldAddCommentToLegacyJsonArrayTypeThatDoesNotHaveIt(): void
{
if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) {
$this->markTestSkipped('This test is only supported on platforms that have native JSON type.');
}
$this->connection->executeQuery('CREATE TABLE json_array_test (parameters JSON NOT NULL)');
$table = new Table('json_array_test');
$table->addColumn('parameters', 'json_array');
$comparator = new Comparator();
$tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table);
self::assertInstanceOf(TableDiff::class, $tableDiff);
self::assertSame(['comment'], $tableDiff->changedColumns['parameters']->changedProperties);
}
/**
* @group 2782
* @group 6654
*/
public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayType(): void
{
if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) {
$this->markTestSkipped('This test is only supported on platforms that have native JSON type.');
}
$this->connection->executeQuery('CREATE TABLE json_array_test (parameters JSON DEFAULT NULL)');
$table = new Table('json_array_test');
$table->addColumn('parameters', 'json_array');
$comparator = new Comparator();
$tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table);
self::assertInstanceOf(TableDiff::class, $tableDiff);
self::assertSame(['notnull', 'comment'], $tableDiff->changedColumns['parameters']->changedProperties);
}
/**
* @group 2782
* @group 6654
*/
public function testComparatorShouldReturnAllChangesWhenUsingLegacyJsonArrayTypeEvenWhenPlatformHasJsonSupport(): void
{
if (! $this->schemaManager->getDatabasePlatform()->hasNativeJsonType()) {
$this->markTestSkipped('This test is only supported on platforms that have native JSON type.');
}
$this->connection->executeQuery('CREATE TABLE json_array_test (parameters JSON DEFAULT NULL)');
$table = new Table('json_array_test');
$table->addColumn('parameters', 'json_array');
$comparator = new Comparator();
$tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_array_test'), $table);
self::assertInstanceOf(TableDiff::class, $tableDiff);
self::assertSame(['notnull', 'comment'], $tableDiff->changedColumns['parameters']->changedProperties);
}
/** /**
* @group 2782 * @group 2782
* @group 6654 * @group 6654
......
...@@ -32,7 +32,7 @@ class TypeConversionTest extends FunctionalTestCase ...@@ -32,7 +32,7 @@ class TypeConversionTest extends FunctionalTestCase
$table->addColumn('test_time', 'time', ['notnull' => false]); $table->addColumn('test_time', 'time', ['notnull' => false]);
$table->addColumn('test_text', 'text', ['notnull' => false]); $table->addColumn('test_text', 'text', ['notnull' => false]);
$table->addColumn('test_array', 'array', ['notnull' => false]); $table->addColumn('test_array', 'array', ['notnull' => false]);
$table->addColumn('test_json_array', 'json_array', ['notnull' => false]); $table->addColumn('test_json', 'json', ['notnull' => false]);
$table->addColumn('test_object', 'object', ['notnull' => false]); $table->addColumn('test_object', 'object', ['notnull' => false]);
$table->addColumn('test_float', 'float', ['notnull' => false]); $table->addColumn('test_float', 'float', ['notnull' => false]);
$table->addColumn('test_decimal', 'decimal', ['notnull' => false, 'scale' => 2, 'precision' => 10]); $table->addColumn('test_decimal', 'decimal', ['notnull' => false, 'scale' => 2, 'precision' => 10]);
...@@ -165,7 +165,7 @@ class TypeConversionTest extends FunctionalTestCase ...@@ -165,7 +165,7 @@ class TypeConversionTest extends FunctionalTestCase
{ {
return [ return [
'array' => ['array', ['foo' => 'bar']], 'array' => ['array', ['foo' => 'bar']],
'json_array' => ['json_array', ['foo' => 'bar']], 'json' => ['json', ['foo' => 'bar']],
]; ];
} }
......
...@@ -857,7 +857,7 @@ abstract class AbstractPlatformTestCase extends TestCase ...@@ -857,7 +857,7 @@ abstract class AbstractPlatformTestCase extends TestCase
$column = [ $column = [
'length' => 666, 'length' => 666,
'notnull' => true, 'notnull' => true,
'type' => Type::getType('json_array'), 'type' => Type::getType('json'),
]; ];
self::assertSame( self::assertSame(
......
<?php
namespace Doctrine\DBAL\Tests\Types;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\JsonArrayType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use function base64_encode;
use function fopen;
use function json_encode;
class JsonArrayTest extends TestCase
{
/** @var AbstractPlatform|MockObject */
protected $platform;
/** @var JsonArrayType */
protected $type;
protected function setUp(): void
{
$this->platform = $this->createMock(AbstractPlatform::class);
$this->type = Type::getType('json_array');
}
public function testReturnsBindingType(): void
{
self::assertSame(ParameterType::STRING, $this->type->getBindingType());
}
public function testReturnsName(): void
{
self::assertSame(Types::JSON_ARRAY, $this->type->getName());
}
public function testReturnsSQLDeclaration(): void
{
$this->platform->expects(self::once())
->method('getJsonTypeDeclarationSQL')
->willReturn('TEST_JSON');
self::assertSame('TEST_JSON', $this->type->getSQLDeclaration([], $this->platform));
}
public function testJsonNullConvertsToPHPValue(): void
{
self::assertSame([], $this->type->convertToPHPValue(null, $this->platform));
}
public function testJsonEmptyStringConvertsToPHPValue(): void
{
self::assertSame([], $this->type->convertToPHPValue('', $this->platform));
}
public function testJsonStringConvertsToPHPValue(): void
{
$value = ['foo' => 'bar', 'bar' => 'foo'];
$databaseValue = json_encode($value);
$phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform);
self::assertEquals($value, $phpValue);
}
public function testJsonResourceConvertsToPHPValue(): void
{
$value = ['foo' => 'bar', 'bar' => 'foo'];
$databaseValue = fopen('data://text/plain;base64,' . base64_encode(json_encode($value)), 'r');
$phpValue = $this->type->convertToPHPValue($databaseValue, $this->platform);
self::assertSame($value, $phpValue);
}
public function testRequiresSQLCommentHint(): void
{
self::assertTrue($this->type->requiresSQLCommentHint($this->platform));
}
}
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