Development

Changeset 20976

You must first sign up to be able to contribute.

Changeset 20976

Show
Ignore:
Timestamp:
08/09/09 22:21:17 (5 years ago)
Author:
bschussek
Message:

Improved usability of mock exception

Files:

Legend:

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

    r20309 r20976  
    2828    if (!$this->verified && !$this->failOnVerify && ($this->expectNothing || count($this->invocations) > 0)) 
    2929    { 
    30       throw new LimeAssertionException('Unexpected method call', $invocation); 
     30      throw new LimeMockException($invocation, array(), array()); 
    3131    } 
    3232  } 
  • tools/lime/branches/2.0-experimental/lib/mock/LimeMockException.php

    • Property svn:mergeinfo set
    r20970 r20976  
    11<?php 
    22 
    3 class LimeMockInvocationException extends Exception 
     3class LimeMockException extends Exception 
    44{ 
    55  private 
     
    1515    $this->pastInvocations = $pastInvocations; 
    1616 
    17     parent::__construct('Unexpected method call: ' . $invocation); 
     17    parent::__construct('Unexpected call: ' . $invocation); 
     18  } 
     19 
     20  public function getInvocation() 
     21  { 
     22    return $this->invocation; 
     23  } 
     24 
     25  public function getExpectedInvocations() 
     26  { 
     27    return $this->expectedInvocations; 
     28  } 
     29 
     30  public function getPastInvocations() 
     31  { 
     32    return $this->pastInvocations; 
    1833  } 
    1934} 
  • tools/lime/branches/2.0-experimental/lib/mock/template/mocked_class.tpl

    r20955 r20976  
    1313  } 
    1414   
    15   public function __call($method, array $parameters) 
     15  public function __call($method, $parameters) 
    1616  { 
    17     return $this->state->invoke($this->class, $method, $parameters); 
     17    try 
     18    { 
     19      return $this->state->invoke($this->class, $method, $parameters); 
     20    } 
     21    catch (LimeMockException $e) 
     22    { 
     23      // hide the internal trace to not distract when debugging test errors 
     24      throw new LimeMockException($e->getInvocation(), $e->getExpectedInvocations(), $e->getPastInvocations()); 
     25    } 
    1826  } 
    1927   
     
    3038  <?php if ($generate_methods): ?> 
    3139  public function replay() { return $this->__lime_replay(); } 
    32   public function any($method, array $parameters = array()) { return $this->state->invoke($this->class, $method); } 
     40  public function any($method) { return $this->__call($method, LimeMockInvocation::ANY_PARAMETERS); } 
    3341  public function reset() { return $this->state->reset(); } 
    3442  public function verify() { return $this->state->verify(); } 
  • tools/lime/branches/2.0-experimental/lib/output/LimeOutputConsoleDetailed.php

    r20975 r20976  
    143143    $this->printer->printLargeBox($message, LimePrinter::ERROR); 
    144144 
    145     if ($this->options['verbose']) 
    146     { 
    147       $this->printer->printLine('Exception trace:', LimePrinter::COMMENT); 
    148  
    149       $this->printTrace(null, $exception->getFile(), $exception->getLine()); 
    150  
    151       foreach ($exception->getTrace() as $trace) 
    152       { 
    153         if (array_key_exists('class', $trace)) 
    154         { 
    155           $method = sprintf('%s%s%s()', $trace['class'], $trace['type'], $trace['function']); 
    156         } 
    157         else 
    158         { 
    159           $method = sprintf('%s()', $trace['function']); 
    160         } 
    161  
    162         if (array_key_exists('file', $trace)) 
    163         { 
    164           $this->printTrace($method, $trace['file'], $trace['line']); 
    165         } 
    166         else 
    167         { 
    168           $this->printTrace($method); 
    169         } 
    170       } 
    171  
    172       $this->printer->printLine(''); 
    173     } 
     145    $this->printer->printLine('Exception trace:', LimePrinter::COMMENT); 
     146 
     147    $this->printTrace(null, $exception->getFile(), $exception->getLine()); 
     148 
     149    foreach ($exception->getTrace() as $trace) 
     150    { 
     151      // hide the part of the trace that is responsible for getting the 
     152      // annotations to work 
     153      if (strpos($trace['function'], '__lime_annotation_') === 0 && !$this->options['verbose']) 
     154      { 
     155        break; 
     156      } 
     157 
     158      if (array_key_exists('class', $trace)) 
     159      { 
     160        $method = sprintf('%s%s%s()', $trace['class'], $trace['type'], $trace['function']); 
     161      } 
     162      else 
     163      { 
     164        $method = sprintf('%s()', $trace['function']); 
     165      } 
     166 
     167      if (array_key_exists('file', $trace)) 
     168      { 
     169        $this->printTrace($method, $trace['file'], $trace['line']); 
     170      } 
     171      else 
     172      { 
     173        $this->printTrace($method); 
     174      } 
     175    } 
     176 
     177    $this->printer->printLine(''); 
    174178  } 
    175179 
  • tools/lime/branches/2.0-experimental/test/unit/mock/LimeMockStrictTest.php

    r20332 r20976  
    5151  $m->method2(); 
    5252  $m->replay(); 
    53   $t->expect('LimeAssertionException'); 
     53  $t->expect('LimeMockException'); 
    5454  // test 
    5555  $m->method2(); 
     
    6262  $m->replay(); 
    6363  $m->method1(); 
    64   $t->expect('LimeAssertionException'); 
     64  $t->expect('LimeMockException'); 
    6565  $m->method2(); 
    6666 
     
    9191  $m->method2(); 
    9292  $m->replay(); 
    93   $t->expect('LimeAssertionException'); 
     93  $t->expect('LimeMockException'); 
    9494  // test 
    9595  $m->method1(); 
     
    122122  $m->method2(); 
    123123  $m->replay(); 
    124   $t->expect('LimeAssertionException'); 
     124  $t->expect('LimeMockException'); 
    125125  // test 
    126126  $m->method2(); 
  • tools/lime/branches/2.0-experimental/test/unit/mock/LimeMockTest.php

    r20955 r20976  
    4848{ 
    4949  public function __construct() {} 
    50   public function __call($method, array $args) {} 
     50  public function __call($method, $args) {} 
    5151  public function __lime_replay() {} 
    5252  public function __lime_getState() {} 
     
    285285  $m->testMethod(1, 'Foobar'); 
    286286  $m->replay(); 
    287   $t->expect('LimeAssertionException'); 
     287  $t->expect('LimeMockException'); 
    288288  // test 
    289289  $m->testMethod(1); 
     
    295295  $m->testMethod(1, 'Foobar'); 
    296296  $m->replay(); 
    297   $t->expect('LimeAssertionException'); 
     297  $t->expect('LimeMockException'); 
    298298  // test 
    299299  $m->testMethod('Foobar', 1); 
     
    389389  $m->testMethod(1); 
    390390  $m->replay(); 
    391   $t->expect('LimeAssertionException'); 
     391  $t->expect('LimeMockException'); 
    392392  // test 
    393393  $m->testMethod('1'); 
     
    427427  $m->testMethod(1); 
    428428  $m->testMethod(1); 
    429   $t->expect('LimeAssertionException'); 
     429  $t->expect('LimeMockException'); 
    430430  // test 
    431431  $m->testMethod(1); 
     
    451451  $m->replay(); 
    452452  $m->testMethod(1); 
    453   $t->expect('LimeAssertionException'); 
     453  $t->expect('LimeMockException'); 
    454454  // test 
    455455  $m->testMethod(); 
     
    574574  $m->testMethod(); 
    575575  $m->testMethod(); 
    576   $t->expect('LimeAssertionException'); 
     576  $t->expect('LimeMockException'); 
    577577  $m->testMethod(); 
    578578 
     
    599599  $m->replay(); 
    600600  $m->testMethod(1, 2, 3); 
    601   $t->expect('LimeAssertionException'); 
     601  $t->expect('LimeMockException'); 
    602602  $m->testMethod(); 
    603603 
     
    610610  $m->testMethod(1)->strict(); 
    611611  $m->replay(); 
    612   $t->expect('LimeAssertionException'); 
     612  $t->expect('LimeMockException'); 
    613613  // test 
    614614  $m->testMethod('1'); 
     
    656656  $m->setExpectNothing(); 
    657657  $m->replay(); 
    658   $t->expect('LimeAssertionException'); 
    659   // test 
    660   $m->testMethod(); 
     658  $t->expect('LimeMockException'); 
     659  // test 
     660  $m->testMethod(); 
  • tools/lime/branches/2.0-experimental/test/unit/output/LimeOutputConsoleDetailedTest.php

    r20975 r20976  
    1414LimeAnnotationSupport::enable(); 
    1515 
    16 $t = new LimeTest(58); 
     16$t = new LimeTest(64); 
    1717 
    1818// @Before 
     
    218218  // fixtures 
    219219  $printer->printLargeBox("LimeError: A very important error\n(in /test/file on line 11)", LimePrinter::ERROR); 
     220  $printer->printLine('Exception trace:', LimePrinter::COMMENT); 
     221  $printer->any('printText')->atLeastOnce(); 
     222  $printer->any('printLine')->atLeastOnce(); 
    220223  $printer->replay(); 
    221224  // test 
     
    230233  $output = new LimeOutputConsoleDetailed($printer, array('base_dir' => '/test')); 
    231234  $printer->printLargeBox("LimeError: A very important error\n(in /file on line 11)", LimePrinter::ERROR); 
     235  $printer->printLine('Exception trace:', LimePrinter::COMMENT); 
     236  $printer->any('printText')->atLeastOnce(); 
     237  $printer->any('printLine')->atLeastOnce(); 
    232238  $printer->replay(); 
    233239  // test