Changeset 20976
- Timestamp:
- 08/09/09 22:21:17 (4 years ago)
- Files:
-
- tools/lime/branches/2.0-experimental/lib/mock/LimeMockBehaviour.php (modified) (1 diff)
- tools/lime/branches/2.0-experimental/lib/mock/LimeMockException.php (moved) (moved from tools/lime/branches/2.0-experimental/lib/mock/LimeMockInvocationException.php) (2 diffs, 1 prop)
- tools/lime/branches/2.0-experimental/lib/mock/template/mocked_class.tpl (modified) (2 diffs)
- tools/lime/branches/2.0-experimental/lib/output/LimeOutputConsoleDetailed.php (modified) (1 diff)
- tools/lime/branches/2.0-experimental/test/unit/mock/LimeMockStrictTest.php (modified) (4 diffs)
- tools/lime/branches/2.0-experimental/test/unit/mock/LimeMockTest.php (modified) (10 diffs)
- tools/lime/branches/2.0-experimental/test/unit/output/LimeOutputConsoleDetailedTest.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tools/lime/branches/2.0-experimental/lib/mock/LimeMockBehaviour.php
r20309 r20976 28 28 if (!$this->verified && !$this->failOnVerify && ($this->expectNothing || count($this->invocations) > 0)) 29 29 { 30 throw new Lime AssertionException('Unexpected method call', $invocation);30 throw new LimeMockException($invocation, array(), array()); 31 31 } 32 32 } tools/lime/branches/2.0-experimental/lib/mock/LimeMockException.php
- Property svn:mergeinfo set
r20970 r20976 1 1 <?php 2 2 3 class LimeMock InvocationException extends Exception3 class LimeMockException extends Exception 4 4 { 5 5 private … … 15 15 $this->pastInvocations = $pastInvocations; 16 16 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; 18 33 } 19 34 } tools/lime/branches/2.0-experimental/lib/mock/template/mocked_class.tpl
r20955 r20976 13 13 } 14 14 15 public function __call($method, array$parameters)15 public function __call($method, $parameters) 16 16 { 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 } 18 26 } 19 27 … … 30 38 <?php if ($generate_methods): ?> 31 39 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); } 33 41 public function reset() { return $this->state->reset(); } 34 42 public function verify() { return $this->state->verify(); } tools/lime/branches/2.0-experimental/lib/output/LimeOutputConsoleDetailed.php
r20975 r20976 143 143 $this->printer->printLargeBox($message, LimePrinter::ERROR); 144 144 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(''); 174 178 } 175 179 tools/lime/branches/2.0-experimental/test/unit/mock/LimeMockStrictTest.php
r20332 r20976 51 51 $m->method2(); 52 52 $m->replay(); 53 $t->expect('Lime AssertionException');53 $t->expect('LimeMockException'); 54 54 // test 55 55 $m->method2(); … … 62 62 $m->replay(); 63 63 $m->method1(); 64 $t->expect('Lime AssertionException');64 $t->expect('LimeMockException'); 65 65 $m->method2(); 66 66 … … 91 91 $m->method2(); 92 92 $m->replay(); 93 $t->expect('Lime AssertionException');93 $t->expect('LimeMockException'); 94 94 // test 95 95 $m->method1(); … … 122 122 $m->method2(); 123 123 $m->replay(); 124 $t->expect('Lime AssertionException');124 $t->expect('LimeMockException'); 125 125 // test 126 126 $m->method2(); tools/lime/branches/2.0-experimental/test/unit/mock/LimeMockTest.php
r20955 r20976 48 48 { 49 49 public function __construct() {} 50 public function __call($method, array$args) {}50 public function __call($method, $args) {} 51 51 public function __lime_replay() {} 52 52 public function __lime_getState() {} … … 285 285 $m->testMethod(1, 'Foobar'); 286 286 $m->replay(); 287 $t->expect('Lime AssertionException');287 $t->expect('LimeMockException'); 288 288 // test 289 289 $m->testMethod(1); … … 295 295 $m->testMethod(1, 'Foobar'); 296 296 $m->replay(); 297 $t->expect('Lime AssertionException');297 $t->expect('LimeMockException'); 298 298 // test 299 299 $m->testMethod('Foobar', 1); … … 389 389 $m->testMethod(1); 390 390 $m->replay(); 391 $t->expect('Lime AssertionException');391 $t->expect('LimeMockException'); 392 392 // test 393 393 $m->testMethod('1'); … … 427 427 $m->testMethod(1); 428 428 $m->testMethod(1); 429 $t->expect('Lime AssertionException');429 $t->expect('LimeMockException'); 430 430 // test 431 431 $m->testMethod(1); … … 451 451 $m->replay(); 452 452 $m->testMethod(1); 453 $t->expect('Lime AssertionException');453 $t->expect('LimeMockException'); 454 454 // test 455 455 $m->testMethod(); … … 574 574 $m->testMethod(); 575 575 $m->testMethod(); 576 $t->expect('Lime AssertionException');576 $t->expect('LimeMockException'); 577 577 $m->testMethod(); 578 578 … … 599 599 $m->replay(); 600 600 $m->testMethod(1, 2, 3); 601 $t->expect('Lime AssertionException');601 $t->expect('LimeMockException'); 602 602 $m->testMethod(); 603 603 … … 610 610 $m->testMethod(1)->strict(); 611 611 $m->replay(); 612 $t->expect('Lime AssertionException');612 $t->expect('LimeMockException'); 613 613 // test 614 614 $m->testMethod('1'); … … 656 656 $m->setExpectNothing(); 657 657 $m->replay(); 658 $t->expect('Lime AssertionException');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 14 14 LimeAnnotationSupport::enable(); 15 15 16 $t = new LimeTest( 58);16 $t = new LimeTest(64); 17 17 18 18 // @Before … … 218 218 // fixtures 219 219 $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(); 220 223 $printer->replay(); 221 224 // test … … 230 233 $output = new LimeOutputConsoleDetailed($printer, array('base_dir' => '/test')); 231 234 $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(); 232 238 $printer->replay(); 233 239 // test