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

Replaced MockPlatform with the ones generated by PHPUnit #3470

Merged
merged 1 commit into from
Feb 26, 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
32 changes: 18 additions & 14 deletions tests/Doctrine/Tests/DBAL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ protected function setUp() : void
$this->connection = DriverManager::getConnection($this->params);
}

public function getExecuteUpdateMockConnection()
/**
* @return Connection|MockObject
*/
private function getExecuteUpdateMockConnection()
{
$driverMock = $this->createMock(Driver::class);

Expand All @@ -63,9 +66,11 @@ public function getExecuteUpdateMockConnection()
$this->createMock(DriverConnection::class)
));

$platform = $this->getMockForAbstractClass(AbstractPlatform::class);

return $this->getMockBuilder(Connection::class)
->setMethods(['executeUpdate'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock])
->setConstructorArgs([['platform' => $platform], $driverMock])
->getMock();
}

Expand Down Expand Up @@ -153,9 +158,8 @@ public function testConnectDispatchEvent()
$driverMock = $this->createMock(Driver::class);
$driverMock->expects($this->at(0))
->method('connect');
$platform = new Mocks\MockPlatform();

$conn = new Connection(['platform' => $platform], $driverMock, new Configuration(), $eventManager);
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
Majkl578 marked this conversation as resolved.
Show resolved Hide resolved
$conn->connect();
}

Expand Down Expand Up @@ -249,7 +253,7 @@ public function testConnectStartsTransactionInNoAutoCommitMode()
->will($this->returnValue(
$this->createMock(DriverConnection::class)
));
$conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock);
$conn = new Connection([], $driverMock);

$conn->setAutoCommit(false);

Expand All @@ -271,7 +275,7 @@ public function testCommitStartsTransactionInNoAutoCommitMode()
->will($this->returnValue(
$this->createMock(DriverConnection::class)
));
$conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock);
$conn = new Connection([], $driverMock);

$conn->setAutoCommit(false);
$conn->connect();
Expand All @@ -291,7 +295,7 @@ public function testRollBackStartsTransactionInNoAutoCommitMode()
->will($this->returnValue(
$this->createMock(DriverConnection::class)
));
$conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock);
$conn = new Connection([], $driverMock);

$conn->setAutoCommit(false);
$conn->connect();
Expand All @@ -311,7 +315,7 @@ public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions()
->will($this->returnValue(
$this->createMock(DriverConnection::class)
));
$conn = new Connection(['platform' => new Mocks\MockPlatform()], $driverMock);
$conn = new Connection([], $driverMock);

$conn->connect();
$conn->beginTransaction();
Expand Down Expand Up @@ -520,7 +524,7 @@ public function testFetchAssoc()
/** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class)
->setMethods(['executeQuery'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock])
->setConstructorArgs([[], $driverMock])
->getMock();

$conn->expects($this->once())
Expand Down Expand Up @@ -556,7 +560,7 @@ public function testFetchArray()
/** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class)
->setMethods(['executeQuery'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock])
->setConstructorArgs([[], $driverMock])
->getMock();

$conn->expects($this->once())
Expand Down Expand Up @@ -593,7 +597,7 @@ public function testFetchColumn()
/** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class)
->setMethods(['executeQuery'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock])
->setConstructorArgs([[], $driverMock])
->getMock();

$conn->expects($this->once())
Expand Down Expand Up @@ -628,7 +632,7 @@ public function testFetchAll()
/** @var Connection|MockObject $conn */
$conn = $this->getMockBuilder(Connection::class)
->setMethods(['executeQuery'])
->setConstructorArgs([['platform' => new Mocks\MockPlatform()], $driverMock])
->setConstructorArgs([[], $driverMock])
->getMock();

