Skip to content

Commit 6673906

Browse files
authored
Add GetMockBuilderGetMockToCreateMockRector rule to rector (#4951)
1 parent 3d664de commit 6673906

File tree

127 files changed

+294
-746
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+294
-746
lines changed

module/VuFind/src/VuFindTest/Unit/RecommendDeferredTestCase.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ protected function getMockResults($params = null)
8181
if (null === $params) {
8282
$params = $this->getMockParams();
8383
}
84-
$results = $this->getMockBuilder(\VuFind\Search\Solr\Results::class)
85-
->disableOriginalConstructor()->getMock();
84+
$results = $this->createMock(\VuFind\Search\Solr\Results::class);
8685
$results->method('getParams')->willReturn($params);
8786
return $results;
8887
}
@@ -99,8 +98,7 @@ protected function getMockParams($query = null)
9998
if (null === $query) {
10099
$query = new \VuFindSearch\Query\Query('foo', 'bar');
101100
}
102-
$params = $this->getMockBuilder(\VuFind\Search\Solr\Params::class)
103-
->disableOriginalConstructor()->getMock();
101+
$params = $this->createMock(\VuFind\Search\Solr\Params::class);
104102
$params->method('getQuery')->willReturn($query);
105103
return $params;
106104
}

module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/CommentRecordTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function testSuccessfulTransaction(): void
150150
->willReturn(1);
151151
$this->container->set(CommentsServiceInterface::class, $mockCommentsService);
152152

153-
$driver = $this->getMockBuilder(DefaultRecord::class)->getMock();
153+
$driver = $this->createMock(DefaultRecord::class);
154154
$driver->expects($this->once())
155155
->method('isRatingAllowed')
156156
->willReturn(true);

module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/RecommendTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ protected function getMockParams($query = null)
6363
if (null === $query) {
6464
$query = new \VuFindSearch\Query\Query('foo', 'bar');
6565
}
66-
$params = $this->getMockBuilder(\VuFind\Search\Solr\Params::class)
67-
->disableOriginalConstructor()->getMock();
66+
$params = $this->createMock(\VuFind\Search\Solr\Params::class);
6867
$params->method('getQuery')->willReturn($query);
6968
return $params;
7069
}
@@ -81,8 +80,7 @@ protected function getMockResults($params = null): Results
8180
if (null === $params) {
8281
$params = $this->getMockParams();
8382
}
84-
$results = $this->getMockBuilder(Results::class)
85-
->disableOriginalConstructor()->getMock();
83+
$results = $this->createMock(Results::class);
8684
$results->method('getParams')->willReturn($params);
8785
return $results;
8886
}

