title: How do I Mock Methods in a Dependency Class of a Controller
body: <p>I'd like to Mock the <code>getReviews</code> method of the <code>CommentModel</code> so I can test if it's called in the <code>ApiReviewCommentsController</code> Method.</p>
  
  <p>This is my method:</p>
  
  <pre><code>class ApiReviewCommentsController extends ApiController
  {
      private $commentsModel;
  
      public function __construct(CommentsModel $commentsModel)
      {
          $this-&gt;commentsModel = $commentsModel;
          $this-&gt;commentsModel-&gt;getReviewComment();
  
      }
  }
  </code></pre>
  
  <p>This is my test:</p>
  
  <pre><code>public function testThatItShouldAddGetAllCommentsForReviewId(){
  
  
      $reviewId = 1;
  
  
      $commentsModel = $this-&gt;getMockBuilder(CommentsModel::class)-&gt;getMock();
  
      $controller = new ApiReviewCommentsController($commentsModel);
  
      $commentsModel-&gt;expects($this-&gt;once())
          -&gt;method('getReviewComments')
          -&gt;willReturn(false);
  
  }
  </code></pre>
  
  <p>This is my <strong>error</strong>:</p>
  
  <blockquote>
    <p>Expectation failed for method name is equal to
     when invoked 1 time(s).</p>
  </blockquote>
  
  <p>Method was expected to be called 1 times, actually called 0 times.</p>
  
  <p>Please why is the method not called?</p>