$conn->expects($this->once())
Expand Down Expand Up @@ -694,8 +698,8 @@ public function dataCallConnectOnce()
public function testCallConnectOnce($method, $params)
{
$driverMock = $this->createMock(Driver::class);
$pdoMock = $this->createMock(\Doctrine\DBAL\Driver\Connection::class);
$platformMock = new Mocks\MockPlatform();
$pdoMock = $this->createMock(Connection::class);
$platformMock = $this->createMock(AbstractPlatform::class);
$stmtMock = $this->createMock(Statement::class);

$pdoMock->expects($this->any())
Expand Down
10 changes: 5 additions & 5 deletions tests/Doctrine/Tests/DBAL/DriverManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSqliteDriver;
use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Sharding\PoolingShardConnection;
use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase;
use Doctrine\Tests\Mocks\ConnectionMock;
use Doctrine\Tests\Mocks\DriverMock;
Expand Down Expand Up @@ -77,14 +77,14 @@ public function testInvalidDriver()
*/
public function testCustomPlatform()
{
$mockPlatform = new MockPlatform();
$options = [
$platform = $this->createMock(AbstractPlatform::class);
$options = [
'pdo' => new PDO('sqlite::memory:'),
'platform' => $mockPlatform,
'platform' => $platform,
];

$conn = DriverManager::getConnection($options);
self::assertSame($mockPlatform, $conn->getDatabasePlatform());
self::assertSame($platform, $conn->getDatabasePlatform());
}

/**
Expand Down
100 changes: 0 additions & 100 deletions tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php

This file was deleted.

12 changes: 9 additions & 3 deletions tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Doctrine\Tests\DBAL\Schema;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\SchemaDiff;
use Doctrine\DBAL\Schema\Sequence;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class SchemaDiffTest extends TestCase
Expand Down Expand Up @@ -36,9 +37,13 @@ public function testSchemaDiffToSaveSql()
self::assertEquals($expected, $sql);
}

public function createPlatform($unsafe = false)
/**
* @return AbstractPlatform|MockObject
*/
private function createPlatform(bool $unsafe)
{
$platform = $this->createMock(MockPlatform::class);
/** @var AbstractPlatform|MockObject $platform */
$platform = $this->createMock(AbstractPlatform::class);
$platform->expects($this->exactly(1))
->method('getCreateSchemaSQL')
->with('foo_ns')
Expand Down Expand Up @@ -93,6 +98,7 @@ public function createPlatform($unsafe = false)
$platform->expects($this->exactly(2))
->method('supportsForeignKeyConstraints')
->will($this->returnValue(true));

return $platform;
}

Expand Down
20 changes: 14 additions & 6 deletions tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,39 @@

namespace Doctrine\Tests\DBAL\Schema;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Identifier;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class TableDiffTest extends TestCase
{
/** @var AbstractPlatform|MockObject */
private $platform;

public function setUp() : void
{
$this->platform = $this->createMock(AbstractPlatform::class);
}

/**
* @group DBAL-1013
*/
public function testReturnsName()
{
$tableDiff = new TableDiff('foo');

self::assertEquals(new Identifier('foo'), $tableDiff->getName(new MockPlatform()));
self::assertEquals(new Identifier('foo'), $tableDiff->getName($this->platform));
}

/**
* @group DBAL-1016
*/
public function testPrefersNameFromTableObject()
{
$platformMock = new MockPlatform();
$tableMock = $this->getMockBuilder(Table::class)
$tableMock = $this->getMockBuilder(Table::class)
->disableOriginalConstructor()
->getMock();

Expand All @@ -35,10 +43,10 @@ public function testPrefersNameFromTableObject()

$tableMock->expects($this->once())
->method('getQuotedName')
->with($platformMock)
->with($this->platform)
->will($this->returnValue('foo'));

self::assertEquals(new Identifier('foo'), $tableDiff->getName($platformMock));
self::assertEquals(new Identifier('foo'), $tableDiff->getName($this->platform));
}

/**
Expand Down
16 changes: 6 additions & 10 deletions tests/Doctrine/Tests/DBAL/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Statement;
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
use Doctrine\Tests\DbalTestCase;
use Exception;
use PDOStatement;
Expand All @@ -31,19 +30,16 @@ protected function setUp() : void
$this->pdoStatement = $this->getMockBuilder(PDOStatement::class)
->setMethods(['execute', 'bindParam', 'bindValue'])
->getMock();
$platform = new MockPlatform();
$driverConnection = $this->createMock(DriverConnection::class);

$driverConnection = $this->createMock(DriverConnection::class);
$driverConnection->expects($this->any())
->method('prepare')
->will($this->returnValue($this->pdoStatement));

$driver = $this->createMock(Driver::class);
$constructorArgs = [
['platform' => $platform],
$driver,
];
$this->conn = $this->getMockBuilder(Connection::class)
->setConstructorArgs($constructorArgs)
$driver = $this->createMock(Driver::class);

$this->conn = $this->getMockBuilder(Connection::class)
->setConstructorArgs([[], $driver])
->getMock();
$this->conn->expects($this->atLeastOnce())
->method('getWrappedConnection')
Expand Down
Loading