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

Use willReturn() in mocks instead of will(returnValue()) #4954

Merged
merged 1 commit into from
Nov 6, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 41 additions & 41 deletions tests/Doctrine/Tests/DBAL/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ private function getExecuteStatementMockConnection()

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

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

Expand Down Expand Up @@ -247,9 +247,9 @@ public function testConnectStartsTransactionInNoAutoCommitMode(): void
$driverMock = $this->createMock(Driver::class);
$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue(
->willReturn(
$this->createMock(DriverConnection::class)
));
);
$conn = new Connection([], $driverMock);

$conn->setAutoCommit(false);
Expand All @@ -266,9 +266,9 @@ public function testCommitStartsTransactionInNoAutoCommitMode(): void
$driverMock = $this->createMock(Driver::class);
$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue(
->willReturn(
$this->createMock(DriverConnection::class)
));
);
$conn = new Connection([], $driverMock);

$conn->setAutoCommit(false);
Expand All @@ -290,7 +290,7 @@ public function testCommitReturn(bool $expectedResult): void
$driverMock = $this->createMock(Driver::class);
$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue($driverConnection));
->willReturn($driverConnection);

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

Expand All @@ -313,9 +313,9 @@ public function testRollBackStartsTransactionInNoAutoCommitMode(): void
$driverMock = $this->createMock(Driver::class);
$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue(
->willReturn(
$this->createMock(DriverConnection::class)
));
);
$conn = new Connection([], $driverMock);

$conn->setAutoCommit(false);
Expand All @@ -330,9 +330,9 @@ public function testSwitchingAutoCommitModeCommitsAllCurrentTransactions(): void
$driverMock = $this->createMock(Driver::class);
$driverMock->expects($this->any())
->method('connect')
->will($this->returnValue(
->willReturn(
$this->createMock(DriverConnection::class)
));
);
$conn = new Connection([], $driverMock);

$conn->connect();
Expand Down Expand Up @@ -516,16 +516,16 @@ public function testFetchAssoc(): void

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

$driverStatementMock = $this->createMock(Statement::class);

$driverStatementMock->expects($this->once())
->method('fetch')
->with(FetchMode::ASSOCIATIVE)
->will($this->returnValue($result));
->willReturn($result);

$conn = (new MockBuilderProxy($this->getMockBuilder(Connection::class)))
->onlyMethods(['executeQuery'])
Expand All @@ -535,7 +535,7 @@ public function testFetchAssoc(): void
$conn->expects($this->once())
->method('executeQuery')
->with($statement, $params, $types)
->will($this->returnValue($driverStatementMock));
->willReturn($driverStatementMock);

self::assertSame($result, $conn->fetchAssoc($statement, $params, $types));
}
Expand All @@ -551,16 +551,16 @@ public function testFetchArray(): void

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

$driverStatementMock = $this->createMock(Statement::class);

$driverStatementMock->expects($this->once())
->method('fetch')
->with(FetchMode::NUMERIC)
->will($this->returnValue($result));
->willReturn($result);

$conn = (new MockBuilderProxy($this->getMockBuilder(Connection::class)))
->onlyMethods(['executeQuery'])
Expand All @@ -570,7 +570,7 @@ public function testFetchArray(): void
$conn->expects($this->once())
->method('executeQuery')
->with($statement, $params, $types)
->will($this->returnValue($driverStatementMock));
->willReturn($driverStatementMock);

self::assertSame($result, $conn->fetchArray($statement, $params, $types));
}
Expand All @@ -587,16 +587,16 @@ public function testFetchColumn(): void

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

$driverStatementMock = $this->createMock(Statement::class);

$driverStatementMock->expects($this->once())
->method('fetchColumn')
->with($column)
->will($this->returnValue($result));
->willReturn($result);

$conn = (new MockBuilderProxy($this->getMockBuilder(Connection::class)))
->onlyMethods(['executeQuery'])
Expand All @@ -606,7 +606,7 @@ public function testFetchColumn(): void
$conn->expects($this->once())
->method('executeQuery')
->with($statement, $params, $types)
->will($this->returnValue($driverStatementMock));
->willReturn($driverStatementMock);

self::assertSame($result, $conn->fetchColumn($statement, $params, $column, $types));
}
Expand All @@ -622,15 +622,15 @@ public function testFetchAll(): void

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

$driverStatementMock = $this->createMock(Statement::class);

$driverStatementMock->expects($this->once())
->method('fetchAll')
->will($this->returnValue($result));
->willReturn($result);

$conn = (new MockBuilderProxy($this->getMockBuilder(Connection::class)))
->onlyMethods(['executeQuery'])
Expand All @@ -640,7 +640,7 @@ public function testFetchAll(): void
$conn->expects($this->once())
->method('executeQuery')
->with($statement, $params, $types)
->will($this->returnValue($driverStatementMock));
->willReturn($driverStatementMock);

self::assertSame($result, $conn->fetchAll($statement, $params, $types));
}
Expand Down Expand Up @@ -714,7 +714,7 @@ public function testCallConnectOnce(string $method, array $params): void

$wrappedConnection
->method('prepare')
->will($this->returnValue($stmt));
->willReturn($stmt);

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

Expand All @@ -735,20 +735,20 @@ public function testPlatformDetectionIsTriggerOnlyOnceOnRetrievingPlatform(): vo

$driverMock->expects($this->once())
->method('connect')
->will($this->returnValue($driverConnectionMock));
->willReturn($driverConnectionMock);

