title: PHPUnit mocks - assert method called
body: <p>i'm new to phpunit and have read the documentation on mock objects but it isn't very clear.</p>
  
  <p>I am trying to write a simple test that asserts a method within a class is called. With the following code, i am testing that when the Client::exchangeArray is called, a call is made to Client::getInputFilter.</p>
  
  <pre><code>class Client implements InputFilterAwareInterface
  {
  
  public function getInputFilter() {
      if(!$this-&gt;_inputFilter){
          $inputFactory = new InputFactory();
          $inputFilter = new InputFilter();
  
          $inputFilter-&gt;add($inputFactory-&gt;createInput(array(
              'name' =&gt; 'id',
              'required' =&gt; true,
              'filters' =&gt; array(
                  array(
                      'name' =&gt; 'Int'
                  )
              )
          )));
  
          $inputFilter-&gt;add($inputFactory-&gt;createInput(array(
              'name' =&gt; 'name',
              'required' =&gt; true,
              'filters' =&gt; array(
                  array(
                      'name' =&gt; 'StripTags'
                  ),
                  array(
                      'name' =&gt; 'StringTrim'
                  ),
                  array(
                       'name' =&gt; 'StripNewLines'      
                  ),
                  array(
                      'name' =&gt; 'Alpha'
                  )
              ),
              'validators' =&gt; array(
                  array(
                      'name' =&gt; 'StringLength',
                      'options' =&gt; array(
                          'encoding' =&gt; 'UTF-8',
                          'min' =&gt; 2,
                          'max' =&gt; 100
                      )
                  )
              )
          )));
  
          $inputFilter-&gt;add($inputFactory-&gt;createInput(array(
              'name' =&gt; 'surname',
              'required' =&gt; true,
              'filters' =&gt; array(
                  array(
                      'name' =&gt; 'StripTags'
                  ),
                  array(
                      'name' =&gt; 'StringTrim'
                  )
              ),
              'validators' =&gt; array(
                  array(
                      'name' =&gt; 'StringLength',
                      'options' =&gt; array(
                          'encoding' =&gt; 'UTF-8',
                          'min' =&gt; 2,
                          'max' =&gt; 100
                      )
                  )
              )
          )));
  
          $inputFilter-&gt;add($inputFactory-&gt;createInput(array(
              'name' =&gt; 'email',
              'required' =&gt; false,
              'filters' =&gt; array(
                  array(
                      'name' =&gt; 'StripTags'
                  ),
                  array(
                      'name' =&gt; 'StringTrim'
                  )
              ),
              'validators' =&gt; array(
                  array(
                      'name' =&gt; 'StringLength',
                      'options' =&gt; array(
                          'encoding' =&gt; 'UTF-8',
                          'min' =&gt; 2,
                          'max' =&gt; 150
                      )
                  ),
                  array(
                      'name' =&gt; 'EmailAddress'
                  )
              )
          )));
  
          $this-&gt;_inputFilter = $inputFilter;
      }
      return $this-&gt;_inputFilter;
  }
  
  public function exchangeArray($data){
      $inputFilter = $this-&gt;getInputFilter();
      $inputFilter-&gt;setData($data);
      if(!$inputFilter-&gt;isValid()){
          throw new \Exception('Invalid client data'); 
      }
  
      $cleanValues = $inputFilter-&gt;getValues();
  
      $this-&gt;_id = (isset($cleanValues['id']) ? $cleanValues['id'] : null);
      $this-&gt;_name = (isset($cleanValues['name']) ? $cleanValues['name'] : null);
      $this-&gt;_surname = (isset($cleanValues['surname']) ? $cleanValues['surname'] : null);
      $this-&gt;_email = (isset($cleanValues['email']) ? $cleanValues['email'] : null);
      }        
  }
  </code></pre>
  
  <p>Here is my test case:</p>
  
  <pre><code>public function testExchangeArrayCallsInputFilter(){
      $data = array('id' =&gt; 54,
              'name' =&gt; 'john',
              'surname' =&gt; 'doe',
              'email' =&gt; 'john.doe@domain.com'
      );
  
      $mock = $this-&gt;getMock('Client', array('exchangeArray'));
      $mock-&gt;expects($this-&gt;once())
           -&gt;method('getInputFilter');
      $mock-&gt;exchangeArray($data);
  }
  </code></pre>
  
  <p>...and i'm getting the following error:</p>
  
  <blockquote>
    <p>Expectation failed for method name is equal to 
    when invoked 1 time(s). Method was expected to be called 1 times,
    actually called 0 times.</p>
  </blockquote>
  
  <p>Where am i going wrong?</p>