Skip to content

Commit b87a89f

Browse files
authored
Create stubs instead of mocks (#6564)
| Q | A |------------- | ----------- | Type | improvement | Fixed issues | <!-- use #NUM format to reference an issue --> #### Summary _This is a followup of https://github.com/doctrine/dbal/pull/6558_, I have touched only what previous PR touched. @greg0ire [requested](#6562 (review)) to use stubs where there are no expectations ![image](https://github.com/user-attachments/assets/f71ad45f-87f7-4575-b10d-2f46b2c6525a)
1 parent 9fca0ee commit b87a89f

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

tests/ConnectionTest.php

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ protected function setUp(): void
5757
/** @return Connection&MockObject */
5858
private function getExecuteStatementMockConnection(): Connection
5959
{
60-
$driverMock = $this->createMock(Driver::class);
60+
$driver = $this->createStub(Driver::class);
6161

62-
$driverMock
62+
$driver
6363
->method('connect')
6464
->willReturn(
65-
$this->createMock(DriverConnection::class),
65+
$this->createStub(DriverConnection::class),
6666
);
6767

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

7070
return $this->getMockBuilder(Connection::class)
7171
->onlyMethods(['executeStatement'])
72-
->setConstructorArgs([['platform' => $platform], $driverMock])
72+
->setConstructorArgs([['platform' => $platform], $driver])
7373
->getMock();
7474
}
7575

@@ -183,13 +183,13 @@ public function testConnectDispatchEvent(): void
183183
public function testTransactionBeginDispatchEvent(): void
184184
{
185185
$eventManager = new EventManager();
186-
$driverMock = $this->createMock(Driver::class);
187-
$driverMock
186+
$driver = $this->createStub(Driver::class);
187+
$driver
188188
->method('connect')
189189
->willReturn(
190-
$this->createMock(DriverConnection::class),
190+
$this->createStub(DriverConnection::class),
191191
);
192-
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
192+
$conn = new Connection([], $driver, new Configuration(), $eventManager);
193193
$listenerMock = $this->createMock(TransactionBeginDispatchEventListener::class);
194194
$listenerMock
195195
->expects(self::exactly(1))
@@ -209,13 +209,13 @@ static function (TransactionBeginEventArgs $eventArgs) use ($conn): bool {
209209
public function testTransactionCommitDispatchEvent(): void
210210
{
211211
$eventManager = new EventManager();
212-
$driverMock = $this->createMock(Driver::class);
213-
$driverMock
212+
$driver = $this->createStub(Driver::class);
213+
$driver
214214
->method('connect')
215215
->willReturn(
216-
$this->createMock(DriverConnection::class),
216+
$this->createStub(DriverConnection::class),
217217
);
218-
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
218+
$conn = new Connection([], $driver, new Configuration(), $eventManager);
219219
$listenerMock = $this->createMock(TransactionCommitDispatchEventListener::class);
220220
$listenerMock
221221
->expects(self::exactly(1))
@@ -236,13 +236,13 @@ static function (TransactionCommitEventArgs $eventArgs) use ($conn): bool {
236236
public function testTransactionCommitEventNotCalledAfterRollBack(): void
237237
{
238238
$eventManager = new EventManager();
239-
$driverMock = $this->createMock(Driver::class);
240-
$driverMock
239+
$driver = $this->createStub(Driver::class);
240+
$driver
241241
->method('connect')
242242
->willReturn(
243-
$this->createMock(DriverConnection::class),
243+
$this->createStub(DriverConnection::class),
244244
);
245-
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
245+
$conn = new Connection([], $driver, new Configuration(), $eventManager);
246246
$rollBackListenerMock = $this->createMock(TransactionRollBackDispatchEventListener::class);
247247
$rollBackListenerMock
248248
->expects(self::exactly(1))
@@ -272,13 +272,13 @@ static function (TransactionRollBackEventArgs $eventArgs) use ($conn): bool {
272272
public function testTransactionRollBackDispatchEvent(): void
273273
{
274274
$eventManager = new EventManager();
275-
$driverMock = $this->createMock(Driver::class);
276-
$driverMock
275+
$driver = $this->createStub(Driver::class);
276+
$driver
277277
->method('connect')
278278
->willReturn(
279-
$this->createMock(DriverConnection::class),
279+
$this->createStub(DriverConnection::class),
280280
);
281-
$conn = new Connection([], $driverMock, new Configuration(), $eventManager);
281+
$conn = new Connection([], $driver, new Configuration(), $eventManager);
282282
$listenerMock = $this->createMock(TransactionRollBackDispatchEventListener::class);
283283
$listenerMock
284284
->expects(self::exactly(1))
@@ -306,7 +306,7 @@ public function testEventManagerPassedToPlatform(): void
306306
->method('setEventManager')
307307
->with($eventManager);
308308

309-
$driver = $this->createMock(Driver::class);
309+
$driver = $this->createStub(Driver::class);
310310
$driver
311311
->method('getDatabasePlatform')
312312
->willReturn($platform);
@@ -383,7 +383,7 @@ public function testConnectStartsTransactionInNoAutoCommitMode(): void
383383
$driverMock
384384
->method('connect')
385385
->willReturn(
386-
$this->createMock(DriverConnection::class),
386+
$this->createStub(DriverConnection::class),
387387
);
388388
$conn = new Connection([], $driverMock);
389389

@@ -398,13 +398,13 @@ public function testConnectStartsTransactionInNoAutoCommitMode(): void
398398

399399
public function testCommitStartsTransactionInNoAutoCommitMode(): void
400400
{
401-
$driverMock = $this->createMock(Driver::class);
402-
$driverMock
401+
$driver = $this->createStub(Driver::class);
402+
$driver
403403
->method('connect')
404404
->willReturn(
405-
$this->createMock(DriverConnection::class),
405+
$this->createStub(DriverConnection::class),
406406
);
407-
$conn = new Connection([], $driverMock);
407+
$conn = new Connection([], $driver);
408408

409409
$conn->setAutoCommit(false);
410410
$conn->connect();
@@ -420,12 +420,12 @@ public function testCommitReturn(bool $expectedResult): void
420420
$driverConnection->expects(self::once())
421421
->method('commit')->willReturn($expectedResult);
422422

423-
$driverMock = $this->createMock(Driver::class);
424-
$driverMock
423+
$driver = $this->createStub(Driver::class);
424+
$driver
425425
->method('connect')
426426
->willReturn($driverConnection);
427427

428-
$conn = new Connection([], $driverMock);
428+
$conn = new Connection([], $driver);
429429

430430
$conn->connect();
431431
$conn->beginTransaction();
@@ -441,13 +441,13 @@ public static function resultProvider(): array
441441

442442
public function testRollBackStartsTransactionInNoAutoCommitMode(): void
443443
{
444-
$driverMock = $this->createMock(Driver::class);
445-
$driverMock
444+
$driver = $this->createStub(Driver::class);
445+
$driver
446446
->method('connect')
447447
->willReturn(
448-
$this->createMock(DriverConnection::class),
448+
$this->createStub(DriverConnection::class),
449449
);
450-
$conn = new Connection([], $driverMock);
450+
$conn = new Connection([], $driver);
451451

452452
$conn->setAutoCommit(false);
453453
$conn->connect();
@@ -458,13 +458,13 @@ public function testRollBackStartsTransactionInNoAutoCommitMode(): void
458458

459459
public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions(): void
460460
{
461-
$driverMock = $this->createMock(Driver::class);
462-
$driverMock
461+
$driver = $this->createStub(Driver::class);
462+
$driver
463463
->method('connect')
464464
->willReturn(
465-
$this->createMock(DriverConnection::class),
465+
$this->createStub(DriverConnection::class),
466466
);
467-
$conn = new Connection([], $driverMock);
467+
$conn = new Connection([], $driver);
468468

469469
$conn->connect();
470470
$conn->beginTransaction();

tests/Query/Expression/ExpressionBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class ExpressionBuilderTest extends TestCase
1313

1414
protected function setUp(): void
1515
{
16-
$conn = $this->createMock(Connection::class);
16+
$conn = $this->createStub(Connection::class);
1717

1818
$this->expr = new ExpressionBuilder($conn);
1919

tests/Schema/Visitor/DropSchemaSqlCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testGetQueriesUsesAcceptedForeignKeys(): void
4141

4242
private function getStubKeyConstraint(string $name): ForeignKeyConstraint
4343
{
44-
$constraint = $this->createMock(ForeignKeyConstraint::class);
44+
$constraint = $this->createStub(ForeignKeyConstraint::class);
4545

4646
$constraint
4747
->method('getName')

0 commit comments

Comments
 (0)