$driverConnectionMock->expects($this->once())
->method('requiresQueryForServerVersion')
->will($this->returnValue(false));
->willReturn(false);

$driverConnectionMock->expects($this->once())
->method('getServerVersion')
->will($this->returnValue('6.6.6'));
->willReturn('6.6.6');

$driverMock->expects($this->once())
->method('createDatabasePlatformForVersion')
->with('6.6.6')
->will($this->returnValue($platformMock));
->willReturn($platformMock);

self::assertSame($platformMock, $connection->getDatabasePlatform());
}
Expand All @@ -761,7 +761,7 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach
->expects($this->atLeastOnce())
->method('fetch')
->with('cacheKey')
->will($this->returnValue(['realKey' => []]));
->willReturn(['realKey' => []]);

$query = 'SELECT * FROM foo WHERE bar = ?';
$params = [666];
Expand All @@ -772,14 +772,14 @@ public function testConnectionParamsArePassedToTheQueryCacheProfileInExecuteCach
$queryCacheProfileMock
->expects($this->any())
->method('getResultCacheDriver')
->will($this->returnValue($resultCacheDriverMock));
->willReturn($resultCacheDriverMock);

// This is our main expectation
$queryCacheProfileMock
->expects($this->once())
->method('generateCacheKeys')
->with($query, $params, $types, $this->params)
->will($this->returnValue(['cacheKey', 'realKey']));
->willReturn(['cacheKey', 'realKey']);

$driver = $this->createMock(Driver::class);
$result = (new Connection($this->params, $driver))
Expand All @@ -797,14 +797,14 @@ public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecute
->expects($this->atLeastOnce())
->method('fetch')
->with('cacheKey')
->will($this->returnValue(['realKey' => []]));
->willReturn(['realKey' => []]);

$queryCacheProfileMock = $this->createMock(QueryCacheProfile::class);

$queryCacheProfileMock
->expects($this->any())
->method('getResultCacheDriver')
->will($this->returnValue($resultCacheDriverMock));
->willReturn($resultCacheDriverMock);

$query = 'SELECT 1';

Expand All @@ -814,7 +814,7 @@ public function testShouldNotPassPlatformInParamsToTheQueryCacheProfileInExecute
->expects($this->once())
->method('generateCacheKeys')
->with($query, [], [], $connectionParams)
->will($this->returnValue(['cacheKey', 'realKey']));
->willReturn(['cacheKey', 'realKey']);

$connectionParams['platform'] = $this->createMock(AbstractPlatform::class);

Expand Down Expand Up @@ -867,13 +867,13 @@ public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGen
$queryCacheProfile
->expects($this->any())
->method('getResultCacheDriver')
->will($this->returnValue($resultCacheDriver));
->willReturn($resultCacheDriver);

$resultCacheDriver
->expects($this->atLeastOnce())
->method('fetch')
->with('cacheKey')
->will($this->returnValue(['realKey' => []]));
->willReturn(['realKey' => []]);

$query = 'SELECT 1';

Expand All @@ -889,7 +889,7 @@ public function testExecuteCacheQueryStripsPlatformFromConnectionParamsBeforeGen
->expects($this->once())
->method('generateCacheKeys')
->with($query, [], [], $paramsWithoutPlatform)
->will($this->returnValue(['cacheKey', 'realKey']));
->willReturn(['cacheKey', 'realKey']);

$connection = new Connection($params, $driver);

Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function testReturnsDatabaseName(): void

$connection->expects($this->once())
->method('getParams')
->will($this->returnValue($params));
->willReturn($params);

self::assertSame($params['dbname'], $this->driver->getDatabase($connection));
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Doctrine/Tests/DBAL/Driver/AbstractMySQLDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public function testReturnsDatabaseName(): void

$statement->expects($this->once())
->method('fetchColumn')
->will($this->returnValue($database));
->willReturn($database);

$connection = $this->getConnectionMock();

$connection->expects($this->once())
->method('getParams')
->will($this->returnValue($params));
->willReturn($params);

$connection->expects($this->once())
->method('query')
->will($this->returnValue($statement));
->willReturn($statement);

self::assertSame($database, $this->driver->getDatabase($connection));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/DBAL/Driver/AbstractOracleDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testReturnsDatabaseName(): void

$connection->expects($this->once())
->method('getParams')
->will($this->returnValue($params));
->willReturn($params);

self::assertSame($params['user'], $this->driver->getDatabase($connection));
}
Expand All @@ -43,7 +43,7 @@ public function testReturnsDatabaseNameWithConnectDescriptor(): void

$connection->expects($this->once())
->method('getParams')
->will($this->returnValue($params));
->willReturn($params);

self::assertSame($params['user'], $this->driver->getDatabase($connection));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ public function testReturnsDatabaseName(): void

$statement->expects($this->once())
->method('fetchColumn')
->will($this->returnValue($database));
->willReturn($database);

$connection = $this->getConnectionMock();

$connection->expects($this->once())
->method('getParams')
->will($this->returnValue($params));
->willReturn($params);

$connection->expects($this->once())
->method('query')
->will($this->returnValue($statement));
->willReturn($statement);

self::assertSame($database, $this->driver->getDatabase($connection));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testReturnsDatabaseName(): void

$connection->expects($this->once())
->method('getParams')
->will($this->returnValue($params));
->willReturn($params);

self::assertSame($params['path'], $this->driver->getDatabase($connection));
}
Expand Down