Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove more hard-coded mock classes #3474

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions tests/Doctrine/Tests/DBAL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\Tests\DbalTestCase;
use Doctrine\Tests\Mocks\DriverMock;
use Doctrine\Tests\Mocks\DriverStatementMock;
use Doctrine\Tests\Mocks\ServerInfoAwareConnectionMock;
use Doctrine\Tests\Mocks\VersionAwarePlatformDriverMock;
Expand Down Expand Up @@ -165,10 +164,22 @@ public function testConnectDispatchEvent()

public function testEventManagerPassedToPlatform()
{
$driverMock = new DriverMock();
$connection = new Connection($this->params, $driverMock);
self::assertInstanceOf(EventManager::class, $connection->getDatabasePlatform()->getEventManager());
self::assertSame($connection->getEventManager(), $connection->getDatabasePlatform()->getEventManager());
$eventManager = new EventManager();

/** @var AbstractPlatform|MockObject $driver */
$platform = $this->createMock(AbstractPlatform::class);
$platform->expects($this->once())
morozov marked this conversation as resolved.
Show resolved Hide resolved
->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();
}

/**
Expand Down
25 changes: 15 additions & 10 deletions tests/Doctrine/Tests/DBAL/DriverManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Doctrine\Tests\DBAL;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Connections\MasterSlaveConnection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver as DrizzlePDOMySqlDriver;
use Doctrine\DBAL\Driver\PDOMySql\Driver as PDOMySQLDriver;
use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSqliteDriver;
Expand All @@ -13,11 +15,10 @@
use Doctrine\DBAL\Sharding\PoolingShardConnection;
use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser;
use Doctrine\Tests\DbalTestCase;
use Doctrine\Tests\Mocks\ConnectionMock;
use Doctrine\Tests\Mocks\DriverMock;
use PDO;
use stdClass;
use function extension_loaded;
use function get_class;
use function in_array;
use function is_array;

Expand Down Expand Up @@ -92,7 +93,8 @@ public function testCustomPlatform()
*/
public function testCustomWrapper()
{
$wrapperClass = ConnectionMock::class;
$wrapper = $this->createMock(Connection::class);
$wrapperClass = get_class($wrapper);

$options = [
'pdo' => new PDO('sqlite::memory:'),
Expand Down Expand Up @@ -238,6 +240,9 @@ public function testDatabaseUrl($url, $expected)

public function databaseUrls()
{
$driver = $this->createMock(Driver::class);
$driverClass = get_class($driver);

return [
'simple URL' => [
'mysql://foo:bar@localhost/baz',
Expand Down Expand Up @@ -406,14 +411,14 @@ public function databaseUrls()
'URL without scheme but custom driver' => [
[
'url' => '//foo:bar@localhost/baz',
'driverClass' => DriverMock::class,
'driverClass' => $driverClass,
],
[
'user' => 'foo',
'password' => 'bar',
'host' => 'localhost',
'dbname' => 'baz',
'driverClass' => DriverMock::class,
'driverClass' => $driverClass,
],
],
'URL without scheme but default PDO driver and default driver' => [
Expand All @@ -434,14 +439,14 @@ public function databaseUrls()
[
'url' => '//foo:bar@localhost/baz',
'driver' => 'pdo_mysql',
'driverClass' => DriverMock::class,
'driverClass' => $driverClass,
],
[
'user' => 'foo',
'password' => 'bar',
'host' => 'localhost',
'dbname' => 'baz',
'driverClass' => DriverMock::class,
'driverClass' => $driverClass,
],
],
'URL with default PDO driver' => [
Expand Down Expand Up @@ -473,7 +478,7 @@ public function databaseUrls()
'URL with default custom driver' => [
[
'url' => 'mysql://foo:bar@localhost/baz',
'driverClass' => DriverMock::class,
'driverClass' => $driverClass,
],
[
'user' => 'foo',
Expand Down Expand Up @@ -501,7 +506,7 @@ public function databaseUrls()
[
'url' => 'mysql://foo:bar@localhost/baz',
'driver' => 'sqlite',
'driverClass' => DriverMock::class,
'driverClass' => $driverClass,
],
[
'user' => 'foo',
Expand All @@ -516,7 +521,7 @@ public function databaseUrls()
'url' => 'mysql://foo:bar@localhost/baz',
'pdo' => true,
'driver' => 'sqlite',
'driverClass' => DriverMock::class,
'driverClass' => $driverClass,
],
[
'user' => 'foo',
Expand Down
70 changes: 0 additions & 70 deletions tests/Doctrine/Tests/Mocks/ConnectionMock.php

This file was deleted.

121 changes: 0 additions & 121 deletions tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php

This file was deleted.

Loading