title: Using chained partial mocks on an interface used in an artisan command
body: <p>I'm trying to unittest an artisan command in Laravel 5.3. The command calls on functions in a class that is provided to the command constructor as an interface. That interface calls on functions in another class. This is the general setup.</p>
  
  <pre><code>class MyCommand
  {
      public function __construct(MyRepositoryInterface $interface)
      {
          ...
          $this-&gt;interface = $interface;
          ...
      }
  
      public function fire()
      {
          $this-&gt;interface-&gt;useTheSecondClass();
      }
  }
  
  class MyRepository implements MyRepositoryInterface
  {
      public function __construct(MySecondRepositoryInterface $second)
      {
          ...
          $this-&gt;second = $second;
          ...
      }
  
      public function useTheSecondClass()
      {
          $response = $this-&gt;second-&gt;getSomeValue();
      }
  }
  
  class MySecondRepository implements MySecondRepositoryInterface
  {
      /**
       * @return Some\External\Client
       */
      public function getExternalClient()
      {
          ....
          return $external_client;
      }
  
      public function getSomeValue()
      {
          $client = $this-&gt;getExternalClient();
  
          $something = $client-&gt;doSomething();
  
          Event::fire('some event based on $something`);
  
          return $something;
      }
  }
  </code></pre>
  
  <p>I'm attempting to mock the variable returned in <code>MySecondRepository -&gt; getExternalClient()</code> so that I can fake an external API call and use that faked data to test both the <code>MySecondRepository -&gt; getSomeValue()</code> and <code>MyRepository -&gt; useTheSecondClass()</code> functionalities as called from the <code>MyCommand</code> class as such.</p>
  
  <pre><code>public function testMyCommand()
  {
      $external_client_mock = Mockery::mock("Some\External\Client");
      $external_client_mock-&gt;shouldReceive("doSomething")
          -&gt;andReturn("some values");
  
      $second_repository_mock = Mockery::mock("MySecondRepositoryInterface")
          -&gt;makePartial();
      $second_repository_mock-&gt;shouldReceive("getExternalClient")
          -&gt;andReturn($external_client_mock);
  
      $resource = new MyRepository($second_repository_mock);
      $this-&gt;app-&gt;instance("MyRepositoryInterface", $resource);
  
      $class = App::make(MyCommand::class);
      $class-&gt;fire();
  
      ...
  }
  </code></pre>
  
  <p>I have used this exact same mock chain successfully to test the <code>$resource</code> variable directly (e.g., testing <code>$resource-&gt;useTheSecondClass()</code> directly, not through <code>MyCommand</code>), but in this situation, while <code>$second_repository_mock-&gt;getExternalClient()</code> is mocking correctly, the test is still expecting there to be a mocked expectation for <code>$second_repository_mock-&gt;getSomeValue()</code>. Since <code>$second_repository_mock</code> is set to a partial mock, I don't understand why it's still looking for all functions to be mocked.</p>
  
  <p>If I remove the <code>$external_client_mock</code> part and fully mock <code>$second_repository_mock</code> my tests directly related to the artisan command work, however I'd like to test that the event triggered in <code>getSomeValue()</code> is dealt with properly from the artisan command, which I can't do if I can't use the partial mock.</p>
  
  <p>Does anyone have any insight on why this isn't working?</p>