Skip to content

Commit 5c64814

Browse files
committed
Avoid mocks without expectations
1 parent 09e50f0 commit 5c64814

31 files changed

+74
-90
lines changed

tests/Connection/CachedQueryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private function createConnection(int $expectedQueryCount, array $columnNames, a
8888
->method('query')
8989
->willReturnCallback(static fn (): ArrayResult => new ArrayResult($columnNames, $rows));
9090

91-
$driver = $this->createMock(Driver::class);
91+
$driver = self::createStub(Driver::class);
9292
$driver->method('connect')
9393
->willReturn($connection);
9494

tests/ConnectionTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ public function testTransactionIsNotActiveAfterTransactionalInAutoCommitMode():
183183

184184
public function testTransactionIsActiveAfterTransactionalInNoAutoCommitMode(): void
185185
{
186-
$platformMock = $this->createMock(AbstractPlatform::class);
186+
$platformMock = self::createStub(AbstractPlatform::class);
187187
$platformMock
188188
->method('supportsSavepoints')
189189
->willReturn(true);
190190

191-
$driverMock = $this->createMock(Driver::class);
191+
$driverMock = self::createStub(Driver::class);
192192
$driverMock
193193
->method('connect')
194194
->willReturn(
@@ -470,7 +470,7 @@ public function testFetch(string $method, callable $invoke, mixed $expected): vo
470470
->willReturn($expected);
471471

472472
$driver = $this->createConfiguredMock(Driver::class, [
473-
'connect' => $this->createMock(DriverConnection::class),
473+
'connect' => self::createStub(DriverConnection::class),
474474
]);
475475

476476
$conn = $this->getMockBuilder(Connection::class)
@@ -565,7 +565,7 @@ public function testPlatformDetectionTriggersConnectionIfRequiredByTheDriver():
565565
->method('getServerVersion')
566566
->willReturn('6.6.6');
567567

568-
$platform = $this->createMock(AbstractPlatform::class);
568+
$platform = self::createStub(AbstractPlatform::class);
569569

570570
$driver = $this->createMock(Driver::class);
571571
$driver->expects(self::once())
@@ -590,7 +590,7 @@ public function testPlatformDetectionDoesNotTriggerConnectionIfNotRequiredByTheD
590590
$driverConnection->expects(self::never())
591591
->method('getServerVersion');
592592

593-
$platform = $this->createMock(AbstractPlatform::class);
593+
$platform = self::createStub(AbstractPlatform::class);
594594

595595
$driver = $this->createMock(Driver::class);
596596
$driver->expects(self::never())
@@ -608,9 +608,9 @@ public function testPlatformDetectionFetchedFromParameters(): void
608608
{
609609
$driverMock = $this->createMock(Driver::class);
610610

611-
$driverConnectionMock = $this->createMock(Driver\Connection::class);
611+
$driverConnectionMock = self::createStub(Driver\Connection::class);
612612

613-
$platformMock = $this->createMock(AbstractPlatform::class);
613+
$platformMock = self::createStub(AbstractPlatform::class);
614614

615615
$connection = new Connection(['serverVersion' => '8.0'], $driverMock);
616616

@@ -630,9 +630,9 @@ public function testPlatformDetectionFetchedFromPrimaryReplicaParameters(): void
630630
{
631631
$driverMock = $this->createMock(Driver::class);
632632

633-
$driverConnectionMock = $this->createMock(Driver\Connection::class);
633+
$driverConnectionMock = self::createStub(Driver\Connection::class);
634634

635-
$platformMock = $this->createMock(AbstractPlatform::class);
635+
$platformMock = self::createStub(AbstractPlatform::class);
636636

637637
$connection = new Connection(['primary' => ['serverVersion' => '8.0']], $driverMock);
638638

@@ -650,7 +650,7 @@ public function testPlatformDetectionFetchedFromPrimaryReplicaParameters(): void
650650

651651
public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCacheQuery(): void
652652
{
653-
$cacheItemMock = $this->createMock(CacheItemInterface::class);
653+
$cacheItemMock = self::createStub(CacheItemInterface::class);
654654
$cacheItemMock->method('isHit')->willReturn(true);
655655
$cacheItemMock->method('get')->willReturn(['realKey' => [[], []]]);
656656

@@ -682,7 +682,7 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach
682682
->with($query, $params, $types, $expectedConnectionParams)
683683
->willReturn(['cacheKey', 'realKey']);
684684

685-
$driver = $this->createMock(Driver::class);
685+
$driver = self::createStub(Driver::class);
686686

687687
(new Connection(self::CONNECTION_PARAMS, $driver))
688688
->executeCacheQuery($query, $params, $types, $queryCacheProfileMock);

tests/Driver/Middleware/AbstractConnectionMiddlewareTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class AbstractConnectionMiddlewareTest extends TestCase
1414
{
1515
public function testPrepare(): void
1616
{
17-
$statement = $this->createMock(Statement::class);
17+
$statement = self::createStub(Statement::class);
1818
$connection = $this->createMock(Connection::class);
1919
$connection->expects(self::once())
2020
->method('prepare')
@@ -26,7 +26,7 @@ public function testPrepare(): void
2626

2727
public function testQuery(): void
2828
{
29-
$result = $this->createMock(Result::class);
29+
$result = self::createStub(Result::class);
3030
$connection = $this->createMock(Connection::class);
3131
$connection->expects(self::once())
3232
->method('query')

tests/Driver/Middleware/AbstractDriverMiddlewareTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class AbstractDriverMiddlewareTest extends TestCase
1313
{
1414
public function testConnect(): void
1515
{
16-
$connection = $this->createMock(Connection::class);
16+
$connection = self::createStub(Connection::class);
1717
$driver = $this->createMock(Driver::class);
1818
$driver->expects(self::once())
1919
->method('connect')

tests/Driver/Middleware/AbstractStatementMiddlewareTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class AbstractStatementMiddlewareTest extends TestCase
1313
{
1414
public function testExecute(): void
1515
{
16-
$result = $this->createMock(Result::class);
16+
$result = self::createStub(Result::class);
1717
$statement = $this->createMock(Statement::class);
1818
$statement->expects(self::once())
1919
->method('execute')

tests/DriverManagerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testInvalidDriver(): void
4141
#[RequiresPhpExtension('sqlite3')]
4242
public function testCustomWrapper(): void
4343
{
44-
$wrapper = $this->createMock(Connection::class);
44+
$wrapper = self::createStub(Connection::class);
4545
$wrapperClass = $wrapper::class;
4646

4747
$options = [

tests/Logging/MiddlewareTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class MiddlewareTest extends TestCase
1818

1919
public function setUp(): void
2020
{
21-
$connection = $this->createMock(Connection::class);
21+
$connection = self::createStub(Connection::class);
2222

23-
$driver = $this->createMock(Driver::class);
23+
$driver = self::createStub(Driver::class);
2424
$driver->method('connect')
2525
->willReturn($connection);
2626

tests/Portability/ConnectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testGetNativeConnection(): void
2828
$nativeConnection = new class () {
2929
};
3030

31-
$driverConnection = $this->createMock(ConnectionInterface::class);
31+
$driverConnection = self::createStub(ConnectionInterface::class);
3232
$driverConnection->method('getNativeConnection')
3333
->willReturn($nativeConnection);
3434

tests/Query/QueryBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function setUp(): void
3838
$this->conn->method('createExpressionBuilder')
3939
->willReturnCallback(fn () => new ExpressionBuilder($this->conn));
4040

41-
$platform = $this->createMock(AbstractPlatform::class);
41+
$platform = self::createStub(AbstractPlatform::class);
4242
$platform->method('getUnionSelectPartSQL')
4343
->willReturnArgument(0);
4444
$platform->method('getUnionAllSQL')

tests/Schema/ColumnTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testSettingUnknownOptionIsStillSupported(): void
7373
$this->expectException(UnknownColumnOption::class);
7474
$this->expectExceptionMessage('The "unknown_option" column option is not supported.');
7575

76-
new Column('foo', $this->createMock(Type::class), ['unknown_option' => 'bar']);
76+
new Column('foo', self::createStub(Type::class), ['unknown_option' => 'bar']);
7777
}
7878

7979
public function testOptionsShouldNotBeIgnored(): void

0 commit comments

Comments
 (0)