Examples:
ShortifyPunit::when($mock)->first_method()->returns(1);
echo $mock->first_method(); // method called once
ShortifyPunit::verify($mock)->first_method()->neverCalled(); // returns FALSE
ShortifyPunit::verify($mock)->first_method()->atLeast(2); // returns FALSE
ShortifyPunit::verify($mock)->first_method()->calledTimes(1); // returns TRUE
echo $mock->first_method(); // method has been called twice
ShortifyPunit::verify($mock)->first_method()->neverCalled(); // returns FALSE
ShortifyPunit::verify($mock)->first_method()->atLeast(2); // returns TRUE
ShortifyPunit::verify($mock)->first_method()->calledTimes(2); // returns TRUE
public static verify ( $mock ) : ShortifyPunit\Verify\Verify | ||
$mock | ||
return | ShortifyPunit\Verify\Verify |
public function testOnKernelController() { $request = ShortifyPunit::mock('Symfony\\Component\\HttpFoundation\\Request'); $requestStack = ShortifyPunit::mock('Symfony\\Component\\HttpFoundation\\RequestStack'); $sandboxResponseManager = ShortifyPunit::mock('danrevah\\SandboxBundle\\Managers\\SandboxResponseManager'); $event = ShortifyPunit::mock('Symfony\\Component\\HttpKernel\\Event\\FilterControllerEvent'); $parameterBag = ShortifyPunit::mock('Symfony\\Component\\HttpFoundation\\ParameterBag'); ShortifyPunit::when($request)->getContent()->returns(''); $request->query = $parameterBag; $request->request = $parameterBag; ShortifyPunit::when($requestStack)->getCurrentRequest()->returns($request); ShortifyPunit::when($event)->getController()->returns([0, 1]); ShortifyPunit::when($event)->setController(anything())->returns(1); $sandboxListener = new SandboxListener($requestStack, $sandboxResponseManager); $sandboxListener->onKernelController($event); $this->assertTrue(ShortifyPunit::verify($event)->setController(anything())->atLeastOnce()); $response = [false, 0, 0, 0]; ShortifyPunit::when($sandboxResponseManager)->getResponseController(anything(), anything(), anything(), anything(), anything())->returns($response); $event2 = ShortifyPunit::mock('Symfony\\Component\\HttpKernel\\Event\\FilterControllerEvent'); ShortifyPunit::when($event2)->setController(anything())->returns(''); ShortifyPunit::when($event2)->getController(anything())->returns([0, 1]); $sandboxListener = new SandboxListener($requestStack, $sandboxResponseManager); $sandboxListener->onKernelController($event2); $this->assertTrue(ShortifyPunit::verify($event2)->setController(anything())->neverCalled()); }
/** * Testing with Hamcrest matching functions */ public function testWithHamcrestMatcher() { $mock = ShortifyPunit::mock('Foo'); ShortifyPunit::when($mock)->bar(equalTo(1))->foo(anything())->returns(10); $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->neverCalled()); $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeast(0)); $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->calledTimes(0)); $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->lessThan(1)); $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeastOnce()); $mock->bar(1)->foo(2); $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->neverCalled()); $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeast(1)); $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeastOnce()); $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->calledTimes(1)); $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->lessThan(2)); $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeast(2)); $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->calledTimes(2)); $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->lessThan(1)); }