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