Development

Changeset 20332

You must first sign up to be able to contribute.

Changeset 20332

Show
Ignore:
Timestamp:
07/19/09 20:28:51 (5 years ago)
Author:
bschussek
Message:

Changed LimeTest? to use new LimeOutput? classes

Files:

Legend:

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

    r20125 r20332  
    7474      $resultFile = tempnam(sys_get_temp_dir(), 'lime'); 
    7575 
    76       list($return, $output) = $this->shell->execute(<<<EOF 
    77 include('$file'); 
    78 file_put_contents('$resultFile', serialize(LimeTest::toArray())); 
    79 EOF 
    80       ); 
    81  
    82       $output = file_get_contents($resultFile); 
    83       $stats['output'] = $output ? unserialize($output) : ''; 
     76      list($return, $output) = $this->shell->execute($file, array('--array', '--serialize')); 
     77 
     78      $stats['output'] = $output ? @unserialize($output) : ''; 
    8479      if (!$stats['output']) 
    8580      { 
  • tools/lime/branches/2.0-experimental/lib/LimeTest.php

    r20278 r20332  
    2323 
    2424  protected 
    25     $nbTests            = 0, 
    26     $output             = null, 
    27     $results            = array(), 
    28     $options            = array(), 
    29     $expectedException  = null, 
    30     $expectedCode       = null, 
    31     $actualException    = null, 
    32     $actualCode         = null; 
    33  
    34   static protected 
    35     $allResults = array(); 
     25    $output               = null, 
     26    $options              = array(), 
     27    $expectedException    = null, 
     28    $expectedCode         = null, 
     29    $actualException      = null, 
     30    $actualCode           = null, 
     31    $expectedExceptionAt  = null; 
    3632 
    3733  public function __construct($plan = null, array $options = array()) 
     
    4440    ), $options); 
    4541 
    46     $this->output = $this->options['output'] ? $this->options['output'] : new LimeOutput($this->options['force_colors']); 
     42    list ($file, $line) = self::findCaller(); 
     43 
     44    $this->output = $this->options['output'] ? $this->options['output'] : $this->getDefaultOutput($this->options['force_colors']); 
     45    $this->output->plan($plan, $file); 
     46 
    4747    $this->options['base_dir'] = realpath($this->options['base_dir']); 
    48  
    49     $caller = $this->findCaller(debug_backtrace()); 
    50     self::$allResults[] = array( 
    51       'file'  => $caller[0], 
    52       'tests' => array(), 
    53       'stats' => array('plan' => $plan, 'total' => 0, 'failed' => array(), 'passed' => array(), 'skipped' => array()), 
    54     ); 
    55  
    56     $this->results = &self::$allResults[count(self::$allResults) - 1]; 
    57  
    58     null !== $plan and $this->output->echoln(sprintf("1..%d", $plan)); 
    59   } 
    60  
    61   static public function reset() 
    62   { 
    63     self::$allResults = array(); 
    64   } 
    65  
    66   static public function toArray() 
    67   { 
    68     return self::$allResults; 
     48  } 
     49 
     50  public function __destruct() 
     51  { 
     52    $this->output->flush(); 
     53  } 
     54 
     55  protected function getDefaultOutput($forceColors = false) 
     56  { 
     57    if (in_array('--xml', $GLOBALS['argv'])) 
     58    { 
     59      return new LimeOutputXml(); 
     60    } 
     61    else if (in_array('--array', $GLOBALS['argv'])) 
     62    { 
     63      $serialize = in_array('--serialize', $GLOBALS['argv']); 
     64 
     65      return new LimeOutputArray($serialize); 
     66    } 
     67    else 
     68    { 
     69      $colorizer = LimeColorizer::isSupported() || $forceColors ? new LimeColorizer() : null; 
     70 
     71      return new LimeOutputConsoleDetailed(new LimePrinter($colorizer)); 
     72    } 
     73  } 
     74 
     75  public function getOutput() 
     76  { 
     77    return $this->output; 
    6978  } 
    7079 
     
    129138  } 
    130139 
    131   public function __destruct() 
    132   { 
    133     $plan = $this->results['stats']['plan']; 
    134     $passed = count($this->results['stats']['passed']); 
    135     $failed = count($this->results['stats']['failed']); 
    136     $total = $this->results['stats']['total']; 
    137     is_null($plan) and $plan = $total and $this->output->echoln(sprintf("1..%d", $plan)); 
    138  
    139     if ($total > $plan) 
    140     { 
    141       $this->output->redBar(sprintf(" Looks like you planned %d tests but ran %d extra.", $plan, $total - $plan)); 
    142     } 
    143     elseif ($total < $plan) 
    144     { 
    145       $this->output->redBar(sprintf(" Looks like you planned %d tests but only ran %d.", $plan, $total)); 
    146     } 
    147  
    148     if ($failed) 
    149     { 
    150       $this->output->redBar(sprintf(" Looks like you failed %d tests of %d.", $failed, $passed + $failed)); 
    151     } 
    152     else if ($total == $plan) 
    153     { 
    154       $this->output->greenBar(" Looks like everything went fine."); 
    155     } 
    156  
    157     flush(); 
     140  static protected function findCaller() 
     141  { 
     142    $traces = debug_backtrace(); 
     143 
     144    $t = array_reverse($traces); 
     145    foreach ($t as $trace) 
     146    { 
     147      if (isset($trace['object']) && $trace['object'] instanceof LimeTest && isset($trace['file']) && isset($trace['line'])) 
     148      { 
     149        return array($trace['file'], $trace['line']); 
     150      } 
     151    } 
     152 
     153    // return the first call 
     154    $file = $traces[0]['file']; 
     155    if ($this->options['base_dir']) 
     156    { 
     157      $file = str_replace(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->options['base_dir']), '', str_replace(array('/', '\\'), $file)); 
     158    } 
     159 
     160    return array($file, $traces[0]['line']); 
     161  } 
     162 
     163  protected function test($condition, $message, $error = null) 
     164  { 
     165    list ($file, $line) = $this->findCaller(debug_backtrace()); 
     166 
     167    if ($result = (boolean) $condition) 
     168    { 
     169      $this->output->pass($message, $file, $line); 
     170    } 
     171    else 
     172    { 
     173      $this->output->fail($message, $file, $line, $error); 
     174    } 
     175 
     176    return $result; 
    158177  } 
    159178 
     
    168187  public function ok($exp, $message = '') 
    169188  { 
    170     $this->updateStats(); 
    171  
    172     if ($result = (boolean) $exp) 
    173     { 
    174       $this->results['stats']['passed'][] = $this->nbTests; 
    175     } 
    176     else 
    177     { 
    178       $this->results['stats']['failed'][] = $this->nbTests; 
    179     } 
    180     $this->results['tests'][$this->nbTests]['message'] = $message; 
    181     $this->results['tests'][$this->nbTests]['status'] = $result; 
    182     $this->output->echoln(sprintf("%s %d%s", $result ? 'ok' : 'not ok', $this->nbTests, $message = $message ? sprintf('%s %s', 0 === strpos($message, '#') ? '' : ' -', $message) : '')); 
    183  
    184     if (!$result) 
    185     { 
    186       $this->output->diag(sprintf('    Failed test (%s at line %d)', str_replace(getcwd(), '.', $this->results['tests'][$this->nbTests]['file']), $this->results['tests'][$this->nbTests]['line'])); 
    187     } 
    188  
    189     return $result; 
     189    return $this->test($exp, $message); 
    190190  } 
    191191 
     
    214214    } 
    215215 
    216     if (!$result = $this->ok($value, $message)) 
    217     { 
    218       $this->setLastTestErrors(array(sprintf("           got: %s", var_export($exp1, true)), sprintf("      expected: %s", var_export($exp2, true)))); 
    219     } 
    220  
    221     return $result; 
     216    $error = sprintf("     got: %s\nexpected: %s", var_export($exp1, true), var_export($exp2, true)); 
     217 
     218    return $this->test($value, $message, $error); 
    222219  } 
    223220 
     
    233230  public function isnt($exp1, $exp2, $message = '') 
    234231  { 
    235     if (!$result = $this->ok($exp1 != $exp2, $message)) 
    236     { 
    237       $this->setLastTestErrors(array(sprintf("      %s", var_export($exp2, true)), '          ne', sprintf("      %s", var_export($exp2, true)))); 
    238     } 
    239  
    240     return $result; 
     232    $error = sprintf("%s\n    ne\n%s", var_export($exp2, true), var_export($exp2, true)); 
     233 
     234    return $this->test($exp1 != $exp2, $message, $error); 
    241235  } 
    242236 
     
    252246  public function like($exp, $regex, $message = '') 
    253247  { 
    254     if (!$result = $this->ok(preg_match($regex, $exp), $message)) 
    255     { 
    256       $this->setLastTestErrors(array(sprintf("                    '%s'", $exp), sprintf("      doesn't match '%s'", $regex))); 
    257     } 
    258  
    259     return $result; 
     248    $error = sprintf("              '%s'\ndoesn't match '%s'", $exp, $regex); 
     249 
     250    return $this->test(preg_match($regex, $exp), $message, $error); 
    260251  } 
    261252 
     
    271262  public function unlike($exp, $regex, $message = '') 
    272263  { 
    273     if (!$result = $this->ok(!preg_match($regex, $exp), $message)) 
    274     { 
    275       $this->setLastTestErrors(array(sprintf("               '%s'", $exp), sprintf("      matches '%s'", $regex))); 
    276     } 
    277  
    278     return $result; 
     264    $error = sprintf("              '%s'\nmatches '%s'", $exp, $regex); 
     265 
     266    return $this->test(!preg_match($regex, $exp), $message, $error); 
    279267  } 
    280268 
     
    292280  { 
    293281    eval(sprintf("\$result = \$exp1 $op \$exp2;")); 
    294     if (!$this->ok($result, $message)) 
    295     { 
    296       $this->setLastTestErrors(array(sprintf("      %s", str_replace("\n", '', var_export($exp1, true))), sprintf("          %s", $op), sprintf("      %s", str_replace("\n", '', var_export($exp2, true))))); 
    297     } 
    298  
    299     return $result; 
     282 
     283    $error = sprintf("%s\n    %s\n%s", str_replace("\n", '', var_export($exp1, true)), $op, str_replace("\n", '', var_export($exp2, true))); 
     284 
     285    return $this->test($result, $message, $error); 
    300286  } 
    301287 
     
    322308    } 
    323309 
    324     !$this->ok($result, $message); 
    325  
    326     !$result and $this->setLastTestErrors($failedMessages); 
    327  
    328     return $result; 
     310    return $this->test($result, $message, implode("\n", $failedMessages)); 
    329311  } 
    330312 
     
    341323  { 
    342324    $type = is_object($var) ? get_class($var) : gettype($var); 
    343     if (!$result = $this->ok($type == $class, $message)) 
    344     { 
    345       $this->setLastTestErrors(array(sprintf("      variable isn't a '%s' it's a '%s'", $class, $type))); 
    346     } 
    347  
    348     return $result; 
     325    $error = sprintf("      variable isn't a '%s' it's a '%s'", $class, $type); 
     326 
     327    return $this->test($type == $class, $message, $error); 
    349328  } 
    350329 
     
    360339  public function isDeeply($exp1, $exp2, $message = '') 
    361340  { 
    362     if (!$result = $this->ok($this->testIsDeeply($exp1, $exp2), $message)) 
    363     { 
    364       $this->setLastTestErrors(array(sprintf("           got: %s", str_replace("\n", '', var_export($exp1, true))), sprintf("      expected: %s", str_replace("\n", '', var_export($exp2, true))))); 
    365     } 
    366  
    367     return $result; 
     341    $error = sprintf("     got: %s\nexpected: %s", str_replace("\n", '', var_export($exp1, true)), str_replace("\n", '', var_export($exp2, true))); 
     342 
     343    return $this->test($this->testIsDeeply($exp1, $exp2), $message, $error); 
    368344  } 
    369345 
     
    377353  public function pass($message = '') 
    378354  { 
    379     return $this->ok(true, $message); 
     355    return $this->test(true, $message); 
    380356  } 
    381357 
     
    389365  public function fail($message = '') 
    390366  { 
    391     return $this->ok(false, $message); 
     367    return $this->test(false, $message); 
    392368  } 
    393369 
     
    401377  public function diag($message) 
    402378  { 
    403     $this->output->diag($message); 
     379    $this->output->comment($message); 
    404380  } 
    405381 
     
    416392    for ($i = 0; $i < $nbTests; $i++) 
    417393    { 
    418       $this->pass(sprintf("# SKIP%s", $message ? ' '.$message : '')); 
    419       $this->results['stats']['skipped'][] = $this->nbTests; 
    420       array_pop($this->results['stats']['passed']); 
     394      list ($file, $line) = $this->findCaller(); 
     395 
     396      $this->output->skip($message, $file, $line); 
    421397    } 
    422398  } 
     
    431407  public function todo($message = '') 
    432408  { 
    433     $this->pass(sprintf("# TODO%s", $message ? ' '.$message : '')); 
    434     $this->results['stats']['skipped'][] = $this->nbTests; 
    435     array_pop($this->results['stats']['passed']); 
     409    $this->skip('TODO: '.$message); 
    436410  } 
    437411 
     
    489463  public function expect($exception, $code = null) 
    490464  { 
    491     $this->expectedException  = $exception; 
    492     $this->expectedCode       = $code; 
    493     $this->actualException    = null; 
    494     $this->actualCode         = null; 
     465    $this->expectedExceptionAt  = self::findCaller(); 
     466    $this->expectedException    = $exception; 
     467    $this->expectedCode         = $code; 
     468    $this->actualException      = null; 
     469    $this->actualCode           = null; 
    495470  } 
    496471 
     
    519494      if (is_null($this->expectedCode)) 
    520495      { 
    521         $this->is($this->actualException, $this->expectedException, sprintf('A "%s" was thrown', $this->expectedException)); 
     496        $actual = $this->actualException; 
     497        $expected = $this->expectedException; 
     498        $message = sprintf('A "%s" was thrown', $this->expectedException); 
    522499      } 
    523500      else 
     
    525502        $actual = sprintf('%s (%s)', $this->actualException, var_export($this->actualCode, true)); 
    526503        $expected = sprintf('%s (%s)', $this->expectedException, var_export($this->expectedCode, true)); 
    527  
    528         $this->is($actual, $expected, sprintf('A "%s" with code "%s" was thrown', $this->expectedException, $this->expectedCode)); 
     504        $message = sprintf('A "%s" with code "%s" was thrown', $this->expectedException, $this->expectedCode); 
     505      } 
     506 
     507      list ($file, $line) = $this->expectedExceptionAt; 
     508 
     509      if ($actual == $expected) 
     510      { 
     511        $this->output->pass($message, $file, $line); 
     512      } 
     513      else 
     514      { 
     515        $error = sprintf("     got: %s\nexpected: %s", is_null($this->actualException) ? 'none' : $actual, $expected); 
     516        $this->output->fail($message, $file, $line, $error); 
    529517      } 
    530518    } 
     
    532520    $this->expectedException = null; 
    533521  } 
    534  
    535   protected function updateStats() 
    536   { 
    537     ++$this->nbTests; 
    538     ++$this->results['stats']['total']; 
    539  
    540     list($this->results['tests'][$this->nbTests]['file'], $this->results['tests'][$this->nbTests]['line']) = $this->findCaller(debug_backtrace()); 
    541   } 
    542  
    543   protected function setLastTestErrors(array $errors) 
    544   { 
    545     $this->output->diag($errors); 
    546  
    547     $this->results['tests'][$this->nbTests]['error'] = implode("\n", $errors); 
    548   } 
    549  
    550   protected function findCaller(array $traces) 
    551   { 
    552     $t = array_reverse($traces); 
    553     foreach ($t as $trace) 
    554     { 
    555       if (isset($trace['object']) && $trace['object'] instanceof LimeTest && isset($trace['file']) && isset($trace['line'])) 
    556       { 
    557         return array($trace['file'], $trace['line']); 
    558       } 
    559     } 
    560  
    561     // return the first call 
    562     $last = count($traces) - 1; 
    563     $file = $traces[$last]['file']; 
    564     if ($this->options['base_dir']) 
    565     { 
    566       $file = str_replace(str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $this->options['base_dir']), '', str_replace(array('/', '\\'), $file)); 
    567     } 
    568     return array($file, $traces[$last]['line']); 
    569   } 
    570522} 
  • tools/lime/branches/2.0-experimental/lib/expectation/LimeExpectationCollection.php

    r20113 r20332  
    7373   * @var LimeTest 
    7474   */ 
    75   protected $test = null; 
     75  protected $output = null; 
    7676 
    7777  /** 
     
    102102  protected $strict = false; 
    103103 
    104   public function __construct(LimeTest $test = null) 
    105   { 
    106     $this->test = $test; 
     104  public function __construct(LimeOutputInterface $output = null) 
     105  { 
     106    $this->output = $output; 
     107  } 
     108 
     109  static protected function findCaller() 
     110  { 
     111    $traces = debug_backtrace(); 
     112 
     113    $t = array_reverse($traces); 
     114    foreach ($t as $trace) 
     115    { 
     116      if (isset($trace['object']) && $trace['object'] instanceof LimeExpectationCollection && isset($trace['file']) && isset($trace['line'])) 
     117      { 
     118        return array($trace['file'], $trace['line']); 
     119      } 
     120    } 
     121 
     122    return array($traces[0]['file'], $traces[0]['line']); 
    107123  } 
    108124 
     
    131147  public function verify() 
    132148  { 
    133     if (is_null($this->test)) 
     149    if (is_null($this->output)) 
    134150    { 
    135151      throw new BadMethodCallException("A LimeTest object is required for verification"); 
    136152    } 
    137153 
     154    list ($file, $line) = self::findCaller(); 
     155 
    138156    if (count($this->expected) == 0) 
    139157    { 
    140       $this->test->pass('No values have been expected'); 
    141     } 
    142     else if ($this->strict
    143     { 
    144       $this->test->ok($this->actual === $this->expected, 'The expected values have been set'); 
     158      $this->output->pass('No values have been expected', $file, $line); 
     159    } 
     160    else if ($this->strict ? ($this->actual === $this->expected) : ($this->actual == $this->expected)
     161    { 
     162      $this->output->pass('The expected values have been set', $file, $line); 
    145163    } 
    146164    else 
    147165    { 
    148       $this->test->ok($this->actual == $this->expected, 'The expected values have been set'); 
     166      $this->output->fail('The expected values have been set', $file, $line); 
    149167    } 
    150168  } 
  • tools/lime/branches/2.0-experimental/lib/lexer/LimeLexerAnnotations.php

    r20311 r20332  
    6767    $functionCount, 
    6868    $initialized, 
    69     $testVariable; 
     69    $testVariable, 
     70    $classBuffer, 
     71    $classImplementsInterface; 
    7072 
    7173  /** 
     
    105107    $this->functionCount = 0; 
    106108    $this->functions = array(); 
     109    $this->classBuffer = ''; 
     110    $this->classImplementsInterface = false; 
    107111 
    108112    foreach ($this->allowedAnnotations as $annotation) 
     
    145149  protected function process($text, $id) 
    146150  { 
     151    if (!$this->inClass()) 
     152    { 
     153      $this->classBuffer = ''; 
     154      $this->classImplementsInterface = false; 
     155    } 
     156 
     157    // classes implementing any interfaces seem not to be recognized by PHP if 
     158    // they are placed after the exit() statement, so we need to leave them in 
     159    // the source code 
     160    // this functionality is covered in LimeAnnotationSupportTest 11+12 
     161    if ($this->inClassDeclaration()) 
     162    { 
     163      if ($id == T_IMPLEMENTS) 
     164      { 
     165        $this->classImplementsInterface = true; 
     166        $text = $this->classBuffer.$text; 
     167        $this->classBuffer = ''; 
     168      } 
     169      else 
     170      { 
     171        $this->classBuffer .= $text; 
     172      } 
     173    } 
     174 
    147175    if ($id == T_OPEN_TAG && !$this->initialized) 
    148176    { 
     
    152180      } 
    153181      $this->initialized = true; 
     182    } 
     183    else if ($this->inClass() && $this->classImplementsInterface) 
     184    { 
     185      // just print 
    154186    } 
    155187    else if ($this->inClass() || $this->inFunction()) 
  • tools/lime/branches/2.0-experimental/lib/mock/LimeMock.php

    r20313 r20332  
    173173   * @return LimeMockInterface           The mock object 
    174174   */ 
    175   public static function create($classOrInterface, LimeTest $test = null, $generateMethods = true) 
     175  public static function create($classOrInterface, $test = null, $generateMethods = true) 
    176176  { 
    177177    $name = self::generateClass($classOrInterface, $generateMethods); 
    178  
    179     return new $name($classOrInterface, new LimeMockUnorderedBehaviour(), $test); 
    180   } 
    181  
    182   public static function createStrict($classOrInterface, LimeTest $test = null, $generateMethods = true) 
     178    $output = $test instanceof LimeOutputInterface ? $test : ($test ? $test->getOutput() : null); 
     179 
     180    return new $name($classOrInterface, new LimeMockUnorderedBehaviour(), $output); 
     181  } 
     182 
     183  public static function createStrict($classOrInterface, $test = null, $generateMethods = true) 
    183184  { 
    184185    $name = self::generateClass($classOrInterface, $generateMethods); 
    185  
    186     return new $name($classOrInterface, new LimeMockOrderedBehaviour(), $test); 
     186    $output = $test instanceof LimeOutputInterface ? $test : ($test ? $test->getOutput() : null); 
     187 
     188    return new $name($classOrInterface, new LimeMockOrderedBehaviour(), $output); 
    187189  } 
    188190 
  • tools/lime/branches/2.0-experimental/lib/mock/LimeMockExpectedInvocation.php

    r20294 r20332  
    2525    $strict       = false; 
    2626 
    27   public function __construct(LimeMockInvocation $invocation, LimeTest $output = null) 
     27  public function __construct(LimeMockInvocation $invocation, LimeOutputInterface $output = null) 
    2828  { 
    2929    $this->invocation = $invocation; 
     
    3333 
    3434    $this->atLeastOnce(); 
     35  } 
     36 
     37  static protected function findCaller() 
     38  { 
     39    $traces = debug_backtrace(); 
     40 
     41    $t = array_reverse($traces); 
     42    foreach ($t as $trace) 
     43    { 
     44      if (isset($trace['object']) && $trace['object'] instanceof LimeMockInterface && isset($trace['file']) && isset($trace['line'])) 
     45      { 
     46        return array($trace['file'], $trace['line']); 
     47      } 
     48    } 
     49 
     50    return array($traces[0]['file'], $traces[0]['line']); 
    3551  } 
    3652 
     
    90106    } 
    91107 
    92     $this->output->ok($valid, implode(' ', $messages)); 
     108    list ($file, $line) = self::findCaller(); 
     109    $message = implode(' ', $messages); 
     110 
     111    if ($valid) 
     112    { 
     113      $this->output->pass($message, $file, $line); 
     114    } 
     115    else 
     116    { 
     117      $this->output->fail($message, $file, $line); 
     118    } 
    93119  } 
    94120 
  • tools/lime/branches/2.0-experimental/lib/mock/LimeMockRecordState.php

    r20307 r20332  
    1414  protected 
    1515    $behaviour = null, 
    16     $test = null; 
     16    $output = null; 
    1717 
    18   public function __construct(LimeMockBehaviourInterface $behaviour, LimeTest $test = null) 
     18  public function __construct(LimeMockBehaviourInterface $behaviour, LimeOutputInterface $output = null) 
    1919  { 
    2020    $this->behaviour = $behaviour; 
    21     $this->test = $test; 
     21    $this->output = $output; 
    2222  } 
    2323 
     
    2525  { 
    2626    $invocation = new LimeMockInvocation($class, $method, $parameters); 
    27     $invocation = new LimeMockExpectedInvocation($invocation, $this->test); 
     27    $invocation = new LimeMockExpectedInvocation($invocation, $this->output); 
    2828 
    2929    $this->behaviour->expect($invocation); 
  • tools/lime/branches/2.0-experimental/lib/mock/template/mocked_class.tpl

    r20307 r20332  
    66    $behaviour = null; 
    77   
    8   public function __construct($class, LimeMockBehaviourInterface $behaviour, LimeTest $test = null) 
     8  public function __construct($class, LimeMockBehaviourInterface $behaviour, LimeOutputInterface $output = null) 
    99  { 
    1010    $this->class = $class; 
    1111    $this->behaviour = $behaviour; 
    12     $this->state = new LimeMockRecordState($this->behaviour, $test); 
     12    $this->state = new LimeMockRecordState($this->behaviour, $output); 
    1313  } 
    1414   
     
    3030  <?php if ($generate_methods): ?> 
    3131  public function replay() { return $this->__lime_replay(); } 
     32  public function invoke($method, array $parameters = array()) { return $this->__call($method, $parameters); } 
    3233  public function reset() { return $this->state->reset(); } 
    3334  public function verify() { return $this->state->verify(); } 
  • tools/lime/branches/2.0-experimental/test/unit/LimeAnnotationSupport/test_class_before_annotations.php

    r20117 r20332  
    3131abstract class TestAbstractClassDefinition {} 
    3232 
    33 class TestExtendingClassDefinition extends TestClassDefinition implements TestInterfaceDefinition {} 
     33class TestExtendingClassDefinition extends TestClassDefinition {} 
     34 
     35class TestExtendingAbstractClassDefinition extends TestAbstractClassDefinition {} 
    3436 
    3537class TestImplementingClassDefinition implements TestInterfaceDefinition {} 
     38 
     39class TestExtendingAndImplementingClassDefinition extends TestClassDefinition implements TestInterfaceDefinition {} 
    3640 
    3741$t = new LimeTest(0); 
     
    5458  echo "If is not matched\n"; 
    5559} 
     60 
     61// @Test 
     62// instantiate all classes to see whether they are known to PHP 
     63$class = new TestClassDefinition(); 
     64$class = new TestClassDefinitionInOneLine(); 
     65$class = new TestExtendingClassDefinition(); 
     66$class = new TestExtendingAbstractClassDefinition(); 
     67$class = new TestImplementingClassDefinition(); 
     68$class = new TestExtendingAndImplementingClassDefinition(); 
  • tools/lime/branches/2.0-experimental/test/unit/LimeAnnotationSupportTest.php

    r20311 r20332  
    2422421..4 
    243243Test 1 
    244 not ok 1 - A RuntimeException was thrown 
     244not ok 1 - A "RuntimeException" was thrown 
    245245#     Failed test (%ANY%) 
    246 #            got: NULL 
    247 #       expected: 'RuntimeException' 
    248 Test 2 
    249 ok 2 - A RuntimeException was thrown 
     246#            got: none 
     247#       expected: RuntimeException 
     248Test 2 
     249ok 2 - A "RuntimeException" was thrown 
    250250Test 3 
    251 not ok 3 - A RuntimeException with code 1 was thrown 
     251not ok 3 - A "RuntimeException" with code "1" was thrown 
    252252#     Failed test (%ANY%) 
    253 #            got: 'RuntimeException (0)' 
    254 #       expected: 'RuntimeException (1)' 
     253#            got: RuntimeException (0) 
     254#       expected: RuntimeException (1) 
    255255Test 4 
    256 ok 4 - A RuntimeException with code 1 was thrown 
     256ok 4 - A "RuntimeException" with code "1" was thrown 
    257257 Looks like you failed 2 tests of 4. 
    258258EOF 
     
    2702701..2 
    271271Test 1 
    272 ok 1 - A RuntimeException was thrown 
    273 Test 2 
    274 not ok 2 - A LogicException was thrown 
     272ok 1 - A "RuntimeException" was thrown 
     273Test 2 
     274not ok 2 - A "LogicException" was thrown 
    275275#     Failed test (%ANY%) 
    276 #            got: NULL 
    277 #       expected: 'LogicException' 
     276#            got: none 
     277#       expected: LogicException 
    278278 Looks like you failed 1 tests of 2. 
    279279EOF 
  • tools/lime/branches/2.0-experimental/test/unit/LimeTestCaseTest.php

    r20113 r20332  
    5151  // fixtures 
    5252  $test = new TestCase(); 
    53   $test->methodCalls = new LimeExpectationList($t); 
     53  $test->methodCalls = new LimeExpectationList($t->getOutput()); 
    5454  $test->methodCalls->addExpected('setUp'); 
    5555  $test->methodCalls->addExpected('testDoSomething'); 
  • tools/lime/branches/2.0-experimental/test/unit/LimeTestRunnerTest.php

    r20330 r20332  
    5353 
    5454 
    55 $t = new LimeTest(7); 
     55$t = new LimeTest(20); 
    5656 
    5757 
     
    5959 
    6060  // fixtures 
    61   $test = new TestCase($t); 
    62   $r = new LimeTestRunner(); 
    63   $r->addBefore(array($test, 'setUp')); 
    64   $r->addTest(array($test, 'testDoSomething')); 
    65   $r->addTest(array($test, 'testDoSomethingElse')); 
    66   $test->methodCalls->addExpected('setUp'); 
    67   $test->methodCalls->addExpected('testDoSomething'); 
    68   $test->methodCalls->addExpected('setUp'); 
    69   $test->methodCalls->addExpected('testDoSomethingElse'); 
    70   // test 
    71   $r->run(); 
    72   // assertions 
    73   $test->methodCalls->verify(); 
     61  $mock = LimeMock::createStrict('Mock', $t); 
     62  $r = new LimeTestRunner(); 
     63  $r->addBefore(array($mock, 'setUp')); 
     64  $r->addTest(array($mock, 'testDoSomething')); 
     65  $r->addTest(array($mock, 'testDoSomethingElse')); 
     66  $mock->setUp(); 
     67  $mock->testDoSomething(); 
     68  $mock->setUp(); 
     69  $mock->testDoSomethingElse(); 
     70  $mock->replay(); 
     71  // test 
     72  $r->run(); 
     73  // assertions 
     74  $mock->verify(); 
    7475 
    7576 
     
    7778 
    7879  // fixtures 
    79   $test = new TestCase($t); 
    80   $r = new LimeTestRunner(); 
    81   $r->addAfter(array($test, 'tearDown')); 
    82   $r->addTest(array($test, 'testDoSomething')); 
    83   $r->addTest(array($test, 'testDoSomethingElse')); 
    84   $test->methodCalls->addExpected('testDoSomething'); 
    85   $test->methodCalls->addExpected('tearDown'); 
    86   $test->methodCalls->addExpected('testDoSomethingElse'); 
    87   $test->methodCalls->addExpected('tearDown'); 
    88   // test 
    89   $r->run(); 
    90   // assertions 
    91   $test->methodCalls->verify(); 
     80  $mock = LimeMock::createStrict('Mock', $t); 
     81  $r = new LimeTestRunner(); 
     82  $r->addAfter(array($mock, 'tearDown')); 
     83  $r->addTest(array($mock, 'testDoSomething')); 
     84  $r->addTest(array($mock, 'testDoSomethingElse')); 
     85  $mock->testDoSomething(); 
     86  $mock->tearDown(); 
     87  $mock->testDoSomethingElse(); 
     88  $mock->tearDown(); 
     89  $mock->replay(); 
     90  // test 
     91  $r->run(); 
     92  // assertions 
     93  $mock->verify(); 
    9294 
    9395 
     
    9597 
    9698  // fixtures 
    97   $test = new TestCase($t); 
    98   $r = new LimeTestRunner(); 
    99   $r->addBeforeAll(array($test, 'setUp')); 
    100   $r->addTest(array($test, 'testDoSomething')); 
    101   $r->addTest(array($test, 'testDoSomethingElse')); 
    102   $test->methodCalls->addExpected('setUp'); 
    103   $test->methodCalls->addExpected('testDoSomething'); 
    104   $test->methodCalls->addExpected('testDoSomethingElse'); 
    105   // test 
    106   $r->run(); 
    107   // assertions 
    108   $test->methodCalls->verify(); 
     99  $mock = LimeMock::createStrict('Mock', $t); 
     100  $r = new LimeTestRunner(); 
     101  $r->addBeforeAll(array($mock, 'setUp')); 
     102  $r->addTest(array($mock, 'testDoSomething')); 
     103  $r->addTest(array($mock, 'testDoSomethingElse')); 
     104  $mock->setUp(); 
     105  $mock->testDoSomething(); 
     106  $mock->testDoSomethingElse(); 
     107  $mock->replay(); 
     108  // test 
     109  $r->run(); 
     110  // assertions 
     111  $mock->verify(); 
    109112 
    110113 
     
    112115 
    113116  // fixtures 
    114   $test = new TestCase($t); 
    115   $r = new LimeTestRunner(); 
    116   $r->addAfterAll(array($test, 'tearDown')); 
    117   $r->addTest(array($test, 'testDoSomething')); 
    118   $r->addTest(array($test, 'testDoSomethingElse')); 
    119   $test->methodCalls->addExpected('testDoSomething'); 
    120   $test->methodCalls->addExpected('testDoSomethingElse'); 
    121   $test->methodCalls->addExpected('tearDown'); 
    122   // test 
    123   $r->run(); 
    124   // assertions 
    125   $test->methodCalls->verify(); 
     117  $mock = LimeMock::createStrict('Mock', $t); 
     118  $r = new LimeTestRunner(); 
     119  $r->addAfterAll(array($mock, 'tearDown')); 
     120  $r->addTest(array($mock, 'testDoSomething')); 
     121  $r->addTest(array($mock, 'testDoSomethingElse')); 
     122  $mock->testDoSomething(); 
     123  $mock->testDoSomethingElse(); 
     124  $mock->tearDown(); 
     125  $mock->replay(); 
     126  // test 
     127  $r->run(); 
     128  // assertions 
     129  $mock->verify(); 
    126130 
    127131 
     
    129133 
    130134  // fixtures 
    131   $test = new TestCase($t); 
    132   $r = new LimeTestRunner(); 
    133   $r->addTest(array($test, 'testThrowsError')); 
    134   $r->addErrorHandler(array($test, 'handleErrorFailed')); 
    135   $r->addErrorHandler(array($test, 'handleErrorSuccessful')); 
    136   $test->methodCalls->addExpected('handleErrorFailed'); 
    137   $test->methodCalls->addExpected('handleErrorSuccessful'); 
    138   // test 
    139   $r->run(); 
    140   // assertions 
    141   $test->methodCalls->verify(); 
     135  function throwError() { 1/0; } 
     136  $mock = LimeMock::createStrict('Mock', $t); 
     137  $r = new LimeTestRunner(); 
     138  $r->addTest('throwError'); 
     139  $r->addErrorHandler(array($mock, 'handleErrorFailed')); 
     140  $r->addErrorHandler(array($mock, 'handleErrorSuccessful')); 
     141  $mock->handleErrorFailed()->anyParameters()->returns(false); 
     142  $mock->handleErrorSuccessful()->anyParameters()->returns(true); 
     143  $mock->replay(); 
     144  // test 
     145  $r->run(); 
     146  // assertions 
     147  $mock->verify(); 
    142148 
    143149 
     
    166172 
    167173  // fixtures 
    168   $test = new TestCase($t); 
    169   $r = new LimeTestRunner(); 
    170   $r->addTest(array($test, 'testThrowsException')); 
    171   $r->addExceptionHandler(array($test, 'handleErrorFailed')); 
    172   $r->addExceptionHandler(array($test, 'handleErrorSuccessful')); 
    173   $test->methodCalls->addExpected('handleErrorFailed'); 
    174   $test->methodCalls->addExpected('handleErrorSuccessful'); 
    175   // test 
    176   $r->run(); 
    177   // assertions 
    178   $test->methodCalls->verify(); 
     174  $mock = LimeMock::createStrict('Mock', $t); 
     175  $r = new LimeTestRunner(); 
     176  $r->addTest(array($mock, 'testThrowsException')); 
     177  $r->addExceptionHandler(array($mock, 'handleErrorFailed')); 
     178  $r->addExceptionHandler(array($mock, 'handleErrorSuccessful')); 
     179  $mock->testThrowsException()->throws('Exception'); 
     180  $mock->handleErrorFailed()->anyParameters()->returns(false); 
     181  $mock->handleErrorSuccessful()->anyParameters()->returns(true); 
     182  $mock->replay(); 
     183  // test 
     184  $r->run(); 
     185  // assertions 
     186  $mock->verify(); 
    179187 
    180188 
     
    182190 
    183191  // fixtures 
    184   $test = new TestCase($t); 
    185   $r = new LimeTestRunner(); 
    186   $r->addTest(array($test, 'testThrowsException')); 
    187   $r->addExceptionHandler(array($test, 'handleErrorFailed')); 
    188   // test 
     192  $mock = LimeMock::createStrict('Mock', $t); 
     193  $r = new LimeTestRunner(); 
     194  $r->addTest(array($mock, 'testThrowsException')); 
     195  $r->addExceptionHandler(array($mock, 'handleErrorFailed')); 
     196  $mock->testThrowsException()->throws('Exception'); 
     197  $mock->handleErrorFailed()->anyParameters()->returns(false); 
     198  $mock->replay(); 
     199  // test 
     200  $t->expect('Exception'); 
    189201  try 
    190202  { 
  • tools/lime/branches/2.0-experimental/test/unit/expectation/LimeExpectationBagTest.php

    r20118 r20332  
    1111 
    1212include dirname(__FILE__).'/../../bootstrap/unit.php'; 
    13 require_once dirname(__FILE__).'/../../MockLimeTest.php'; 
    1413 
     14LimeAnnotationSupport::enable(); 
    1515 
    1616$t = new LimeTest(6); 
    1717 
    1818 
    19 $t->diag('Expected values can be added in any order'); 
     19// @Before 
     20 
     21  $mock = LimeMock::create('LimeOutputInterface', $t); 
     22  $b = new LimeExpectationBag($mock); 
     23 
     24 
     25// @After 
     26 
     27  $mock = null; 
     28  $b = null; 
     29 
     30 
     31// @Test: Expected values can be added in any order 
    2032 
    2133  // fixtures 
    22   $mock = new MockLimeTest(); 
    23   $b = new LimeExpectationBag($mock); 
     34  $mock->invoke('pass')->once()->anyParameters(); 
     35  $mock->invoke('fail')->never(); 
     36  $mock->replay(); 
    2437  // test 
    2538  $b->addExpected(1); 
     
    3144  $b->verify(); 
    3245  // assertions 
    33   $t->is($mock->passes, 1, 'One test passed'); 
    34   $t->is($mock->fails, 0, 'No test failed'); 
     46  $mock->verify(); 
    3547 
    3648 
    37 $t->diag('Exceptions are thrown if unexpected values are added'); 
     49// @Test: Exceptions are thrown if unexpected values are added 
     50 
     51  // test 
     52  $b->addExpected(1); 
     53  $t->expect('LimeAssertionException'); 
     54  $b->addActual(2); 
     55 
     56 
     57// @Test: Exceptions are thrown if expected values are added too often 
     58 
     59  // test 
     60  $b->addExpected(1); 
     61  $b->addActual(1); 
     62  $t->expect('LimeAssertionException'); 
     63  $b->addActual(1); 
     64 
     65 
     66// @Test: setFailOnVerify() suppresses exceptions 
    3867 
    3968  // fixtures 
    40   $mock = new MockLimeTest(); 
    41   $b = new LimeExpectationBag($mock); 
    42   $b->addExpected(1); 
    43   // test 
    44   try 
    45   { 
    46     $b->addActual(2); 
    47     $t->fail('A "LimeAssertionException" is thrown'); 
    48   } 
    49   catch (LimeAssertionException $e) 
    50   { 
    51     $t->pass('A "LimeAssertionException" is thrown'); 
    52   } 
    53  
    54  
    55 $t->diag('Exceptions are thrown if expected values are added too often'); 
    56  
    57   // fixtures 
    58   $mock = new MockLimeTest(); 
    59   $b = new LimeExpectationBag($mock); 
    60   $b->addExpected(1); 
    61   $b->addActual(1); 
    62   // test 
    63   try 
    64   { 
    65     $b->addActual(1); 
    66     $t->fail('A "LimeAssertionException" is thrown'); 
    67   } 
    68   catch (LimeAssertionException $e) 
    69   { 
    70     $t->pass('A "LimeAssertionException" is thrown'); 
    71   } 
    72  
    73  
    74 $t->diag('setFailOnVerify() suppresses exceptions'); 
    75  
    76   // fixtures 
    77   $mock = new MockLimeTest(); 
    78   $b = new LimeExpectationBag($mock); 
     69  $mock->invoke('pass')->never(); 
     70  $mock->invoke('fail')->once()->anyParameters(); 
     71  $mock->replay(); 
    7972  // test 
    8073  $b->setFailOnVerify(); 
     
    8477  $b->verify(); 
    8578  // assertions 
    86   $t->is($mock->passes, 0, 'No test passed'); 
    87   $t->is($mock->fails, 1, 'One test failed'); 
     79  $mock->verify(); 
    8880 
  • tools/lime/branches/2.0-experimental/test/unit/expectation/LimeExpectationCollectionTest.php

    r20118 r20332  
    1111 
    1212include dirname(__FILE__).'/../../bootstrap/unit.php'; 
    13 require_once dirname(__FILE__).'/../../MockLimeTest.php'; 
     13 
     14LimeAnnotationSupport::enable(); 
    1415 
    1516 
     
    2728  protected function isExpected($value) 
    2829  { 
    29     return $this->isExpected;; 
     30    return $this->isExpected; 
    3031  } 
    3132} 
     
    3536 
    3637 
    37 $t->diag('No value expected, no value retrieved'); 
    38  
    39   // fixtures 
    40   $mock = new MockLimeTest(); 
    41   $l = new TestExpectationCollection($mock); 
    42   // test 
    43   $l->verify(); 
    44   // assertions 
    45   $t->is($mock->passes, 1, 'One test passed'); 
    46   $t->is($mock->fails, 0, 'No test failed'); 
    47  
    48  
    49 $t->diag('One value expected, no value retrieved'); 
    50  
    51   // fixtures 
    52   $mock = new MockLimeTest(); 
    53   $l = new TestExpectationCollection($mock); 
    54   // test 
    55   $l->addExpected(1); 
    56   $l->verify(); 
    57   // assertions 
    58   $t->is($mock->passes, 0, 'No test passed'); 
    59   $t->is($mock->fails, 1, 'One test failed'); 
    60  
    61  
    62 $t->diag('One value expected, one different value retrieved'); 
    63  
    64   // fixtures 
    65   $mock = new MockLimeTest(); 
    66   $l = new TestExpectationCollection($mock); 
     38// @Before 
     39 
     40  $output = LimeMock::create('LimeOutputInterface', $t); 
     41  $l = new TestExpectationCollection($output); 
     42 
     43 
     44// @After 
     45 
     46  $output = null; 
     47  $l = null; 
     48 
     49 
     50// @Test: No value expected, no value retrieved 
     51 
     52  // test 
     53  $output->invoke('pass')->once()->anyParameters(); 
     54  $output->invoke('fail')->never(); 
     55  $l->verify(); 
     56  // assertions 
     57  $output->verify(); 
     58 
     59 
     60// @Test: One value expected, no value retrieved 
     61 
     62  // fixtures 
     63  $output = new MockLimeTest(); 
     64  $l = new TestExpectationCollection($output); 
     65  // test 
     66  $l->addExpected(1); 
     67  $l->verify(); 
     68  // assertions 
     69  $t->is($output->passes, 0, 'No test passed'); 
     70  $t->is($output->fails, 1, 'One test failed'); 
     71 
     72 
     73// @Test: One value expected, one different value retrieved 
     74 
     75  // fixtures 
     76  $output = new MockLimeTest(); 
     77  $l = new TestExpectationCollection($output); 
    6778  // test 
    6879  $l->addExpected(1); 
     
    7081  $l->verify(); 
    7182  // assertions 
    72   $t->is($mock->passes, 0, 'No test passed'); 
    73   $t->is($mock->fails, 1, 'One test failed'); 
    74  
    75  
    76 $t->diag('No expectations are set, added values are ignored'); 
    77  
    78   // fixtures 
    79   $mock = new MockLimeTest(); 
    80   $l = new TestExpectationCollection($mock); 
    81   // test 
    82   $l->addActual(1); 
    83   $l->verify(); 
    84   // assertions 
    85   $t->is($mock->passes, 1, 'One test passed'); 
    86   $t->is($mock->fails, 0, 'No test failed'); 
    87  
    88  
    89 $t->diag('An exception is thrown if an unexpected value is added'); 
    90  
    91   // fixtures 
    92   $mock = new MockLimeTest(); 
    93   $l = new TestExpectationCollection($mock, false); 
     83  $t->is($output->passes, 0, 'No test passed'); 
     84  $t->is($output->fails, 1, 'One test failed'); 
     85 
     86 
     87// @Test: No expectations are set, added values are ignored 
     88 
     89  // fixtures 
     90  $output = new MockLimeTest(); 
     91  $l = new TestExpectationCollection($output); 
     92  // test 
     93  $l->addActual(1); 
     94  $l->verify(); 
     95  // assertions 
     96  $t->is($output->passes, 1, 'One test passed'); 
     97  $t->is($output->fails, 0, 'No test failed'); 
     98 
     99 
     100// @Test: An exception is thrown if an unexpected value is added 
     101 
     102  // fixtures 
     103  $output = new MockLimeTest(); 
     104  $l = new TestExpectationCollection($output, false); 
    94105  $l->addExpected('Foo'); 
    95106  // test 
     
    105116 
    106117 
    107 $t->diag('Exactly no values are expected'); 
    108  
    109   // fixtures 
    110   $mock = new MockLimeTest(); 
    111   $l = new TestExpectationCollection($mock, false); 
     118// @Test: Exactly no values are expected 
     119 
     120  // fixtures 
     121  $output = new MockLimeTest(); 
     122  $l = new TestExpectationCollection($output, false); 
    112123  $l->setExpectNothing(); 
    113124  // test 
     
    123134 
    124135 
    125 $t->diag('The expected value was added'); 
    126  
    127   // fixtures 
    128   $mock = new MockLimeTest(); 
    129   $l = new TestExpectationCollection($mock); 
    130   // test 
    131   $l->addExpected(1); 
    132   $l->addActual(1); 
    133   $l->verify(); 
    134   // assertions 
    135   $t->is($mock->passes, 1, 'One test passed'); 
    136   $t->is($mock->fails, 0, 'No test failed'); 
    137  
    138  
    139 $t->diag('The list can contain a mix of different types'); 
    140  
    141   // fixtures 
    142   $mock = new MockLimeTest(); 
    143   $l = new TestExpectationCollection($mock); 
     136// @Test: The expected value was added 
     137 
     138  // fixtures 
     139  $output = new MockLimeTest(); 
     140  $l = new TestExpectationCollection($output); 
     141  // test 
     142  $l->addExpected(1); 
     143  $l->addActual(1); 
     144  $l->verify(); 
     145  // assertions 
     146  $t->is($output->passes, 1, 'One test passed'); 
     147  $t->is($output->fails, 0, 'No test failed'); 
     148 
     149 
     150// @Test: The list can contain a mix of different types 
     151 
     152  // fixtures 
     153  $output = new MockLimeTest(); 
     154  $l = new TestExpectationCollection($output); 
    144155  // test 
    145156  $l->addExpected(1); 
     
    151162  $l->verify(); 
    152163  // assertions 
    153   $t->is($mock->passes, 1, 'One test passed'); 
    154   $t->is($mock->fails, 0, 'No test failed'); 
    155  
    156  
    157 $t->diag('By default, values are compared with weak typing'); 
    158  
    159   // fixtures 
    160   $mock = new MockLimeTest(); 
    161   $l = new TestExpectationCollection($mock); 
     164  $t->is($output->passes, 1, 'One test passed'); 
     165  $t->is($output->fails, 0, 'No test failed'); 
     166 
     167 
     168// @Test: By default, values are compared with weak typing 
     169 
     170  // fixtures 
     171  $output = new MockLimeTest(); 
     172  $l = new TestExpectationCollection($output); 
    162173  // test 
    163174  $l->addExpected(1); 
     
    165176  $l->verify(); 
    166177  // assertions 
    167   $t->is($mock->passes, 1, 'One test passed'); 
    168   $t->is($mock->fails, 0, 'No test failed'); 
    169  
    170  
    171 $t->diag('If you call setStrict(), values are compared with strict typing - different types'); 
    172  
    173   // fixtures 
    174   $mock = new MockLimeTest(); 
    175   $l = new TestExpectationCollection($mock); 
     178  $t->is($output->passes, 1, 'One test passed'); 
     179  $t->is($output->fails, 0, 'No test failed'); 
     180 
     181 
     182// @Test: If you call setStrict(), values are compared with strict typing - different types 
     183 
     184  // fixtures 
     185  $output = new MockLimeTest(); 
     186  $l = new TestExpectationCollection($output); 
    176187  // test 
    177188  $l->setStrict(); 
     
    180191  $l->verify(); 
    181192  // assertions 
    182   $t->is($mock->passes, 0, 'No test passed'); 
    183   $t->is($mock->fails, 1, 'One test failed'); 
    184  
    185  
    186 $t->diag('If you call setStrict(), values are compared with strict typing - same types'); 
    187  
    188   // fixtures 
    189   $mock = new MockLimeTest(); 
    190   $l = new TestExpectationCollection($mock); 
     193  $t->is($output->passes, 0, 'No test passed'); 
     194  $t->is($output->fails, 1, 'One test failed'); 
     195 
     196 
     197// @Test: If you call setStrict(), values are compared with strict typing - same types 
     198 
     199  // fixtures 
     200  $output = new MockLimeTest(); 
     201  $l = new TestExpectationCollection($output); 
    191202  // test 
    192203  $l->setStrict(); 
     
    195206  $l->verify(); 
    196207  // assertions 
    197   $t->is($mock->passes, 1, 'One test passed'); 
    198   $t->is($mock->fails, 0, 'No test failed'); 
    199  
    200  
    201 $t->diag('Calling verify() results in an exception if no test is set'); 
     208  $t->is($output->passes, 1, 'One test passed'); 
     209  $t->is($output->fails, 0, 'No test failed'); 
     210 
     211 
     212// @Test: Calling verify() results in an exception if no test is set 
    202213 
    203214  // fixtures 
  • tools/lime/branches/2.0-experimental/test/unit/expectation/LimeExpectationListTest.php

    r20118 r20332  
    1717 
    1818 
    19 $t->diag('Exceptions are thrown if unexpected values are added'); 
     19// @Test: Exceptions are thrown if unexpected values are added 
    2020 
    2121  // fixtures 
     
    3636 
    3737 
    38 $t->diag('Exceptions are thrown if expected values are added too often'); 
     38// @Test: Exceptions are thrown if expected values are added too often 
    3939 
    4040  // fixtures 
     
    5555 
    5656 
    57 $t->diag('setFailOnVerify() suppresses exceptions'); 
     57// @Test: setFailOnVerify() suppresses exceptions 
    5858 
    5959  // fixtures 
  • tools/lime/branches/2.0-experimental/test/unit/expectation/LimeExpectationSetTest.php

    r20118 r20332  
    1717 
    1818 
    19 $t->diag('Expected values can be added in any order'); 
     19// @Test: Expected values can be added in any order 
    2020 
    2121  // fixtures 
     
    3535 
    3636 
    37 $t->diag('Expected values can be added any number of times'); 
     37// @Test: Expected values can be added any number of times 
    3838 
    3939  // fixtures 
     
    5050 
    5151 
    52 $t->diag('Exceptions are thrown if unexpected values are added'); 
     52// @Test: Exceptions are thrown if unexpected values are added 
    5353 
    5454  // fixtures 
     
    6868 
    6969 
    70 $t->diag('setFailOnVerify() suppresses exceptions'); 
     70// @Test: setFailOnVerify() suppresses exceptions 
    7171 
    7272  // fixtures 
  • tools/lime/branches/2.0-experimental/test/unit/mock/LimeMockStrictTest.php

    r20308 r20332  
    1111 
    1212include dirname(__FILE__).'/../../bootstrap/unit.php'; 
    13 require_once dirname(__FILE__).'/../../MockLimeTest.php'; 
     13require_once dirname(__FILE__).'/../../MockLimeOutput.php'; 
    1414 
    1515LimeAnnotationSupport::enable(); 
     
    2121// @Before 
    2222 
    23   $mockTest = new MockLimeTest(); 
    24   $m = LimeMock::createStrict('TestClass', $mockTest); 
     23  $output = new MockLimeOutput(); 
     24  $m = LimeMock::createStrict('TestClass', $output); 
    2525 
    2626 
    2727// @After 
    2828 
    29   $mockTest = null; 
     29  $output = null; 
    3030  $m = null; 
    3131 
     
    4141  $m->verify(); 
    4242  // assertions 
    43   $t->is($mockTest->passes, 2, 'Two tests passed'); 
    44   $t->is($mockTest->fails, 0, 'No test failed'); 
     43  $t->is($output->passes, 2, 'Two tests passed'); 
     44  $t->is($output->fails, 0, 'No test failed'); 
    4545 
    4646 
     
    7979  $m->verify(); 
    8080  // assertions 
    81   $t->is($mockTest->passes, 2, 'Two tests passed'); 
    82   $t->is($mockTest->fails, 1, 'One test failed'); 
     81  $t->is($output->passes, 2, 'Two tests passed'); 
     82  $t->is($output->fails, 1, 'One test failed'); 
    8383 
    8484 
     
    110110  $m->verify(); 
    111111  // assertions 
    112   $t->is($mockTest->passes, 2, 'Two tests passed'); 
    113   $t->is($mockTest->fails, 0, 'No test failed'); 
     112  $t->is($output->passes, 2, 'Two tests passed'); 
     113  $t->is($output->fails, 0, 'No test failed'); 
    114114 
    115115 
     
    139139  $m->verify(); 
    140140  // assertions 
    141   $t->is($mockTest->passes, 2, 'Two tests passed'); 
    142   $t->is($mockTest->fails, 0, 'No test failed'); 
     141  $t->is($output->passes, 2, 'Two tests passed'); 
     142  $t->is($output->fails, 0, 'No test failed'); 
    143143 
    144144 
  • tools/lime/branches/2.0-experimental/test/unit/mock/LimeMockTest.php

    r20313 r20332  
    1010 
    1111include dirname(__FILE__).'/../../bootstrap/unit.php'; 
    12 require_once dirname(__FILE__).'/../../MockLimeTest.php'; 
     12require_once dirname(__FILE__).'/../../MockLimeOutput.php'; 
    1313 
    1414LimeAnnotationSupport::enable(); 
     
    4848{ 
    4949  public function __construct() {} 
    50   public function __call($method, $args) {} 
     50  public function __call($method, array $args) {} 
    5151  public function __lime_replay() {} 
    5252  public function __lime_getState() {} 
     
    6161// @Before 
    6262 
    63   $mockTest = new MockLimeTest(); 
    64   $m = LimeMock::create('TestClass', $mockTest); 
     63  $output = new MockLimeOutput(); 
     64  $m = LimeMock::create('TestClass', $output); 
    6565 
    6666 
    6767// @After 
    6868 
    69   $mockTest = null; 
     69  $output = null; 
    7070  $m = null; 
    7171 
     
    190190  $m->verify(); 
    191191  // assertions 
    192   $t->is($mockTest->fails, 1, 'One test failed'); 
    193   $t->is($mockTest->passes, 0, 'No test passed'); 
     192  $t->is($output->fails, 1, 'One test failed'); 
     193  $t->is($output->passes, 0, 'No test passed'); 
    194194 
    195195 
     
    202202  $m->verify(); 
    203203  // assertions 
    204   $t->is($mockTest->passes, 1, 'One test passed'); 
    205   $t->is($mockTest->fails, 0, 'No test failed'); 
     204  $t->is($output->passes, 1, 'One test passed'); 
     205  $t->is($output->fails, 0, 'No test failed'); 
    206206 
    207207 
     
    216216  $m->verify(); 
    217217  // assertions 
    218   $t->is($mockTest->passes, 2, 'Two tests passed'); 
    219   $t->is($mockTest->fails, 0, 'No test failed'); 
     218  $t->is($output->passes, 2, 'Two tests passed'); 
     219  $t->is($output->fails, 0, 'No test failed'); 
    220220 
    221221 
     
    230230  $m->hurray(); 
    231231  // assertions 
    232   $t->is($mockTest->passes, 1, 'One test passed'); 
    233   $t->is($mockTest->fails, 0, 'No test failed'); 
     232  $t->is($output->passes, 1, 'One test passed'); 
     233  $t->is($output->fails, 0, 'No test failed'); 
    234234 
    235235 
     
    244244  $m->verify(); 
    245245  // assertions 
    246   $t->is($mockTest->passes, 1, 'One test passed'); 
    247   $t->is($mockTest->fails, 0, 'No test failed'); 
     246  $t->is($output->passes, 1, 'One test passed'); 
     247  $t->is($output->fails, 0, 'No test failed'); 
    248248 
    249249 
     
    277277  $m->verify(); 
    278278  // assertions 
    279   $t->is($mockTest->fails, 1, 'One test failed'); 
    280   $t->is($mockTest->passes, 0, 'No test passed'); 
     279  $t->is($output->fails, 1, 'One test failed'); 
     280  $t->is($output->passes, 0, 'No test passed'); 
    281281 
    282282 
     
    292292  $m->verify(); 
    293293  // assertions 
    294   $t->is($mockTest->passes, 1, 'One test passed'); 
    295   $t->is($mockTest->fails, 1, 'One test failed'); 
     294  $t->is($output->passes, 1, 'One test passed'); 
     295  $t->is($output->fails, 1, 'One test failed'); 
    296296 
    297297 
     
    306306  $m->verify(); 
    307307  // assertions 
    308   $t->is($mockTest->passes, 2, 'Two tests passed'); 
    309   $t->is($mockTest->fails, 0, 'No test failed'); 
     308  $t->is($output->passes, 2, 'Two tests passed'); 
     309  $t->is($output->fails, 0, 'No test failed'); 
    310310 
    311311 
     
    320320  $m->verify(); 
    321321  // assertions 
    322   $t->is($mockTest->passes, 2, 'Two tests passed'); 
    323   $t->is($mockTest->fails, 0, 'No test failed'); 
     322  $t->is($output->passes, 2, 'Two tests passed'); 
     323  $t->is($output->fails, 0, 'No test failed'); 
    324324 
    325325 
     
    333333  $m->verify(); 
    334334  // assertions 
    335   $t->is($mockTest->passes, 1, 'One test passed'); 
    336   $t->is($mockTest->fails, 0, 'No test failed'); 
     335  $t->is($output->passes, 1, 'One test passed'); 
     336  $t->is($output->fails, 0, 'No test failed'); 
    337337 
    338338 
     
    345345  $m->verify(); 
    346346  // assertions 
    347   $t->is($mockTest->passes, 1, 'One test passed'); 
    348   $t->is($mockTest->fails, 0, 'No test failed'); 
     347  $t->is($output->passes, 1, 'One test passed'); 
     348  $t->is($output->fails, 0, 'No test failed'); 
    349349 
    350350 
     
    371371  $m->verify(); 
    372372  // assertions 
    373   $t->is($mockTest->passes, 1, 'One test passed'); 
    374   $t->is($mockTest->fails, 0, 'No test failed'); 
     373  $t->is($output->passes, 1, 'One test passed'); 
     374  $t->is($output->fails, 0, 'No test failed'); 
    375375 
    376376 
     
    384384  $m->verify(); 
    385385  // assertions 
    386   $t->is($mockTest->passes, 0, 'No test passed'); 
    387   $t->is($mockTest->fails, 1, 'One test failed'); 
     386  $t->is($output->passes, 0, 'No test passed'); 
     387  $t->is($output->fails, 1, 'One test failed'); 
    388388 
    389389 
     
    409409  $m->verify(); 
    410410  // assertions 
    411   $t->is($mockTest->passes, 1, 'One test passed'); 
    412   $t->is($mockTest->fails, 0, 'No test failed'); 
     411  $t->is($output->passes, 1, 'One test passed'); 
     412  $t->is($output->fails, 0, 'No test failed'); 
    413413 
    414414 
     
    432432  $m->verify(); 
    433433  // assertions 
    434   $t->is($mockTest->passes, 0, 'No test passed'); 
    435   $t->is($mockTest->fails, 1, 'One test failed'); 
     434  $t->is($output->passes, 0, 'No test passed'); 
     435  $t->is($output->fails, 1, 'One test failed'); 
    436436 
    437437  // @Test: - Case 2: One actual call 
     
    442442  $m->verify(); 
    443443  // assertions 
    444   $t->is($mockTest->passes, 1, 'One test passed'); 
    445   $t->is($mockTest->fails, 0, 'No test failed'); 
     444  $t->is($output->passes, 1, 'One test passed'); 
     445  $t->is($output->fails, 0, 'No test failed'); 
    446446 
    447447  // @Test: - Case 3: Two actual calls 
     
    453453  $m->verify(); 
    454454  // assertions 
    455   $t->is($mockTest->passes, 1, 'One test passed'); 
    456   $t->is($mockTest->fails, 0, 'No test failed'); 
     455  $t->is($output->passes, 1, 'One test passed'); 
     456  $t->is($output->fails, 0, 'No test failed'); 
    457457 
    458458 
     
    479479  $m->verify(); 
    480480  // assertions 
    481   $t->is($mockTest->passes, 1, 'One test passed'); 
    482   $t->is($mockTest->fails, 0, 'No test failed'); 
     481  $t->is($output->passes, 1, 'One test passed'); 
     482  $t->is($output->fails, 0, 'No test failed'); 
    483483 
    484484  // @Test: - Case 1: "Wrong" parameters 
     
    490490  $m->verify(); 
    491491  // assertions 
    492   $t->is($mockTest->passes, 1, 'One test passed'); 
    493   $t->is($mockTest->fails, 0, 'No test failed'); 
     492  $t->is($output->passes, 1, 'One test passed'); 
     493  $t->is($output->fails, 0, 'No test failed'); 
    494494 
    495495 
     
    504504  $m->verify(); 
    505505  // assertions 
    506   $t->is($mockTest->passes, 0, 'No test passed'); 
    507   $t->is($mockTest->fails, 1, 'One test failed'); 
     506  $t->is($output->passes, 0, 'No test passed'); 
     507  $t->is($output->fails, 1, 'One test failed'); 
    508508 
    509509  // @Test: - Case 2: Correct number 
     
    516516  $m->verify(); 
    517517  // assertions 
    518   $t->is($mockTest->passes, 1, 'One test passed'); 
    519   $t->is($mockTest->fails, 0, 'No test failed'); 
     518  $t->is($output->passes, 1, 'One test passed'); 
     519  $t->is($output->fails, 0, 'No test failed'); 
    520520 
    521521  // @Test: - Case 3: Another correct number 
     
    530530  $m->verify(); 
    531531  // assertions 
    532   $t->is($mockTest->passes, 1, 'One test passed'); 
    533   $t->is($mockTest->fails, 0, 'No test failed'); 
     532  $t->is($output->passes, 1, 'One test passed'); 
     533  $t->is($output->fails, 0, 'No test failed'); 
    534534 
    535535  // @Test: - Case 4: Too many calls 
     
    557557  $m->verify(); 
    558558  // assertions 
    559   $t->is($mockTest->passes, 2, 'Two tests passed'); 
    560   $t->is($mockTest->fails, 0, 'No test failed'); 
     559  $t->is($output->passes, 2, 'Two tests passed'); 
     560  $t->is($output->fails, 0, 'No test failed'); 
    561561 
    562562  // @Test: - Case 2: Any actual calls 
     
    591591  $m->verify(); 
    592592  // assertions 
    593   $t->is($mockTest->passes, 1, 'One test passed'); 
    594   $t->is($mockTest->fails, 0, 'No test failed'); 
     593  $t->is($output->passes, 1, 'One test passed'); 
     594  $t->is($output->fails, 0, 'No test failed'); 
    595595 
    596596 
     
    615615  $m->verify(); 
    616616  // assertions 
    617   $t->is($mockTest->passes, 0, 'No test passed'); 
    618   $t->is($mockTest->fails, 0, 'No test failed'); 
     617  $t->is($output->passes, 0, 'No test passed'); 
     618  $t->is($output->fails, 0, 'No test failed'); 
    619619 
    620620