title: PHPUnit testing Mock's method which takes closure as a param
body: <p>I write a class which populate DI container with services from yaml file. I have problem with testing a below method:</p>
  
  <pre><code>private function parseServices(array $services)
  {
      foreach ($services as $name =&gt; $attr) {
          $this-&gt;container[$name] = function() use($attr) {
              $reflect = new \ReflectionClass($attr["class"]);
              $args = $this-&gt;parseArguments($attr["arguments"]);
  
              return $reflect-&gt;newInstanceArgs($args);
          };
      }
  }
  </code></pre>
  
  <p><code>$services</code> is an array with services:</p>
  
  <pre><code>array(
      serviceName =&gt; array(
          class =&gt; className,
          arguments =&gt; array(...)
      )
  )
  </code></pre>
  
  <p>A method <code>parseArguments()</code> returns a simple array of arguments for a constructor. For tests <code>$container</code> is a mock. I want to test that <code>container</code> is called one time for every service witch specific parameters. How can I test this? My idea was something like this:</p>
  
  <pre><code>$this-&gt;container
       -&gt;expects($this-&gt;at(3))
       -&gt;method('offsetSet')
       -&gt;with('demo',$this-&gt;callback());
  </code></pre>
  
  <p>But this doesn't work.</p>
  
  <h1>EDIT</h1>
  
  <p>The responsibility of this method and even of whole class is populating a container. So maybe the best way to test it is to just check if container is populate correctly? As I wrote in a comment - just don't mock the container but use a concrete implementation. What do you think about it?</p>