Skip to content

Commit

Permalink
Merge pull request doctrine#4964 from morozov/remove-redundant-mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Nov 7, 2021
2 parents 9fc0b68 + 19ef121 commit 2f7e154
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 60 deletions.
6 changes: 0 additions & 6 deletions tests/Connection/LoggingTest.php
Expand Up @@ -7,9 +7,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use PHPUnit\Framework\TestCase;

final class LoggingTest extends TestCase
Expand All @@ -34,8 +32,6 @@ public function testLogExecuteStatement(): void
public function testLogPrepareExecute(): void
{
$driverConnection = $this->createStub(DriverConnection::class);
$driverConnection->method('prepare')
->willReturn($this->createStub(Statement::class));

$this->createConnection($driverConnection, 'UPDATE table SET foo = ?')
->prepare('UPDATE table SET foo = ?')
Expand All @@ -47,8 +43,6 @@ private function createConnection(DriverConnection $driverConnection, string $ex
$driver = $this->createStub(Driver::class);
$driver->method('connect')
->willReturn($driverConnection);
$driver->method('getDatabasePlatform')
->willReturn($this->createMock(AbstractPlatform::class));

$logger = $this->createMock(SQLLogger::class);
$logger->expects(self::once())
Expand Down
58 changes: 7 additions & 51 deletions tests/ConnectionTest.php
Expand Up @@ -62,12 +62,6 @@ private function getExecuteStatementMockConnection()
{
$driverMock = $this->createMock(Driver::class);

$driverMock->expects(self::any())
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class)
);

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

return $this->getMockBuilder(Connection::class)
Expand Down Expand Up @@ -135,11 +129,6 @@ public function testTransactionBeginDispatchEvent(): void
{
$eventManager = new EventManager();
$driverMock = $this->createMock(Driver::class);
$driverMock->expects(self::any())
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class)
);
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
$listenerMock = $this->createMock(TransactionBeginDispatchEventListener::class);
$listenerMock
Expand All @@ -161,11 +150,6 @@ public function testTransactionCommitDispatchEvent(): void
{
$eventManager = new EventManager();
$driverMock = $this->createMock(Driver::class);
$driverMock->expects(self::any())
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class)
);
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
$listenerMock = $this->createMock(TransactionCommitDispatchEventListener::class);
$listenerMock
Expand All @@ -188,12 +172,8 @@ public function testTransactionCommitEventNotCalledAfterRollBack(): void
{
$eventManager = new EventManager();
$driverMock = $this->createMock(Driver::class);
$driverMock->expects(self::any())
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class)
);
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);

$rollBackListenerMock = $this->createMock(TransactionRollBackDispatchEventListener::class);
$rollBackListenerMock
->expects(self::exactly(1))
Expand Down Expand Up @@ -224,11 +204,6 @@ public function testTransactionRollBackDispatchEvent(): void
{
$eventManager = new EventManager();
$driverMock = $this->createMock(Driver::class);
$driverMock->expects(self::any())
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class)
);
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
$listenerMock = $this->createMock(TransactionRollBackDispatchEventListener::class);
$listenerMock
Expand Down Expand Up @@ -333,11 +308,7 @@ public function testSetAutoCommit(): void
public function testConnectStartsTransactionInNoAutoCommitMode(): void
{
$driverMock = $this->createMock(Driver::class);
$driverMock->expects(self::any())
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class)
);

$conn = new Connection([], $driverMock);

$conn->setAutoCommit(false);
Expand All @@ -352,11 +323,7 @@ public function testConnectStartsTransactionInNoAutoCommitMode(): void
public function testCommitStartsTransactionInNoAutoCommitMode(): void
{
$driverMock = $this->createMock(Driver::class);
$driverMock->expects(self::any())
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class)
);

$conn = new Connection([], $driverMock);

$conn->setAutoCommit(false);
Expand All @@ -377,11 +344,7 @@ public function resultProvider(): array
public function testRollBackStartsTransactionInNoAutoCommitMode(): void
{
$driverMock = $this->createMock(Driver::class);
$driverMock->expects(self::any())
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class)
);

$conn = new Connection([], $driverMock);

$conn->setAutoCommit(false);
Expand All @@ -394,11 +357,7 @@ public function testRollBackStartsTransactionInNoAutoCommitMode(): void
public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions(): void
{
$driverMock = $this->createMock(Driver::class);
$driverMock->expects(self::any())
->method('connect')
->willReturn(
$this->createMock(DriverConnection::class)
);

$conn = new Connection([], $driverMock);

$conn->connect();
Expand Down Expand Up @@ -680,10 +639,7 @@ public function testCallConnectOnce(): void
{
$driver = $this->createMock(Driver::class);
$driver->expects(self::once())
->method('connect')
->willReturn(
$this->createMock(Driver\Connection::class)
);
->method('connect');

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

Expand Down
3 changes: 0 additions & 3 deletions tests/Schema/MySQLInheritCharsetTest.php
Expand Up @@ -8,7 +8,6 @@
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Column;
Expand Down Expand Up @@ -73,8 +72,6 @@ private function getTableOptionsForOverride(array $params = []): array
$eventManager = new EventManager();

$driverMock = $this->createMock(Driver::class);
$driverMock->method('connect')
->willReturn($this->createMock(DriverConnection::class));

$platform = new MySQLPlatform();
$params = array_merge(['platform' => $platform], $params);
Expand Down

0 comments on commit 2f7e154

Please sign in to comment.