public function stub($class, array $options = array()) { $options = array_merge(array('nice' => true, 'no_exceptions' => true), $options); return LimeMock::create($class, new LimeOutputNone(), $options); }
// fixture $m->method('testMethod')->parameter(2)->is('foo'); $m->replay(); $t->expect('LimeMockException'); // test $m->testMethod(1); // @Test: If a class with the mock's control methods is mocked, an exception is thrown // test $t->expect('LogicException'); $m = LimeMock::create('TestClassWithControlMethods'); // @Test: If a class with the mock's control methods is mocked and "generate_controls" is set to false, no exception is thrown // test $m = LimeMock::create('TestClassWithControlMethods', array('generate_controls' => false)); // @Test: The control methods like ->replay() can be mocked // fixtures $m = LimeMock::create('TestClass', array('generate_controls' => false)); // test $m->replay()->returns('Foobar'); LimeMock::replay($m); $value = $m->replay(); // assertions $t->is($value, 'Foobar', 'The return value was correct'); // @Test: If no method call is expected, all method calls are ignored // test $m->replay(); $m->testMethod1(); $m->testMethod2(1, 'Foobar'); $m->verify(); // assertions $t->is(count($m->__lime_getInvocationTrace()), 0, 'No test passed'); // @Test: If setExpectNothing() is called, no method must be called
public function stub($class, array $options = array()) { $options = array_merge(array('nice' => true, 'default_count' => 'any'), $options); return LimeMock::create($class, $options); }
$m->method1(); $m->method2(); $m->replay(); $t->expect('LimeMockException'); // test $m->method2(); // @Test: An exception is thrown if too many methods are called // test $m->method1(); $m->replay(); $m->method1(); $t->expect('LimeMockException'); $m->method2(); // @Test: If the option "nice" is set, ->verify() fails if methods were called in the wrong order // test $m = LimeMock::create('TestClass', array('strict' => true, 'nice' => true)); $m->method1(); $m->method2(); $m->method3(); $m->replay(); $m->method3(); $m->method1(); $m->method2(); $t->is(count($m->__lime_getInvocationTrace()), 2, 'Two tests passed'); $t->expect('LimeMockException'); $m->verify(); // @Test: The order of the tests remains intact when using times() // @Test: Case 1 - Assertion fails // fixtures $m->method1()->times(3); $m->method2();