title: PHPunit expectation on Mock object is not fulfilled
body: <p>Here is my class:</p>
  
  <pre><code>public function __construct(Manager $moduleManager, Source\Yesno $yesNo)
  {
      $this-&gt;moduleManager = $moduleManager;
      $this-&gt;yesNo = $yesNo;
  }
  
  public function my1()
  {
      $this-&gt;moduleManager-&gt;isOutputEnabled('');
      $this-&gt;yesNo-&gt;toOptionArray();
  }
  
  public function my2()
  {
      $this-&gt;moduleManager-&gt;isOutputEnabled('');
      $this-&gt;yesNo-&gt;toOptionArray();
  }
  </code></pre>
  
  <p>Here is my test:</p>
  
  <pre><code>...
      $this-&gt;observerMock = $this-&gt;getMock(
          'path\to\Observer',
          null,
          [$this-&gt;moduleManagerMock, $this-&gt;yesNoMock],
          '',
          true
      );
  ...
  public function testMy1()
  {
      $this-&gt;moduleManagerMock-&gt;expects($this-&gt;exactly(2))-&gt;method('isOutputEnabled');
      $this-&gt;yesNoMock-&gt;expects($this-&gt;exactly(2))-&gt;method('toOptionsArray');
      $this-&gt;observerMock-&gt;my1();
      $this-&gt;observerMock-&gt;my2();
  }
  </code></pre>
  
  <p>Test returns:</p>
  
  <blockquote>
    <p>Expectation failed for method name is equal to 
    when invoked 2 time(s). Method was expected to be called 2 times,
    actually called 0 times.</p>
  </blockquote>
  
  <p>My question is: I have faced with such things few times, but every time I can't understand what is going on. Why first expectation is proper, and 2nd not proper?</p>
  
  <h1>Upd.1</h1>
  
  <p>I forgot to say that I faced with such situation few times.
  Here is what I've noticed. Using xDebug I saw that inside test</p>
  
  <pre><code>[this]
      [moduleManager] =&gt; ModuleManager_Mock_Name_&lt;hash #1&gt;
      [yesNo] =&gt; YesNo_Mock_Name_&lt;hash #2&gt;
      [observerObject] =&gt;
          [moduleManager] =&gt; ModuleManager_Mock_Name_&lt;hash #1&gt;
          [yesNo] =&gt; YesNo_Mock_Name_&lt;hash #3&gt; &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;
  </code></pre>
  
  <p>moduleManager objects has the same cache inside unittest object and inside observer object. If I apply smth on moduleMatcher - it appear in both places</p>
  
  <p>Hash of $unittest->yesNo differ from $observerObject hash. If I set matcher for some method - it applies only inside unittest class!!! </p>
  
  <p>Why did it happen? How to prevent create different objects</p>
  
  <h1>Upd.2 FOUND!</h1>
  
  <p>When you create object through object manager</p>
  
  <pre><code>    $this-&gt;observerMock = $objectManager-&gt;getObject(
          'Observer',
          [
              'moduleManager' =&gt; $this-&gt;moduleManagerMock,
              'yesNo' =&gt; $this-&gt;yesNoMock,
          ]
      );
  </code></pre>
  
  <p>Variables 'moduleManager' and 'yesNo' should be the same as variables in constructor:</p>
  
  <pre><code>public function __construct(Manager $moduleManager, Source\Yesno $yesNo)
  {
      $this-&gt;moduleManager = $moduleManager;
      $this-&gt;yesNo = $yesNo;
  }
  </code></pre>
  
  <p>Here is code where phpunit check this:</p>
  
  <pre><code>    foreach ($method-&gt;getParameters() as $parameter) {
          $parameterName = $parameter-&gt;getName();
          $argClassName = null;
          $defaultValue = null;
  
          if (array_key_exists($parameterName, $arguments)) {
              $constructArguments[$parameterName] = $arguments[$parameterName];
              continue;
          }
  </code></pre>