module/VuFind/tests/unit-tests/src/VuFindTest/AjaxHandler/SystemStatusTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function testSuccessfulResponse(): void
142142
*/
143143
protected function getMockRequestParams(array $requestParams = []): Params
144144
{
145-
$params = $this->getMockBuilder(Params::class)->getMock();
145+
$params = $this->createMock(Params::class);
146146
$params->method('fromQuery')
147147
->willReturnCallback(
148148
function ($param, $default = null) use ($requestParams) {

module/VuFind/tests/unit-tests/src/VuFindTest/Auth/ManagerTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ public function testGetSelectableAuthOptions(): void
9696

9797
// Advanced case -- ChoiceAuth's getSelectableAuthOptions returns false.
9898
$pm = $this->getMockPluginManager();
99-
$mockChoice = $this->getMockBuilder(\VuFind\Auth\ChoiceAuth::class)
100-
->disableOriginalConstructor()
101-
->getMock();
99+
$mockChoice = $this->createMock(\VuFind\Auth\ChoiceAuth::class);
102100
$mockChoice->method('getSelectableAuthOptions')->willReturn(false);
103101
$pm->setService('ChoiceAuth2', $mockChoice);
104102
$config = ['Authentication' => ['method' => 'ChoiceAuth2']];

module/VuFind/tests/unit-tests/src/VuFindTest/Auth/MultiILSTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,7 @@ protected function getMockMultiBackend(array $onlyMethods = []): MockObject&Mult
248248
$onlyMethods[] = 'getConfig';
249249
$onlyMethods[] = 'patronLogin';
250250
$configManager = $this->container->get(\VuFind\Config\ConfigManagerInterface::class);
251-
$ilsAuth = $this->getMockBuilder(\VuFind\Auth\ILSAuthenticator::class)
252-
->disableOriginalConstructor()
253-
->getMock();
251+
$ilsAuth = $this->createMock(\VuFind\Auth\ILSAuthenticator::class);
254252
$driverManager
255253
= $this->getMockBuilder(\VuFind\ILS\Driver\PluginManager::class)
256254
->setConstructorArgs([$this->container])

module/VuFind/tests/unit-tests/src/VuFindTest/CSV/ImporterTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ public function testEncodingMismatch(): void
249249
*/
250250
public function testImportInLiveMode(): void
251251
{
252-
$mockWriter = $this->getMockBuilder(\VuFind\Solr\Writer::class)
253-
->disableOriginalConstructor()->getMock();
252+
$mockWriter = $this->createMock(\VuFind\Solr\Writer::class);
254253
$mockWriter->expects($this->once())->method('save')->with(
255254
$this->equalTo('Solr'),
256255
$this->callback(
@@ -284,8 +283,7 @@ function ($doc) {
284283
*/
285284
public function testImportInSmallBatches(): void
286285
{
287-
$mockWriter = $this->getMockBuilder(\VuFind\Solr\Writer::class)
288-
->disableOriginalConstructor()->getMock();
286+
$mockWriter = $this->createMock(\VuFind\Solr\Writer::class);
289287
$mockWriter->expects($this->exactly(3))->method('save')->with(
290288
$this->equalTo('Solr'),
291289
$this->callback(

module/VuFind/tests/unit-tests/src/VuFindTest/Config/YamlReaderTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ public function testCacheWrite()
6464
->willReturn(null);
6565
$cache->expects($this->once())->method('setItem')
6666
->with($this->matchesRegularExpression('/\d+/'), $this->equalTo($yamlData));
67-
$manager = $this->getMockBuilder(\VuFind\Cache\Manager::class)
68-
->disableOriginalConstructor()
69-
->getMock();
67+
$manager = $this->createMock(\VuFind\Cache\Manager::class);
7068
$manager->expects($this->once())->method('getCache')
7169
->with($this->equalTo('yaml'))
7270
->willReturn($cache);
@@ -95,9 +93,7 @@ public function testCacheRead()
9593
$cache->expects($this->once())->method('getItem')
9694
->willReturn($yamlData);
9795
$cache->expects($this->never())->method('setItem');
98-
$manager = $this->getMockBuilder(\VuFind\Cache\Manager::class)
99-
->disableOriginalConstructor()
100-
->getMock();
96+
$manager = $this->createMock(\VuFind\Cache\Manager::class);
10197
$manager->expects($this->once())->method('getCache')
10298
->with($this->equalTo('yaml'))
10399
->willReturn($cache);
@@ -124,9 +120,7 @@ public function testCacheForcedReload()
124120
$cache->expects($this->exactly(2))->method('getItem')
125121
->willReturn($yamlData);
126122
$cache->expects($this->never())->method('setItem');
127-
$manager = $this->getMockBuilder(\VuFind\Cache\Manager::class)
128-
->disableOriginalConstructor()
129-
->getMock();
123+
$manager = $this->createMock(\VuFind\Cache\Manager::class);
130124
$manager->expects($this->exactly(2))->method('getCache')
131125
->with($this->equalTo('yaml'))
132126
->willReturn($cache);

module/VuFind/tests/unit-tests/src/VuFindTest/Content/Covers/BokinfoTest.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,8 @@ class BokinfoTest extends \PHPUnit\Framework\TestCase
5858
*/
5959
protected function getMockRequest(): Request
6060
{
61-
$request = $this->getMockBuilder(Request::class)
62-
->disableOriginalConstructor()
63-
->getMock();
64-
$headers = $this->getMockBuilder(Headers::class)
65-
->disableOriginalConstructor()
66-
->getMock();
61+
$request = $this->createMock(Request::class);
62+
$headers = $this->createMock(Headers::class);
6763
$request->expects($this->once())->method('getHeaders')
6864
->willReturn($headers);
6965
$headers->expects($this->once())->method('addHeaderLine')
@@ -81,9 +77,7 @@ protected function getMockRequest(): Request
8177
*/
8278
protected function getMockResponse(): Response
8379
{
84-
return $this->getMockBuilder(Response::class)
85-
->disableOriginalConstructor()
86-
->getMock();
80+
return $this->createMock(Response::class);
8781
}
8882

8983
/**
@@ -93,9 +87,7 @@ protected function getMockResponse(): Response
9387
*/
9488
protected function getMockClient(): Client
9589
{
96-
$client = $this->getMockBuilder(Client::class)
97-
->disableOriginalConstructor()
98-
->getMock();
90+
$client = $this->createMock(Client::class);
9991
$client->expects($this->once())->method('setOptions')
10092
->with($this->equalTo(['useragent' => 'VuFind', 'keepalive' => true]));
10193
return $client;
@@ -108,9 +100,7 @@ protected function getMockClient(): Client
108100
*/
109101
protected function getMockService(): HttpService
110102
{
111-
$service = $this->getMockBuilder(HttpService::class)
112-
->disableOriginalConstructor()
113-
->getMock();
103+
$service = $this->createMock(HttpService::class);
114104
$url1 = 'https://api.bokinfo.se/book/get/9789129697285';
115105
$url2 = 'https://fake-url';
116106
$client1 = $this->getMockClient();

module/VuFind/tests/unit-tests/src/VuFindTest/Content/Covers/OrbTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ protected function getLoader(?string $fixtureFile = null, string $expectedEAN =
5959
{
6060
$loader = new Orb('http://foo', 'fakeuser', 'fakekey');
6161
if ($fixtureFile) {
62-
$mockDownloader = $this->getMockBuilder(CachingDownloader::class)
63-
->disableOriginalConstructor()
64-
->getMock();
62+
$mockDownloader = $this->createMock(CachingDownloader::class);
6563
$fixture = $this->getFixture($fixtureFile);
6664
$mockDownloader->expects($this->once())->method('downloadJson')
6765
->with($this->equalTo("https://fakeuser:fakekey@http://foo/products?eans=$expectedEAN&sort=ean_asc"))

0 commit comments

Comments
 (0)