Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
8df6546f
Unverified
Commit
8df6546f
authored
Apr 15, 2019
by
Michael Moravec
Committed by
Sergei Morozov
Nov 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove deprecated json_array type
parent
ac2252d2
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
11 additions
and
305 deletions
+11
-305
UPGRADE.md
UPGRADE.md
+4
-0
Comparator.php
lib/Doctrine/DBAL/Schema/Comparator.php
+0
-23
PostgreSqlSchemaManager.php
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
+1
-1
JsonArrayType.php
lib/Doctrine/DBAL/Types/JsonArrayType.php
+0
-48
Type.php
lib/Doctrine/DBAL/Types/Type.php
+0
-4
PostgreSqlSchemaManagerTest.php
...ts/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
+3
-17
SchemaManagerFunctionalTestCase.php
...BAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
+0
-123
TypeConversionTest.php
tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php
+2
-2
AbstractPlatformTestCase.php
...octrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
+1
-1
JsonArrayTest.php
tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php
+0
-86
No files found.
UPGRADE.md
View file @
8df6546f
# Upgrade to 3.0
## BC BREAK Removed previously deprecated features
*
Removed
`json_array`
type and all associated hacks.
## BC BREAK `Connection::ping()` returns `void`.
`Connection::ping()`
and
`PingableConnection::ping()`
no longer return a boolean value. They will throw an exception in case of failure.
...
...
lib/Doctrine/DBAL/Schema/Comparator.php
View file @
8df6546f
...
...
@@ -10,7 +10,6 @@ use function array_key_exists;
use
function
array_keys
;
use
function
array_map
;
use
function
array_merge
;
use
function
array_shift
;
use
function
array_unique
;
use
function
assert
;
use
function
count
;
...
...
@@ -436,13 +435,6 @@ class Comparator
$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 != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation.
if
((
$properties1
[
'default'
]
===
null
)
!==
(
$properties2
[
'default'
]
===
null
)
...
...
@@ -505,21 +497,6 @@ class Comparator
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.
*
...
...
lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
View file @
8df6546f
...
...
@@ -458,7 +458,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
$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
);
}
...
...
lib/Doctrine/DBAL/Types/JsonArrayType.php
deleted
100644 → 0
View file @
ac2252d2
<?php
declare
(
strict_types
=
1
);
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
;
}
}
lib/Doctrine/DBAL/Types/Type.php
View file @
8df6546f
...
...
@@ -65,9 +65,6 @@ abstract class Type
/** @deprecated Use {@see DefaultTypes::JSON} instead. */
public
const
JSON
=
Types
::
JSON
;
/** @deprecated Use {@see DefaultTypes::JSON_ARRAY} instead. */
public
const
JSON_ARRAY
=
Types
::
JSON_ARRAY
;
/** @deprecated Use {@see DefaultTypes::OBJECT} instead. */
public
const
OBJECT
=
Types
::
OBJECT
;
...
...
@@ -113,7 +110,6 @@ abstract class Type
Types
::
GUID
=>
GuidType
::
class
,
Types
::
INTEGER
=>
IntegerType
::
class
,
Types
::
JSON
=>
JsonType
::
class
,
Types
::
JSON_ARRAY
=>
JsonArrayType
::
class
,
Types
::
OBJECT
=>
ObjectType
::
class
,
Types
::
SIMPLE_ARRAY
=>
SimpleArrayType
::
class
,
Types
::
SMALLINT
=>
SmallIntType
::
class
,
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php
View file @
8df6546f
...
...
@@ -386,10 +386,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self
::
assertSame
(
'(id IS NULL)'
,
$onlineTable
->
getIndex
(
'simple_partial_index'
)
->
getOption
(
'where'
));
}
/**
* @dataProvider jsonbColumnTypeProvider
*/
public
function
testJsonbColumn
(
string
$type
)
:
void
public
function
testJsonbColumn
()
:
void
{
if
(
!
$this
->
schemaManager
->
getDatabasePlatform
()
instanceof
PostgreSQL94Platform
)
{
$this
->
markTestSkipped
(
'Requires PostgresSQL 9.4+'
);
...
...
@@ -398,26 +395,15 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
}
$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
);
$columns
=
$this
->
schemaManager
->
listTableColumns
(
'test_jsonb'
);
self
::
assertSame
(
$type
,
$columns
[
'foo'
]
->
getType
()
->
getName
());
self
::
assertSame
(
Types
::
JSON
,
$columns
[
'foo'
]
->
getType
()
->
getName
());
self
::
assertTrue
(
$columns
[
'foo'
]
->
getPlatformOption
(
'jsonb'
));
}
/**
* @return mixed[][]
*/
public
function
jsonbColumnTypeProvider
()
:
array
{
return
[
[
Types
::
JSON
],
[
Types
::
JSON_ARRAY
],
];
}
/**
* @group DBAL-2427
*/
...
...
tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php
View file @
8df6546f
...
...
@@ -1311,129 +1311,6 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
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 6654
...
...
tests/Doctrine/Tests/DBAL/Functional/TypeConversionTest.php
View file @
8df6546f
...
...
@@ -33,7 +33,7 @@ class TypeConversionTest extends DbalFunctionalTestCase
$table
->
addColumn
(
'test_time'
,
'time'
,
[
'notnull'
=>
false
]);
$table
->
addColumn
(
'test_text'
,
'text'
,
[
'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_float'
,
'float'
,
[
'notnull'
=>
false
]);
$table
->
addColumn
(
'test_decimal'
,
'decimal'
,
[
'notnull'
=>
false
,
'scale'
=>
2
,
'precision'
=>
10
]);
...
...
@@ -166,7 +166,7 @@ class TypeConversionTest extends DbalFunctionalTestCase
{
return
[
'array'
=>
[
'array'
,
[
'foo'
=>
'bar'
]],
'json
_array'
=>
[
'json_array
'
,
[
'foo'
=>
'bar'
]],
'json
'
=>
[
'json
'
,
[
'foo'
=>
'bar'
]],
];
}
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
8df6546f
...
...
@@ -880,7 +880,7 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
$column
=
[
'length'
=>
666
,
'notnull'
=>
true
,
'type'
=>
Type
::
getType
(
'json
_array
'
),
'type'
=>
Type
::
getType
(
'json'
),
];
self
::
assertSame
(
...
...
tests/Doctrine/Tests/DBAL/Types/JsonArrayTest.php
deleted
100644 → 0
View file @
ac2252d2
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\Tests\DBAL\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
Doctrine\Tests\DbalTestCase
;
use
PHPUnit\Framework\MockObject\MockObject
;
use
function
base64_encode
;
use
function
fopen
;
use
function
json_encode
;
class
JsonArrayTest
extends
DbalTestCase
{
/** @var AbstractPlatform|MockObject */
protected
$platform
;
/** @var JsonArrayType */
protected
$type
;
/**
* {@inheritdoc}
*/
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
(
$this
->
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
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment