title: Laravel: how to mock dependency injection class methods
body: <p>I'm using the <a href="https://github.com/KnpLabs/php-github-api" rel="noreferrer">GitHub API</a> through a <a href="https://github.com/GrahamCampbell/Laravel-GitHub" rel="noreferrer">Laravel API Wrapper</a>. I've created a dependency injection class. How can I mock the <code>exists</code> method within the <code>App\Http\GitHub.php</code> class?</p>
  
  <p><code>App\Http\GitHub.php</code>:</p>
  
  <pre><code>use GrahamCampbell\GitHub\GitHubManager;
  
  class Github
  {
      public $username;
  
      public $repository;
  
      public function __construct($username, $repository, GitHubManager $github)
      {
          $this-&gt;username = $username;
  
          $this-&gt;repository = $repository;
  
          $this-&gt;github = $github;
      }
  
      public static function make($username, $repository)
      {
          return new static($username, $repository, app(GitHubManager::class));
      }
  
      /**
       * Checks that a given path exists in a repository.
       *
       * @param  string  $path
       * @return bool
       */
      public function exists($path)
      {
          return $this-&gt;github-&gt;repository()-&gt;contents()-&gt;exists($this-&gt;username, $this-&gt;repository, $path);
      }
  }
  </code></pre>
  
  <p>Test:</p>
  
  <pre><code>    use App\Http\GitHub;
      public function test_it_can_check_if_github_file_exists()
      {
          $m = Mockery::mock(GitHub::class);
          $m-&gt;shouldReceive('exists')-&gt;andReturn(true);
          app()-&gt;instance(GitHub::class, $m);
  
          $github = GitHub::make('foo', 'bar');
  
          $this-&gt;assertTrue($github-&gt;exists('composer.lock'));
      }
  </code></pre>
  
  <p>Running this test actually hits the API rather than just returning the mocked <code>true</code> value, what am I doing wrong here?</p>