From a60b15dfbadc5ea45b827487bb0b0fe4e45ec0b8 Mon Sep 17 00:00:00 2001 From: Christian Kuhn Date: Mon, 27 Mar 2023 15:27:36 +0200 Subject: [PATCH] [TASK] Avoid setMethods() on mocks setMethods() has been removed with phpunit 10. $this->getAccessibleMock() used this to only partially mock a test subject. The patch switches to onlyMethods() now. There is one difference: onlyMethods() fails if a methods that should be mocked does not exist, while setMethods() did not fail on this. So this is more strict now. It was frequently used in core tests mocking ['dummy'] to say "mock no method". Those have to be switched to use 'null' as argument to $this->getAccessibleMock() now. Also, when a class is refactored, and a method that has been previously mocked is removed with the refactoring, the mock has to be adapted to remove the method-mock request from the test as well now, otherwise the test will fail. Releases: main, 7 Resolves: #444 --- Classes/Core/BaseTestCase.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Classes/Core/BaseTestCase.php b/Classes/Core/BaseTestCase.php index 1573b4a7..21587013 100644 --- a/Classes/Core/BaseTestCase.php +++ b/Classes/Core/BaseTestCase.php @@ -124,10 +124,15 @@ protected function getAccessibleMock( } $mockBuilder = $this->getMockBuilder($this->buildAccessibleProxy($originalClassName)) - ->setMethods($methods) ->setConstructorArgs($arguments) ->setMockClassName($mockClassName); + if ($methods === null) { + $mockBuilder->onlyMethods([]); + } elseif (!empty($methods)) { + $mockBuilder->onlyMethods($methods); + } + if (!$callOriginalConstructor) { $mockBuilder->disableOriginalConstructor(); }