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
047d0ec3
Unverified
Commit
047d0ec3
authored
Jul 22, 2017
by
Marco Pivetta
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correcting mocking of `Throwable` implementations, which is impossible in bare PHPUnit
parent
4758f426
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
30 deletions
+88
-30
DBALExceptionTest.php
tests/Doctrine/Tests/DBAL/DBALExceptionTest.php
+27
-6
AbstractDriverTest.php
tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php
+61
-24
No files found.
tests/Doctrine/Tests/DBAL/DBALExceptionTest.php
View file @
047d0ec3
...
@@ -4,20 +4,41 @@ namespace Doctrine\Tests\DBAL;
...
@@ -4,20 +4,41 @@ namespace Doctrine\Tests\DBAL;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Exception\DriverException
;
use
Doctrine\DBAL\Exception\DriverException
;
use
Doctrine\DBAL\Driver\DriverException
as
InnerDriverException
;
use
Doctrine\Tests\DbalTestCase
;
use
Doctrine\DBAL\Driver
;
class
DBALExceptionTest
extends
\Doctrine\Tests\
DbalTestCase
class
DBALExceptionTest
extends
DbalTestCase
{
{
public
function
testDriverExceptionDuringQueryAcceptsBinaryData
()
public
function
testDriverExceptionDuringQueryAcceptsBinaryData
()
{
{
$driver
=
$this
->
createMock
(
'\Doctrine\DBAL\Driver'
);
/* @var $driver Driver */
$driver
=
$this
->
createMock
(
Driver
::
class
);
$e
=
DBALException
::
driverExceptionDuringQuery
(
$driver
,
new
\Exception
,
''
,
array
(
'ABC'
,
chr
(
128
)));
$e
=
DBALException
::
driverExceptionDuringQuery
(
$driver
,
new
\Exception
,
''
,
array
(
'ABC'
,
chr
(
128
)));
$this
->
assertContains
(
'with params ["ABC", "\x80"]'
,
$e
->
getMessage
());
$this
->
assertContains
(
'with params ["ABC", "\x80"]'
,
$e
->
getMessage
());
}
}
public
function
testAvoidOverWrappingOnDriverException
()
public
function
testAvoidOverWrappingOnDriverException
()
{
{
$driver
=
$this
->
createMock
(
'\Doctrine\DBAL\Driver'
);
/* @var $driver Driver */
$ex
=
new
DriverException
(
''
,
$this
->
createMock
(
'\Doctrine\DBAL\Driver\DriverException'
));
$driver
=
$this
->
createMock
(
Driver
::
class
);
$inner
=
new
class
extends
\Exception
implements
InnerDriverException
{
/**
* {@inheritDoc}
*/
public
function
getErrorCode
()
{
}
/**
* {@inheritDoc}
*/
public
function
getSQLState
()
{
}
};
$ex
=
new
DriverException
(
''
,
$inner
);
$e
=
DBALException
::
driverExceptionDuringQuery
(
$driver
,
$ex
,
''
);
$e
=
DBALException
::
driverExceptionDuringQuery
(
$driver
,
$ex
,
''
);
$this
->
assertSame
(
$ex
,
$e
);
$this
->
assertSame
(
$ex
,
$e
);
}
}
...
@@ -27,11 +48,11 @@ class DBALExceptionTest extends \Doctrine\Tests\DbalTestCase
...
@@ -27,11 +48,11 @@ class DBALExceptionTest extends \Doctrine\Tests\DbalTestCase
$url
=
'mysql://localhost'
;
$url
=
'mysql://localhost'
;
$exception
=
DBALException
::
driverRequired
(
$url
);
$exception
=
DBALException
::
driverRequired
(
$url
);
$this
->
assertInstanceOf
(
'Doctrine\DBAL\DBALException'
,
$exception
);
$this
->
assertInstanceOf
(
DBALException
::
class
,
$exception
);
$this
->
assertSame
(
$this
->
assertSame
(
sprintf
(
sprintf
(
"The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme "
.
"The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme "
.
"is given to DriverManager::getConnection(). Given URL: %s"
,
'is given to DriverManager::getConnection(). Given URL: %s'
,
$url
$url
),
),
$exception
->
getMessage
()
$exception
->
getMessage
()
...
...
tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php
View file @
047d0ec3
...
@@ -3,9 +3,11 @@
...
@@ -3,9 +3,11 @@
namespace
Doctrine\Tests\DBAL\Driver
;
namespace
Doctrine\Tests\DBAL\Driver
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver\DriverException
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
use
Doctrine\DBAL\Driver\ExceptionConverterDriver
;
use
Doctrine\DBAL\VersionAwarePlatformDriver
;
use
Doctrine\DBAL\VersionAwarePlatformDriver
;
use
Doctrine\Tests\DbalTestCase
;
use
Doctrine\Tests\DbalTestCase
;
use
Throwable
;
abstract
class
AbstractDriverTest
extends
DbalTestCase
abstract
class
AbstractDriverTest
extends
DbalTestCase
{
{
...
@@ -59,19 +61,29 @@ abstract class AbstractDriverTest extends DbalTestCase
...
@@ -59,19 +61,29 @@ abstract class AbstractDriverTest extends DbalTestCase
);
);
}
}
$driverException
=
$this
->
createMock
(
'Doctrine\DBAL\Driver\DriverException'
);
$driverException
=
new
class
extends
\Exception
implements
DriverException
{
$driverException
->
expects
(
$this
->
any
())
public
function
__construct
()
->
method
(
'getErrorCode'
)
{
->
will
(
$this
->
returnValue
(
'foo'
));
parent
::
__construct
(
'baz'
);
}
$driverException
->
expects
(
$this
->
any
())
/**
->
method
(
'getSQLState'
)
* {@inheritDoc}
->
will
(
$this
->
returnValue
(
'bar'
));
*/
public
function
getErrorCode
()
{
return
'foo'
;
}
$driverException
->
expects
(
$this
->
any
())
/**
->
method
(
'getMessage'
)
* {@inheritDoc}
->
will
(
$this
->
returnValue
(
'baz'
));
*/
public
function
getSQLState
()
{
return
'bar'
;
}
};
$data
[]
=
array
(
$driverException
,
self
::
EXCEPTION_DRIVER
);
$data
[]
=
array
(
$driverException
,
self
::
EXCEPTION_DRIVER
);
...
@@ -209,19 +221,44 @@ abstract class AbstractDriverTest extends DbalTestCase
...
@@ -209,19 +221,44 @@ abstract class AbstractDriverTest extends DbalTestCase
foreach
(
$this
->
getExceptionConversionData
()
as
$convertedExceptionClassName
=>
$errors
)
{
foreach
(
$this
->
getExceptionConversionData
()
as
$convertedExceptionClassName
=>
$errors
)
{
foreach
(
$errors
as
$error
)
{
foreach
(
$errors
as
$error
)
{
$driverException
=
$this
->
createMock
(
'Doctrine\DBAL\Driver\DriverException'
);
$driverException
=
new
class
($
error
[
0
],
$error
[
1
],
$error
[
2
])
extends
\Exception
implements
DriverException
{
/**
* @var mixed
*/
private
$errorCode
;
$driverException
->
expects
(
$this
->
any
())
/**
->
method
(
'getErrorCode'
)
* @var mixed
->
will
(
$this
->
returnValue
(
$error
[
0
]));
*/
private
$sqlState
;
public
function
__construct
(
$errorCode
,
$sqlState
,
$message
)
{
parent
::
__construct
(
$message
);
$driverException
->
expects
(
$this
->
any
())
$this
->
errorCode
=
$errorCode
;
->
method
(
'getSQLState'
)
$this
->
sqlState
=
$sqlState
;
->
will
(
$this
->
returnValue
(
$error
[
1
]));
}
/**
* {@inheritDoc}
*/
public
function
getErrorCode
()
{
return
$this
->
errorCode
;
}
$driverException
->
expects
(
$this
->
any
())
/**
->
method
(
'getMessage'
)
* {@inheritDoc}
->
will
(
$this
->
returnValue
(
$error
[
2
]));
*/
public
function
getSQLState
()
{
return
$this
->
sqlState
;
}
};
$data
[]
=
array
(
$driverException
,
$convertedExceptionClassName
);
$data
[]
=
array
(
$driverException
,
$convertedExceptionClassName
);
}
}
...
...
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