The problem is the dependency that I am mocking has an expects() method. This class is a dependency on the class I am testing.
setUp() method
$this->test = $this->getMockBuilder(Request::class)->disableOriginalConstructor()
->getMock();
So when I write my test
$this->test->expects($this->once())->method('otherMethod')
->willReturn(0);
This will give an error:
Cannot redeclare Mock_Test_f21c25ee::expects() in ...
How can I solve this?
Edit:
After i tried the suggested solution with the setMethodsExcept() I now have a different error message. I am also using PHPunit 7.5
Declaration of Mock_Test_fa1cb6c5::expects(PHPUnit\Framework\MockObject\Matcher\Invocation $matcher) should be compatible with App\Services\Api\Test::expects()
Note: Forgot to mention i am using Laravel 5.5 which has its own TestBase Class
Edit2: After i tried using the default PHPUnit testcase i still get the same error message as above. (The must be compatible with error)