From abd57906ecf8be3b2f421216406fbc816e2f8d95 Mon Sep 17 00:00:00 2001 From: soilSpoon Date: Fri, 4 Dec 2020 04:47:11 +0900 Subject: [PATCH] [8.x ]Refactor setMethods to onlyMethods and addMethods `MockBuilder::setMethods` is soft deprecated as of PHPUnit 9 So I refactor the test. Please merge #35474 after merging sebastianbergmann/phpunit#3687 --- tests/Cache/CacheMemcachedStoreTest.php | 12 ++++++------ tests/Database/DatabaseConnectionTest.php | 7 +++---- tests/Validation/ValidationValidatorTest.php | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/Cache/CacheMemcachedStoreTest.php b/tests/Cache/CacheMemcachedStoreTest.php index ab1c19c7c657..bad8313f9f29 100755 --- a/tests/Cache/CacheMemcachedStoreTest.php +++ b/tests/Cache/CacheMemcachedStoreTest.php @@ -66,7 +66,7 @@ public function testSetMethodProperlyCallsMemcache() } Carbon::setTestNow($now = Carbon::now()); - $memcache = $this->getMockBuilder(Memcached::class)->onlyMethods(['set'])->getMock(); + $memcache = $this->getMockBuilder(Memcached::class)->addMethods(['set'])->getMock(); $memcache->expects($this->once())->method('set')->with($this->equalTo('foo'), $this->equalTo('bar'), $this->equalTo($now->timestamp + 60))->willReturn(true); $store = new MemcachedStore($memcache); $result = $store->put('foo', 'bar', 60); @@ -80,7 +80,7 @@ public function testIncrementMethodProperlyCallsMemcache() $this->markTestSkipped('Memcached module not installed'); } - $memcache = $this->getMockBuilder(Memcached::class)->onlyMethods(['increment'])->getMock(); + $memcache = $this->getMockBuilder(Memcached::class)->addMethods(['increment'])->getMock(); $memcache->expects($this->once())->method('increment')->with($this->equalTo('foo'), $this->equalTo(5)); $store = new MemcachedStore($memcache); $store->increment('foo', 5); @@ -92,7 +92,7 @@ public function testDecrementMethodProperlyCallsMemcache() $this->markTestSkipped('Memcached module not installed'); } - $memcache = $this->getMockBuilder(Memcached::class)->onlyMethods(['decrement'])->getMock(); + $memcache = $this->getMockBuilder(Memcached::class)->addMethods(['decrement'])->getMock(); $memcache->expects($this->once())->method('decrement')->with($this->equalTo('foo'), $this->equalTo(5)); $store = new MemcachedStore($memcache); $store->decrement('foo', 5); @@ -104,7 +104,7 @@ public function testStoreItemForeverProperlyCallsMemcached() $this->markTestSkipped('Memcached module not installed'); } - $memcache = $this->getMockBuilder(Memcached::class)->onlyMethods(['set'])->getMock(); + $memcache = $this->getMockBuilder(Memcached::class)->addMethods(['set'])->getMock(); $memcache->expects($this->once())->method('set')->with($this->equalTo('foo'), $this->equalTo('bar'), $this->equalTo(0))->willReturn(true); $store = new MemcachedStore($memcache); $result = $store->forever('foo', 'bar'); @@ -117,7 +117,7 @@ public function testForgetMethodProperlyCallsMemcache() $this->markTestSkipped('Memcached module not installed'); } - $memcache = $this->getMockBuilder(Memcached::class)->onlyMethods(['delete'])->getMock(); + $memcache = $this->getMockBuilder(Memcached::class)->addMethods(['delete'])->getMock(); $memcache->expects($this->once())->method('delete')->with($this->equalTo('foo')); $store = new MemcachedStore($memcache); $store->forget('foo'); @@ -129,7 +129,7 @@ public function testFlushesCached() $this->markTestSkipped('Memcached module not installed'); } - $memcache = $this->getMockBuilder(Memcached::class)->onlyMethods(['flush'])->getMock(); + $memcache = $this->getMockBuilder(Memcached::class)->addMethods(['flush'])->getMock(); $memcache->expects($this->once())->method('flush')->willReturn(true); $store = new MemcachedStore($memcache); $result = $store->flush(); diff --git a/tests/Database/DatabaseConnectionTest.php b/tests/Database/DatabaseConnectionTest.php index 2be19458ed62..47764954d2ef 100755 --- a/tests/Database/DatabaseConnectionTest.php +++ b/tests/Database/DatabaseConnectionTest.php @@ -62,7 +62,7 @@ public function testSelectProperlyCallsPDO() $writePdo = $this->getMockBuilder(DatabaseConnectionTestMockPDO::class)->onlyMethods(['prepare'])->getMock(); $writePdo->expects($this->never())->method('prepare'); $statement = $this->getMockBuilder('PDOStatement') - ->setMethods(['setFetchMode', 'execute', 'fetchAll', 'bindValue']) + ->onlyMethods(['setFetchMode', 'execute', 'fetchAll', 'bindValue']) ->getMock(); $statement->expects($this->once())->method('setFetchMode'); $statement->expects($this->once())->method('bindValue')->with('foo', 'bar', 2); @@ -154,9 +154,8 @@ public function testTransactionLevelNotIncrementedOnTransactionException() public function testBeginTransactionMethodRetriesOnFailure() { $pdo = $this->createMock(DatabaseConnectionTestMockPDO::class); - $pdo->expects($this->at(0)) - ->method('beginTransaction') - ->will($this->throwException(new ErrorException('server has gone away'))); + $pdo->method('beginTransaction') + ->willReturnOnConsecutiveCalls($this->throwException(new ErrorException('server has gone away'))); $connection = $this->getMockConnection(['reconnect'], $pdo); $connection->expects($this->once())->method('reconnect'); $connection->beginTransaction(); diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index a2319b4cfa8e..2522f397f4f6 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -2872,7 +2872,7 @@ public function testValidateImage() $v = new Validator($trans, ['x' => $file7], ['x' => 'Image']); $this->assertTrue($v->passes()); - $file2 = $this->getMockBuilder(UploadedFile::class)->setMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock(); + $file2 = $this->getMockBuilder(UploadedFile::class)->onlyMethods(['guessExtension', 'getClientOriginalExtension'])->setConstructorArgs($uploadedFile)->getMock(); $file2->expects($this->any())->method('guessExtension')->willReturn('jpg'); $file2->expects($this->any())->method('getClientOriginalExtension')->willReturn('jpg'); $v = new Validator($trans, ['x' => $file2], ['x' => 'Image']);