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
d19fa868
Commit
d19fa868
authored
Dec 30, 2019
by
Benjamin Morel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move FK exception tests to their own class
parent
f37a88ed
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
120 additions
and
179 deletions
+120
-179
ExceptionTest.php
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
+0
-179
ForeignKeyExceptionTest.php
...octrine/Tests/DBAL/Functional/ForeignKeyExceptionTest.php
+120
-0
No files found.
tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php
View file @
d19fa868
...
...
@@ -14,7 +14,6 @@ use Doctrine\DBAL\Platforms\SqlitePlatform;
use
Doctrine\DBAL\Schema\Schema
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\Tests\DbalFunctionalTestCase
;
use
Throwable
;
use
const
PHP_OS
;
use
function
array_merge
;
use
function
assert
;
...
...
@@ -76,158 +75,6 @@ class ExceptionTest extends DbalFunctionalTestCase
$schemaManager
->
createTable
(
$table
);
}
public
function
testForeignKeyConstraintViolationExceptionOnInsert
()
:
void
{
$platform
=
$this
->
connection
->
getDatabasePlatform
();
if
(
$platform
instanceof
SqlitePlatform
)
{
$this
->
connection
->
exec
(
'PRAGMA foreign_keys = ON'
);
}
elseif
(
!
$platform
->
supportsForeignKeyConstraints
())
{
$this
->
markTestSkipped
(
'Only fails on platforms with foreign key constraints.'
);
}
$this
->
setUpForeignKeyConstraintViolationExceptionTest
();
try
{
$this
->
connection
->
insert
(
'constraint_error_table'
,
[
'id'
=>
1
]);
$this
->
connection
->
insert
(
'owning_table'
,
[
'id'
=>
1
,
'constraint_id'
=>
1
]);
}
catch
(
Throwable
$exception
)
{
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
throw
$exception
;
}
$this
->
expectException
(
Exception\ForeignKeyConstraintViolationException
::
class
);
try
{
$this
->
connection
->
insert
(
'owning_table'
,
[
'id'
=>
2
,
'constraint_id'
=>
2
]);
}
catch
(
Exception\ForeignKeyConstraintViolationException
$exception
)
{
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
throw
$exception
;
}
catch
(
Throwable
$exception
)
{
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
throw
$exception
;
}
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
}
public
function
testForeignKeyConstraintViolationExceptionOnUpdate
()
:
void
{
$platform
=
$this
->
connection
->
getDatabasePlatform
();
if
(
$platform
instanceof
SqlitePlatform
)
{
$this
->
connection
->
exec
(
'PRAGMA foreign_keys = ON'
);
}
elseif
(
!
$platform
->
supportsForeignKeyConstraints
())
{
$this
->
markTestSkipped
(
'Only fails on platforms with foreign key constraints.'
);
}
$this
->
setUpForeignKeyConstraintViolationExceptionTest
();
try
{
$this
->
connection
->
insert
(
'constraint_error_table'
,
[
'id'
=>
1
]);
$this
->
connection
->
insert
(
'owning_table'
,
[
'id'
=>
1
,
'constraint_id'
=>
1
]);
}
catch
(
Throwable
$exception
)
{
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
throw
$exception
;
}
$this
->
expectException
(
Exception\ForeignKeyConstraintViolationException
::
class
);
try
{
$this
->
connection
->
update
(
'constraint_error_table'
,
[
'id'
=>
2
],
[
'id'
=>
1
]);
}
catch
(
Exception\ForeignKeyConstraintViolationException
$exception
)
{
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
throw
$exception
;
}
catch
(
Throwable
$exception
)
{
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
throw
$exception
;
}
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
}
public
function
testForeignKeyConstraintViolationExceptionOnDelete
()
:
void
{
$platform
=
$this
->
connection
->
getDatabasePlatform
();
if
(
$platform
instanceof
SqlitePlatform
)
{
$this
->
connection
->
exec
(
'PRAGMA foreign_keys = ON'
);
}
elseif
(
!
$platform
->
supportsForeignKeyConstraints
())
{
$this
->
markTestSkipped
(
'Only fails on platforms with foreign key constraints.'
);
}
$this
->
setUpForeignKeyConstraintViolationExceptionTest
();
try
{
$this
->
connection
->
insert
(
'constraint_error_table'
,
[
'id'
=>
1
]);
$this
->
connection
->
insert
(
'owning_table'
,
[
'id'
=>
1
,
'constraint_id'
=>
1
]);
}
catch
(
Throwable
$exception
)
{
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
throw
$exception
;
}
$this
->
expectException
(
Exception\ForeignKeyConstraintViolationException
::
class
);
try
{
$this
->
connection
->
delete
(
'constraint_error_table'
,
[
'id'
=>
1
]);
}
catch
(
Exception\ForeignKeyConstraintViolationException
$exception
)
{
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
throw
$exception
;
}
catch
(
Throwable
$exception
)
{
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
throw
$exception
;
}
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
}
public
function
testForeignKeyConstraintViolationExceptionOnTruncate
()
:
void
{
$platform
=
$this
->
connection
->
getDatabasePlatform
();
if
(
$platform
instanceof
SqlitePlatform
)
{
$this
->
connection
->
exec
(
'PRAGMA foreign_keys = ON'
);
}
elseif
(
!
$platform
->
supportsForeignKeyConstraints
())
{
$this
->
markTestSkipped
(
'Only fails on platforms with foreign key constraints.'
);
}
$this
->
setUpForeignKeyConstraintViolationExceptionTest
();
try
{
$this
->
connection
->
insert
(
'constraint_error_table'
,
[
'id'
=>
1
]);
$this
->
connection
->
insert
(
'owning_table'
,
[
'id'
=>
1
,
'constraint_id'
=>
1
]);
}
catch
(
Throwable
$exception
)
{
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
throw
$exception
;
}
$this
->
expectException
(
Exception\ForeignKeyConstraintViolationException
::
class
);
try
{
$this
->
connection
->
executeUpdate
(
$platform
->
getTruncateTableSQL
(
'constraint_error_table'
));
}
catch
(
Exception\ForeignKeyConstraintViolationException
$exception
)
{
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
throw
$exception
;
}
catch
(
Throwable
$exception
)
{
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
throw
$exception
;
}
$this
->
tearDownForeignKeyConstraintViolationExceptionTest
();
}
public
function
testNotNullConstraintViolationException
()
:
void
{
$schema
=
new
Schema
();
...
...
@@ -413,32 +260,6 @@ EOT
];
}
private
function
setUpForeignKeyConstraintViolationExceptionTest
()
:
void
{
$schemaManager
=
$this
->
connection
->
getSchemaManager
();
$table
=
new
Table
(
'constraint_error_table'
);
$table
->
addColumn
(
'id'
,
'integer'
,
[]);
$table
->
setPrimaryKey
([
'id'
]);
$owningTable
=
new
Table
(
'owning_table'
);
$owningTable
->
addColumn
(
'id'
,
'integer'
,
[]);
$owningTable
->
addColumn
(
'constraint_id'
,
'integer'
,
[]);
$owningTable
->
setPrimaryKey
([
'id'
]);
$owningTable
->
addForeignKeyConstraint
(
$table
,
[
'constraint_id'
],
[
'id'
]);
$schemaManager
->
createTable
(
$table
);
$schemaManager
->
createTable
(
$owningTable
);
}
private
function
tearDownForeignKeyConstraintViolationExceptionTest
()
:
void
{
$schemaManager
=
$this
->
connection
->
getSchemaManager
();
$schemaManager
->
dropTable
(
'owning_table'
);
$schemaManager
->
dropTable
(
'constraint_error_table'
);
}
private
function
isLinuxRoot
()
:
bool
{
return
PHP_OS
===
'Linux'
&&
posix_getpwuid
(
posix_geteuid
())[
'name'
]
===
'root'
;
...
...
tests/Doctrine/Tests/DBAL/Functional/ForeignKeyExceptionTest.php
0 → 100644
View file @
d19fa868
<?php
declare
(
strict_types
=
1
);
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
use
Doctrine\DBAL\Exception
;
use
Doctrine\DBAL\Platforms\SqlitePlatform
;
use
Doctrine\DBAL\Schema\Table
;
use
Doctrine\Tests\DbalFunctionalTestCase
;
class
ForeignKeyExceptionTest
extends
DbalFunctionalTestCase
{
protected
function
setUp
()
:
void
{
parent
::
setUp
();
if
(
!
$this
->
connection
->
getDriver
()
instanceof
ExceptionConverterDriver
)
{
$this
->
markTestSkipped
(
'Driver does not support special exception handling.'
);
}
$schemaManager
=
$this
->
connection
->
getSchemaManager
();
$table
=
new
Table
(
'constraint_error_table'
);
$table
->
addColumn
(
'id'
,
'integer'
,
[]);
$table
->
setPrimaryKey
([
'id'
]);
$owningTable
=
new
Table
(
'owning_table'
);
$owningTable
->
addColumn
(
'id'
,
'integer'
,
[]);
$owningTable
->
addColumn
(
'constraint_id'
,
'integer'
,
[]);
$owningTable
->
setPrimaryKey
([
'id'
]);
$owningTable
->
addForeignKeyConstraint
(
$table
,
[
'constraint_id'
],
[
'id'
]);
$schemaManager
->
createTable
(
$table
);
$schemaManager
->
createTable
(
$owningTable
);
}
protected
function
tearDown
()
:
void
{
parent
::
tearDown
();
$schemaManager
=
$this
->
connection
->
getSchemaManager
();
$schemaManager
->
dropTable
(
'owning_table'
);
$schemaManager
->
dropTable
(
'constraint_error_table'
);
}
public
function
testForeignKeyConstraintViolationExceptionOnInsert
()
:
void
{
$platform
=
$this
->
connection
->
getDatabasePlatform
();
if
(
$platform
instanceof
SqlitePlatform
)
{
$this
->
connection
->
exec
(
'PRAGMA foreign_keys = ON'
);
}
elseif
(
!
$platform
->
supportsForeignKeyConstraints
())
{
$this
->
markTestSkipped
(
'Only fails on platforms with foreign key constraints.'
);
}
$this
->
connection
->
insert
(
'constraint_error_table'
,
[
'id'
=>
1
]);
$this
->
connection
->
insert
(
'owning_table'
,
[
'id'
=>
1
,
'constraint_id'
=>
1
]);
$this
->
expectException
(
Exception\ForeignKeyConstraintViolationException
::
class
);
$this
->
connection
->
insert
(
'owning_table'
,
[
'id'
=>
2
,
'constraint_id'
=>
2
]);
}
public
function
testForeignKeyConstraintViolationExceptionOnUpdate
()
:
void
{
$platform
=
$this
->
connection
->
getDatabasePlatform
();
if
(
$platform
instanceof
SqlitePlatform
)
{
$this
->
connection
->
exec
(
'PRAGMA foreign_keys = ON'
);
}
elseif
(
!
$platform
->
supportsForeignKeyConstraints
())
{
$this
->
markTestSkipped
(
'Only fails on platforms with foreign key constraints.'
);
}
$this
->
connection
->
insert
(
'constraint_error_table'
,
[
'id'
=>
1
]);
$this
->
connection
->
insert
(
'owning_table'
,
[
'id'
=>
1
,
'constraint_id'
=>
1
]);
$this
->
expectException
(
Exception\ForeignKeyConstraintViolationException
::
class
);
$this
->
connection
->
update
(
'constraint_error_table'
,
[
'id'
=>
2
],
[
'id'
=>
1
]);
}
public
function
testForeignKeyConstraintViolationExceptionOnDelete
()
:
void
{
$platform
=
$this
->
connection
->
getDatabasePlatform
();
if
(
$platform
instanceof
SqlitePlatform
)
{
$this
->
connection
->
exec
(
'PRAGMA foreign_keys = ON'
);
}
elseif
(
!
$platform
->
supportsForeignKeyConstraints
())
{
$this
->
markTestSkipped
(
'Only fails on platforms with foreign key constraints.'
);
}
$this
->
connection
->
insert
(
'constraint_error_table'
,
[
'id'
=>
1
]);
$this
->
connection
->
insert
(
'owning_table'
,
[
'id'
=>
1
,
'constraint_id'
=>
1
]);
$this
->
expectException
(
Exception\ForeignKeyConstraintViolationException
::
class
);
$this
->
connection
->
delete
(
'constraint_error_table'
,
[
'id'
=>
1
]);
}
public
function
testForeignKeyConstraintViolationExceptionOnTruncate
()
:
void
{
$platform
=
$this
->
connection
->
getDatabasePlatform
();
if
(
$platform
instanceof
SqlitePlatform
)
{
$this
->
connection
->
exec
(
'PRAGMA foreign_keys = ON'
);
}
elseif
(
!
$platform
->
supportsForeignKeyConstraints
())
{
$this
->
markTestSkipped
(
'Only fails on platforms with foreign key constraints.'
);
}
$this
->
connection
->
insert
(
'constraint_error_table'
,
[
'id'
=>
1
]);
$this
->
connection
->
insert
(
'owning_table'
,
[
'id'
=>
1
,
'constraint_id'
=>
1
]);
$this
->
expectException
(
Exception\ForeignKeyConstraintViolationException
::
class
);
$this
->
connection
->
executeUpdate
(
$platform
->
getTruncateTableSQL
(
'constraint_error_table'
));
}
}
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