Skip to content

Commit cdc920c

Browse files
committed
Refactor setMethods to onlyMethods and addMethods
`MockBuilder::setMethods` is soft deprecated as of PHPUnit 9 So I refactor the test. Please merge laravel#35474 after merging sebastianbergmann/phpunit#3687
1 parent b89363b commit cdc920c

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

tests/Cache/CacheMemcachedStoreTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function testGetReturnsNullWhenNotFound()
1616
$this->markTestSkipped('Memcached module not installed');
1717
}
1818

19-
$memcache = $this->getMockBuilder(stdClass::class)->addMethods(['get', 'getResultCode'])->getMock();
19+
$memcache = $this->getMockBuilder(stdClass::class)->onlyMethods(['get', 'getResultCode'])->getMock();
2020
$memcache->expects($this->once())->method('get')->with($this->equalTo('foo:bar'))->willReturn(null);
2121
$memcache->expects($this->once())->method('getResultCode')->willReturn(1);
2222
$store = new MemcachedStore($memcache, 'foo');
@@ -29,7 +29,7 @@ public function testMemcacheValueIsReturned()
2929
$this->markTestSkipped('Memcached module not installed');
3030
}
3131

32-
$memcache = $this->getMockBuilder(stdClass::class)->addMethods(['get', 'getResultCode'])->getMock();
32+
$memcache = $this->getMockBuilder(stdClass::class)->onlyMethods(['get', 'getResultCode'])->getMock();
3333
$memcache->expects($this->once())->method('get')->willReturn('bar');
3434
$memcache->expects($this->once())->method('getResultCode')->willReturn(0);
3535
$store = new MemcachedStore($memcache);
@@ -42,7 +42,7 @@ public function testMemcacheGetMultiValuesAreReturnedWithCorrectKeys()
4242
$this->markTestSkipped('Memcached module not installed');
4343
}
4444

45-
$memcache = $this->getMockBuilder(stdClass::class)->addMethods(['getMulti', 'getResultCode'])->getMock();
45+
$memcache = $this->getMockBuilder(stdClass::class)->onlyMethods(['getMulti', 'getResultCode'])->getMock();
4646
$memcache->expects($this->once())->method('getMulti')->with(
4747
['foo:foo', 'foo:bar', 'foo:baz']
4848
)->willReturn([

tests/Database/DatabaseConnectionTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testSelectProperlyCallsPDO()
6262
$writePdo = $this->getMockBuilder(DatabaseConnectionTestMockPDO::class)->onlyMethods(['prepare'])->getMock();
6363
$writePdo->expects($this->never())->method('prepare');
6464
$statement = $this->getMockBuilder('PDOStatement')
65-
->setMethods(['setFetchMode', 'execute', 'fetchAll', 'bindValue'])
65+
->onlyMethods(['setFetchMode', 'execute', 'fetchAll', 'bindValue'])
6666
->getMock();
6767
$statement->expects($this->once())->method('setFetchMode');
6868
$statement->expects($this->once())->method('bindValue')->with('foo', 'bar', 2);
@@ -154,9 +154,8 @@ public function testTransactionLevelNotIncrementedOnTransactionException()
154154
public function testBeginTransactionMethodRetriesOnFailure()
155155
{
156156
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
157-
$pdo->expects($this->at(0))
158-
->method('beginTransaction')
159-
->will($this->throwException(new ErrorException('server has gone away')));
157+
$pdo->method('beginTransaction')
158+
->willReturnOnConsecutiveCalls($this->throwException(new ErrorException('server has gone away')));
160159
$connection = $this->getMockConnection(['reconnect'], $pdo);
161160
$connection->expects($this->once())->method('reconnect');
162161
$connection->beginTransaction();

tests/Validation/ValidationValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2872,7 +2872,7 @@ public function testValidateImage()
28722872
$v = new Validator($trans, ['x' => $file7], ['x' => 'Image']);
28732873
$this->assertTrue($v->passes());
28742874

2875-
$file2 = $this->getMockBuilder(UploadedFile::class)->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
2875+
$file2 = $this->getMockBuilder(UploadedFile::class)->onlyMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock();
28762876
$file2->expects($this->any())->method('guessExtension')->willReturn('jpg');
28772877
$file2->expects($this->any())->method('getClientOriginalExtension')->willReturn('jpg');
28782878
$v = new Validator($trans, ['x' => $file2], ['x' => 'Image']);

0 commit comments

Comments
 (0)