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
77ecc637
Unverified
Commit
77ecc637
authored
Mar 05, 2019
by
Marco Pivetta
Committed by
GitHub
Mar 05, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3474 from morozov/remove-more-mocks
Remove more hard-coded mock classes
parents
2080599b
afbae7ef
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
292 deletions
+31
-292
ConnectionTest.php
tests/Doctrine/Tests/DBAL/ConnectionTest.php
+16
-5
DriverManagerTest.php
tests/Doctrine/Tests/DBAL/DriverManagerTest.php
+15
-10
ConnectionMock.php
tests/Doctrine/Tests/Mocks/ConnectionMock.php
+0
-70
DatabasePlatformMock.php
tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php
+0
-121
DriverMock.php
tests/Doctrine/Tests/Mocks/DriverMock.php
+0
-68
SchemaManagerMock.php
tests/Doctrine/Tests/Mocks/SchemaManagerMock.php
+0
-18
No files found.
tests/Doctrine/Tests/DBAL/ConnectionTest.php
View file @
77ecc637
...
@@ -22,7 +22,6 @@ use Doctrine\DBAL\Logging\EchoSQLLogger;
...
@@ -22,7 +22,6 @@ use Doctrine\DBAL\Logging\EchoSQLLogger;
use
Doctrine\DBAL\ParameterType
;
use
Doctrine\DBAL\ParameterType
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\Tests\DbalTestCase
;
use
Doctrine\Tests\DbalTestCase
;
use
Doctrine\Tests\Mocks\DriverMock
;
use
Doctrine\Tests\Mocks\DriverStatementMock
;
use
Doctrine\Tests\Mocks\DriverStatementMock
;
use
Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock
;
use
Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock
;
use
Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock
;
use
Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock
;
...
@@ -165,10 +164,22 @@ class ConnectionTest extends DbalTestCase
...
@@ -165,10 +164,22 @@ class ConnectionTest extends DbalTestCase
public
function
testEventManagerPassedToPlatform
()
public
function
testEventManagerPassedToPlatform
()
{
{
$driverMock
=
new
DriverMock
();
$eventManager
=
new
EventManager
();
$connection
=
new
Connection
(
$this
->
params
,
$driverMock
);
self
::
assertInstanceOf
(
EventManager
::
class
,
$connection
->
getDatabasePlatform
()
->
getEventManager
());
/** @var AbstractPlatform|MockObject $driver */
self
::
assertSame
(
$connection
->
getEventManager
(),
$connection
->
getDatabasePlatform
()
->
getEventManager
());
$platform
=
$this
->
createMock
(
AbstractPlatform
::
class
);
$platform
->
expects
(
$this
->
once
())
->
method
(
'setEventManager'
)
->
with
(
$eventManager
);
/** @var Driver|MockObject $driver */
$driver
=
$this
->
createMock
(
Driver
::
class
);
$driver
->
expects
(
$this
->
any
())
->
method
(
'getDatabasePlatform'
)
->
willReturn
(
$platform
);
$connection
=
new
Connection
(
$this
->
params
,
$driver
,
null
,
$eventManager
);
$connection
->
getDatabasePlatform
();
}
}
/**
/**
...
...
tests/Doctrine/Tests/DBAL/DriverManagerTest.php
View file @
77ecc637
...
@@ -2,8 +2,10 @@
...
@@ -2,8 +2,10 @@
namespace
Doctrine\Tests\DBAL
;
namespace
Doctrine\Tests\DBAL
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Connections\MasterSlaveConnection
;
use
Doctrine\DBAL\Connections\MasterSlaveConnection
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver
as
DrizzlePDOMySqlDriver
;
use
Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver
as
DrizzlePDOMySqlDriver
;
use
Doctrine\DBAL\Driver\PDOMySql\Driver
as
PDOMySQLDriver
;
use
Doctrine\DBAL\Driver\PDOMySql\Driver
as
PDOMySQLDriver
;
use
Doctrine\DBAL\Driver\PDOSqlite\Driver
as
PDOSqliteDriver
;
use
Doctrine\DBAL\Driver\PDOSqlite\Driver
as
PDOSqliteDriver
;
...
@@ -13,11 +15,10 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
...
@@ -13,11 +15,10 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use
Doctrine\DBAL\Sharding\PoolingShardConnection
;
use
Doctrine\DBAL\Sharding\PoolingShardConnection
;
use
Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser
;
use
Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser
;
use
Doctrine\Tests\DbalTestCase
;
use
Doctrine\Tests\DbalTestCase
;
use
Doctrine\Tests\Mocks\ConnectionMock
;
use
Doctrine\Tests\Mocks\DriverMock
;
use
PDO
;
use
PDO
;
use
stdClass
;
use
stdClass
;
use
function
extension_loaded
;
use
function
extension_loaded
;
use
function
get_class
;
use
function
in_array
;
use
function
in_array
;
use
function
is_array
;
use
function
is_array
;
...
@@ -92,7 +93,8 @@ class DriverManagerTest extends DbalTestCase
...
@@ -92,7 +93,8 @@ class DriverManagerTest extends DbalTestCase
*/
*/
public
function
testCustomWrapper
()
public
function
testCustomWrapper
()
{
{
$wrapperClass
=
ConnectionMock
::
class
;
$wrapper
=
$this
->
createMock
(
Connection
::
class
);
$wrapperClass
=
get_class
(
$wrapper
);
$options
=
[
$options
=
[
'pdo'
=>
new
PDO
(
'sqlite::memory:'
),
'pdo'
=>
new
PDO
(
'sqlite::memory:'
),
...
@@ -238,6 +240,9 @@ class DriverManagerTest extends DbalTestCase
...
@@ -238,6 +240,9 @@ class DriverManagerTest extends DbalTestCase
public
function
databaseUrls
()
public
function
databaseUrls
()
{
{
$driver
=
$this
->
createMock
(
Driver
::
class
);
$driverClass
=
get_class
(
$driver
);
return
[
return
[
'simple URL'
=>
[
'simple URL'
=>
[
'mysql://foo:bar@localhost/baz'
,
'mysql://foo:bar@localhost/baz'
,
...
@@ -406,14 +411,14 @@ class DriverManagerTest extends DbalTestCase
...
@@ -406,14 +411,14 @@ class DriverManagerTest extends DbalTestCase
'URL without scheme but custom driver'
=>
[
'URL without scheme but custom driver'
=>
[
[
[
'url'
=>
'//foo:bar@localhost/baz'
,
'url'
=>
'//foo:bar@localhost/baz'
,
'driverClass'
=>
DriverMock
::
c
lass
,
'driverClass'
=>
$driverC
lass
,
],
],
[
[
'user'
=>
'foo'
,
'user'
=>
'foo'
,
'password'
=>
'bar'
,
'password'
=>
'bar'
,
'host'
=>
'localhost'
,
'host'
=>
'localhost'
,
'dbname'
=>
'baz'
,
'dbname'
=>
'baz'
,
'driverClass'
=>
DriverMock
::
c
lass
,
'driverClass'
=>
$driverC
lass
,
],
],
],
],
'URL without scheme but default PDO driver and default driver'
=>
[
'URL without scheme but default PDO driver and default driver'
=>
[
...
@@ -434,14 +439,14 @@ class DriverManagerTest extends DbalTestCase
...
@@ -434,14 +439,14 @@ class DriverManagerTest extends DbalTestCase
[
[
'url'
=>
'//foo:bar@localhost/baz'
,
'url'
=>
'//foo:bar@localhost/baz'
,
'driver'
=>
'pdo_mysql'
,
'driver'
=>
'pdo_mysql'
,
'driverClass'
=>
DriverMock
::
c
lass
,
'driverClass'
=>
$driverC
lass
,
],
],
[
[
'user'
=>
'foo'
,
'user'
=>
'foo'
,
'password'
=>
'bar'
,
'password'
=>
'bar'
,
'host'
=>
'localhost'
,
'host'
=>
'localhost'
,
'dbname'
=>
'baz'
,
'dbname'
=>
'baz'
,
'driverClass'
=>
DriverMock
::
c
lass
,
'driverClass'
=>
$driverC
lass
,
],
],
],
],
'URL with default PDO driver'
=>
[
'URL with default PDO driver'
=>
[
...
@@ -473,7 +478,7 @@ class DriverManagerTest extends DbalTestCase
...
@@ -473,7 +478,7 @@ class DriverManagerTest extends DbalTestCase
'URL with default custom driver'
=>
[
'URL with default custom driver'
=>
[
[
[
'url'
=>
'mysql://foo:bar@localhost/baz'
,
'url'
=>
'mysql://foo:bar@localhost/baz'
,
'driverClass'
=>
DriverMock
::
c
lass
,
'driverClass'
=>
$driverC
lass
,
],
],
[
[
'user'
=>
'foo'
,
'user'
=>
'foo'
,
...
@@ -501,7 +506,7 @@ class DriverManagerTest extends DbalTestCase
...
@@ -501,7 +506,7 @@ class DriverManagerTest extends DbalTestCase
[
[
'url'
=>
'mysql://foo:bar@localhost/baz'
,
'url'
=>
'mysql://foo:bar@localhost/baz'
,
'driver'
=>
'sqlite'
,
'driver'
=>
'sqlite'
,
'driverClass'
=>
DriverMock
::
c
lass
,
'driverClass'
=>
$driverC
lass
,
],
],
[
[
'user'
=>
'foo'
,
'user'
=>
'foo'
,
...
@@ -516,7 +521,7 @@ class DriverManagerTest extends DbalTestCase
...
@@ -516,7 +521,7 @@ class DriverManagerTest extends DbalTestCase
'url'
=>
'mysql://foo:bar@localhost/baz'
,
'url'
=>
'mysql://foo:bar@localhost/baz'
,
'pdo'
=>
true
,
'pdo'
=>
true
,
'driver'
=>
'sqlite'
,
'driver'
=>
'sqlite'
,
'driverClass'
=>
DriverMock
::
c
lass
,
'driverClass'
=>
$driverC
lass
,
],
],
[
[
'user'
=>
'foo'
,
'user'
=>
'foo'
,
...
...
tests/Doctrine/Tests/Mocks/ConnectionMock.php
deleted
100644 → 0
View file @
2080599b
<?php
namespace
Doctrine\Tests\Mocks
;
use
Doctrine\DBAL\Connection
;
use
function
is_string
;
class
ConnectionMock
extends
Connection
{
/** @var DatabasePlatformMock */
private
$platformMock
;
/** @var int */
private
$lastInsertId
=
0
;
/** @var string[][] */
private
$inserts
=
[];
/**
* {@inheritDoc}
*/
public
function
__construct
(
array
$params
,
$driver
,
$config
=
null
,
$eventManager
=
null
)
{
$this
->
platformMock
=
new
DatabasePlatformMock
();
parent
::
__construct
(
$params
,
$driver
,
$config
,
$eventManager
);
}
public
function
getDatabasePlatform
()
{
return
$this
->
platformMock
;
}
/**
* {@inheritDoc}
*/
public
function
insert
(
$tableName
,
array
$data
,
array
$types
=
[])
{
$this
->
inserts
[
$tableName
][]
=
$data
;
}
public
function
lastInsertId
(
$seqName
=
null
)
{
return
$this
->
lastInsertId
;
}
public
function
quote
(
$input
,
$type
=
null
)
{
if
(
is_string
(
$input
))
{
return
"'"
.
$input
.
"'"
;
}
return
$input
;
}
public
function
setLastInsertId
(
$id
)
{
$this
->
lastInsertId
=
$id
;
}
public
function
getInserts
()
{
return
$this
->
inserts
;
}
public
function
reset
()
{
$this
->
inserts
=
[];
$this
->
lastInsertId
=
0
;
}
}
tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php
deleted
100644 → 0
View file @
2080599b
<?php
namespace
Doctrine\Tests\Mocks
;
use
Doctrine\DBAL\DBALException
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
class
DatabasePlatformMock
extends
AbstractPlatform
{
/** @var string */
private
$sequenceNextValSql
=
''
;
/** @var bool */
private
$prefersIdentityColumns
=
true
;
/** @var bool */
private
$prefersSequences
=
false
;
public
function
prefersIdentityColumns
()
{
return
$this
->
prefersIdentityColumns
;
}
public
function
prefersSequences
()
{
return
$this
->
prefersSequences
;
}
public
function
getSequenceNextValSQL
(
$sequenceName
)
{
return
$this
->
sequenceNextValSql
;
}
/**
* {@inheritDoc}
*/
public
function
getBooleanTypeDeclarationSQL
(
array
$field
)
{
}
/**
* {@inheritDoc}
*/
public
function
getIntegerTypeDeclarationSQL
(
array
$field
)
{
}
/**
* {@inheritDoc}
*/
public
function
getBigIntTypeDeclarationSQL
(
array
$field
)
{
}
/**
* {@inheritDoc}
*/
public
function
getSmallIntTypeDeclarationSQL
(
array
$field
)
{
}
/**
* {@inheritDoc}
*/
protected
function
_getCommonIntegerTypeDeclarationSQL
(
array
$columnDef
)
{
}
/**
* {@inheritDoc}
*/
public
function
getVarcharTypeDeclarationSQL
(
array
$field
)
{
}
/**
* {@inheritDoc}
*/
public
function
getClobTypeDeclarationSQL
(
array
$field
)
{
}
/* MOCK API */
/**
* @param bool $prefersIdentityColumns
*/
public
function
setPrefersIdentityColumns
(
$prefersIdentityColumns
)
{
$this
->
prefersIdentityColumns
=
$prefersIdentityColumns
;
}
public
function
setPrefersSequences
(
$bool
)
{
$this
->
prefersSequences
=
$bool
;
}
public
function
setSequenceNextValSql
(
$sql
)
{
$this
->
sequenceNextValSql
=
$sql
;
}
public
function
getName
()
{
return
'mock'
;
}
protected
function
initializeDoctrineTypeMappings
()
{
}
protected
function
getVarcharTypeDeclarationSQLSnippet
(
$length
,
$fixed
)
{
}
/**
* {@inheritDoc}
*/
public
function
getBlobTypeDeclarationSQL
(
array
$field
)
{
throw
DBALException
::
notSupported
(
__METHOD__
);
}
}
tests/Doctrine/Tests/Mocks/DriverMock.php
deleted
100644 → 0
View file @
2080599b
<?php
namespace
Doctrine\Tests\Mocks
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Driver
;
use
Doctrine\DBAL\Platforms\AbstractPlatform
;
use
Doctrine\DBAL\Schema\AbstractSchemaManager
;
use
Throwable
;
class
DriverMock
implements
Driver
{
/** @var DatabasePlatformMock */
private
$platformMock
;
/** @var AbstractSchemaManager */
private
$schemaManagerMock
;
/**
* {@inheritDoc}
*/
public
function
connect
(
array
$params
,
$username
=
null
,
$password
=
null
,
array
$driverOptions
=
[])
{
return
new
DriverConnectionMock
();
}
public
function
getDatabasePlatform
()
{
if
(
!
$this
->
platformMock
)
{
$this
->
platformMock
=
new
DatabasePlatformMock
();
}
return
$this
->
platformMock
;
}
public
function
getSchemaManager
(
Connection
$conn
)
{
if
(
$this
->
schemaManagerMock
===
null
)
{
return
new
SchemaManagerMock
(
$conn
);
}
return
$this
->
schemaManagerMock
;
}
public
function
setDatabasePlatform
(
AbstractPlatform
$platform
)
{
$this
->
platformMock
=
$platform
;
}
public
function
setSchemaManager
(
AbstractSchemaManager
$sm
)
{
$this
->
schemaManagerMock
=
$sm
;
}
public
function
getName
()
{
return
'mock'
;
}
public
function
getDatabase
(
Connection
$conn
)
{
return
;
}
public
function
convertExceptionCode
(
Throwable
$exception
)
{
return
0
;
}
}
tests/Doctrine/Tests/Mocks/SchemaManagerMock.php
deleted
100644 → 0
View file @
2080599b
<?php
namespace
Doctrine\Tests\Mocks
;
use
Doctrine\DBAL\Connection
;
use
Doctrine\DBAL\Schema\AbstractSchemaManager
;
class
SchemaManagerMock
extends
AbstractSchemaManager
{
public
function
__construct
(
Connection
$conn
)
{
parent
::
__construct
(
$conn
);
}
protected
function
_getPortableTableColumnDefinition
(
$tableColumn
)
{
}
}
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