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
b0cc6692
Unverified
Commit
b0cc6692
authored
Sep 24, 2016
by
Guilherme Blanco
Committed by
Sergei Morozov
Nov 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed tests
parent
fe067f20
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
57 additions
and
55 deletions
+57
-55
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+7
-5
SqlitePlatform.php
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
+2
-3
Table.php
lib/Doctrine/DBAL/Schema/Table.php
+4
-4
UniqueConstraint.php
lib/Doctrine/DBAL/Schema/UniqueConstraint.php
+25
-25
AbstractPlatformTestCase.php
...octrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
+13
-13
AbstractSQLServerPlatformTestCase.php
...ests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
+1
-1
SQLAnywherePlatformTest.php
...Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
+5
-4
No files found.
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
b0cc6692
...
...
@@ -2387,15 +2387,17 @@ abstract class AbstractPlatform
throw
new
InvalidArgumentException
(
"Incomplete definition. 'columns' required."
);
}
$flags
=
''
;
$flags
=
[
'UNIQUE'
]
;
if
(
$constraint
->
hasFlag
(
'clustered'
))
{
$flags
=
'CLUSTERED
'
;
$flags
[]
=
'CLUSTERED
'
;
}
return
'CONSTRAINT '
.
$name
->
getQuotedName
(
$this
)
.
' UNIQUE '
.
$flags
.
' ('
.
$this
->
getIndexFieldDeclarationListSQL
(
$index
)
.
')'
;
$constraintName
=
$name
->
getQuotedName
(
$this
);
$constraintName
=
!
empty
(
$constraintName
)
?
$constraintName
.
' '
:
''
;
$columnListNames
=
$this
->
getIndexFieldDeclarationListSQL
(
$columns
);
return
sprintf
(
'CONSTRAINT %s%s (%s)'
,
$constraintName
,
implode
(
' '
,
$flags
),
$columnListNames
);
}
/**
...
...
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
View file @
b0cc6692
...
...
@@ -391,8 +391,7 @@ class SqlitePlatform extends AbstractPlatform
{
return
$fixed
?
(
$length
?
'CHAR('
.
$length
.
')'
:
'CHAR(255)'
)
:
(
$length
?
'VARCHAR('
.
$length
.
')'
:
'TEXT'
)
;
:
(
$length
?
'VARCHAR('
.
$length
.
')'
:
'TEXT'
);
}
/**
...
...
lib/Doctrine/DBAL/Schema/Table.php
View file @
b0cc6692
...
...
@@ -123,12 +123,12 @@ class Table extends AbstractAsset
/**
* @param mixed[] $columnNames
* @param string|null $indexName
* @param
array
$flags
* @param
string[]
$flags
* @param mixed[] $options
*
* @return self
*/
public
function
addUniqueConstraint
(
array
$columnNames
,
$indexName
=
null
,
array
$flags
=
array
()
,
array
$options
=
[])
public
function
addUniqueConstraint
(
array
$columnNames
,
$indexName
=
null
,
array
$flags
=
[]
,
array
$options
=
[])
{
if
(
$indexName
===
null
)
{
$indexName
=
$this
->
_generateIdentifierName
(
...
...
@@ -981,13 +981,13 @@ class Table extends AbstractAsset
* @param mixed[] $columns
* @param string $indexName
* @param mixed[] $flags
* @param
array
$options
* @param
mixed[]
$options
*
* @return UniqueConstraint
*
* @throws SchemaException
*/
private
function
_createUniqueConstraint
(
array
$columns
,
$indexName
,
array
$flags
=
array
()
,
array
$options
=
[])
private
function
_createUniqueConstraint
(
array
$columns
,
$indexName
,
array
$flags
=
[]
,
array
$options
=
[])
{
if
(
preg_match
(
'(([^a-zA-Z0-9_]+))'
,
$this
->
normalizeIdentifier
(
$indexName
)))
{
throw
SchemaException
::
indexNameInvalid
(
$indexName
);
...
...
lib/Doctrine/DBAL/Schema/UniqueConstraint.php
View file @
b0cc6692
...
...
@@ -26,9 +26,9 @@ class UniqueConstraint extends AbstractAsset implements Constraint
* Platform specific flags
* array($flagName => true)
*
* @var
array
* @var
true[]
*/
protected
$flags
=
array
()
;
protected
$flags
=
[]
;
/**
* Platform specific options
...
...
@@ -40,10 +40,10 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/**
* @param string $indexName
* @param string[] $columns
* @param
array
$flags
* @param
string[]
$flags
* @param mixed[] $options
*/
public
function
__construct
(
$indexName
,
array
$columns
,
array
$flags
=
array
()
,
array
$options
=
[])
public
function
__construct
(
$indexName
,
array
$columns
,
array
$flags
=
[]
,
array
$options
=
[])
{
$this
->
_setName
(
$indexName
);
...
...
@@ -58,28 +58,12 @@ class UniqueConstraint extends AbstractAsset implements Constraint
}
}
/**
* @param string $column
*
* @return void
*
* @throws InvalidArgumentException
*/
protected
function
_addColumn
(
$column
)
{
if
(
!
is_string
(
$column
))
{
throw
new
InvalidArgumentException
(
'Expecting a string as Index Column'
);
}
$this
->
_columns
[
$column
]
=
new
Identifier
(
$column
);
}
/**
* {@inheritdoc}
*/
public
function
getColumns
()
{
return
array_keys
(
$this
->
_
columns
);
return
array_keys
(
$this
->
columns
);
}
/**
...
...
@@ -89,7 +73,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint
{
$columns
=
[];
foreach
(
$this
->
_
columns
as
$column
)
{
foreach
(
$this
->
columns
as
$column
)
{
$columns
[]
=
$column
->
getQuotedName
(
$platform
);
}
...
...
@@ -117,11 +101,11 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/**
* Adds flag for a unique constraint that translates to platform specific handling.
*
* @example $uniqueConstraint->addFlag('CLUSTERED')
*
* @param string $flag
*
* @return self
*
* @example $uniqueConstraint->addFlag('CLUSTERED')
*/
public
function
addFlag
(
$flag
)
{
...
...
@@ -135,7 +119,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint
*
* @param string $flag
*
* @return bool
ean
* @return bool
*/
public
function
hasFlag
(
$flag
)
{
...
...
@@ -181,4 +165,20 @@ class UniqueConstraint extends AbstractAsset implements Constraint
{
return
$this
->
options
;
}
/**
* @param string $column
*
* @return void
*
* @throws InvalidArgumentException
*/
protected
function
_addColumn
(
$column
)
{
if
(
!
is_string
(
$column
))
{
throw
new
InvalidArgumentException
(
'Expecting a string as Index Column'
);
}
$this
->
columns
[
$column
]
=
new
Identifier
(
$column
);
}
}
tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
View file @
b0cc6692
...
...
@@ -14,6 +14,7 @@ use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Schema\UniqueConstraint
;
use
Doctrine\DBAL\Types\Type
;
use
Doctrine\Tests\DbalTestCase
;
use
Doctrine\Tests\Types\CommentedType
;
...
...
@@ -220,7 +221,7 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
{
$where
=
'test IS NULL AND test2 IS NOT NULL'
;
$indexDef
=
new
Index
(
'name'
,
[
'test'
,
'test2'
],
false
,
false
,
[],
[
'where'
=>
$where
]);
$unique
Index
=
new
Index
(
'name'
,
[
'test'
,
'test2'
],
true
,
false
,
[],
[
'where'
=>
$where
]);
$unique
Constraint
=
new
UniqueConstraint
(
'name'
,
[
'test'
,
'test2'
],
[],
[
]);
$expected
=
' WHERE '
.
$where
;
...
...
@@ -230,15 +231,14 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
$actuals
[]
=
$this
->
platform
->
getIndexDeclarationSQL
(
'name'
,
$indexDef
);
}
$
actuals
[]
=
$this
->
platform
->
getUniqueConstraintDeclarationSQL
(
'name'
,
$uniqueIndex
);
$
actuals
[]
=
$this
->
platform
->
getCreateIndexSQL
(
$indexDef
,
'table'
);
$
uniqueConstraintSQL
=
$this
->
platform
->
getUniqueConstraintDeclarationSQL
(
'name'
,
$uniqueConstraint
);
$
indexSQL
=
$this
->
platform
->
getCreateIndexSQL
(
$indexDef
,
'table'
);
foreach
(
$actuals
as
$actual
)
{
$this
->
assertStringEndsNotWith
(
$expected
,
$uniqueConstraintSQL
,
'WHERE clause should NOT be present'
);
if
(
$this
->
platform
->
supportsPartialIndexes
())
{
self
::
assertStringEndsWith
(
$expected
,
$actual
,
'WHERE clause should be present'
);
self
::
assertStringEndsWith
(
$expected
,
$indexSQL
,
'WHERE clause should be present'
);
}
else
{
self
::
assertStringEndsNotWith
(
$expected
,
$actual
,
'WHERE clause should NOT be present'
);
}
self
::
assertStringEndsNotWith
(
$expected
,
$indexSQL
,
'WHERE clause should NOT be present'
);
}
}
...
...
@@ -731,11 +731,11 @@ abstract class AbstractPlatformTestCase extends DbalTestCase
*/
public
function
testQuotesReservedKeywordInUniqueConstraintDeclarationSQL
()
:
void
{
$
index
=
new
Index
(
'select'
,
[
'foo'
],
true
);
$
constraint
=
new
UniqueConstraint
(
'select'
,
[
'foo'
],
[],
[]
);
self
::
assertSame
(
$this
->
getQuotesReservedKeywordInUniqueConstraintDeclarationSQL
(),
$this
->
platform
->
getUniqueConstraintDeclarationSQL
(
'select'
,
$
index
)
$this
->
platform
->
getUniqueConstraintDeclarationSQL
(
'select'
,
$
constraint
)
);
}
...
...
tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php
View file @
b0cc6692
...
...
@@ -1416,7 +1416,7 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
*/
protected
function
getQuotesReservedKeywordInUniqueConstraintDeclarationSQL
()
:
string
{
return
'CONSTRAINT [select] UNIQUE (foo)
WHERE foo IS NOT NULL
'
;
return
'CONSTRAINT [select] UNIQUE (foo)'
;
}
/**
...
...
tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
View file @
b0cc6692
...
...
@@ -15,6 +15,7 @@ use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use
Doctrine\DBAL\Schema\Index
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\DBAL\Schema\TableDiff
;
use
Doctrine\DBAL\Schema\UniqueConstraint
;
use
Doctrine\DBAL\TransactionIsolationLevel
;
use
Doctrine\DBAL\Types\Type
;
use
InvalidArgumentException
;
...
...
@@ -391,12 +392,12 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
'CONSTRAINT unique_constraint UNIQUE CLUSTERED (a, b)'
,
$this
->
platform
->
getUniqueConstraintDeclarationSQL
(
'unique_constraint'
,
new
Index
(
null
,
[
'a'
,
'b'
],
true
,
false
,
[
'clustered'
])
new
UniqueConstraint
(
null
,
[
'a'
,
'b'
]
,
[
'clustered'
])
)
);
self
::
assertEquals
(
'UNIQUE (a, b)'
,
$this
->
platform
->
getUniqueConstraintDeclarationSQL
(
null
,
new
Index
(
null
,
[
'a'
,
'b'
],
true
,
false
))
'
CONSTRAINT
UNIQUE (a, b)'
,
$this
->
platform
->
getUniqueConstraintDeclarationSQL
(
null
,
new
UniqueConstraint
(
null
,
[
'a'
,
'b'
]
))
);
}
...
...
@@ -404,7 +405,7 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
{
$this
->
expectException
(
InvalidArgumentException
::
class
);
$this
->
platform
->
getUniqueConstraintDeclarationSQL
(
'constr'
,
new
Index
(
'constr'
,
[],
true
));
$this
->
platform
->
getUniqueConstraintDeclarationSQL
(
'constr'
,
new
UniqueConstraint
(
'constr'
,
[]
));
}
public
function
testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL
()
:
void
...
...
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