Development

Changeset 23569

You must first sign up to be able to contribute.

Changeset 23569

Show
Ignore:
Timestamp:
11/03/09 15:02:40 (4 years ago)
Author:
bschussek
Message:

Added: A return value can be configured even if a callback is specified for a mocked method

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tools/lime/branches/2.0/lib/mock/LimeMockInvocationExpectation.php

    r21377 r23569  
    5656    $output       = null, 
    5757    $matchers     = array(), 
     58    $returns      = false, 
    5859    $returnValue  = null, 
    5960    $exception    = null, 
     
    144145    if (!is_null($this->callback)) 
    145146    { 
    146       return call_user_func_array($this->callback, $invocation->getParameters()); 
     147      $result = call_user_func_array($this->callback, $invocation->getParameters()); 
     148 
     149      return $this->returns ? $this->returnValue : $result; 
    147150    } 
    148151 
     
    323326  public function returns($value) 
    324327  { 
     328    $this->returns = true; 
    325329    $this->returnValue = $value; 
    326330 
  • tools/lime/branches/2.0/test/unit/mock/LimeMockTest.php

    r23567 r23569  
    100100 
    101101 
    102 $t = new LimeTest(94); 
     102$t = new LimeTest(96); 
    103103 
    104104 
     
    741741 
    742742 
     743// @Test: If a callback AND a return value is configured, the return value of the callback is ignored 
     744 
     745  // test 
     746  $m->testMethod()->callback(array('TestCallbackClass', 'callback'))->returns('elvis sure is dead'); 
     747  $m->replay(); 
     748  $value = $m->testMethod(); 
     749  // assertions 
     750  $t->is($value, 'elvis sure is dead', 'The return value of the callback was ignored'); 
     751 
     752 
     753// @Test: The return value of the callback is ignored even if the configured return value is NULL 
     754 
     755  // test 
     756  $m->testMethod()->callback(array('TestCallbackClass', 'callback'))->returns(null); 
     757  $m->replay(); 
     758  $value = $m->testMethod(); 
     759  // assertions 
     760  $t->same($value, null, 'The return value of the callback was ignored'); 
     761 
     762 
    743763// @Test: Parameters are passed to the callback correctly, if any parameters are expected 
    744764