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)); }
/** * Testing when case add method */ public function testWhenCaseAddMethod() { $mock = ShortifyPunit::mock('Foo'); $whenCase = new WhenCase(get_class($mock), $mock->getShortifyPunitInstanceId()); $whenCase->bar(array())->returns(array()); }
/** * Creating sandboxResponseManager with dependencies * * @param $force * @param bool $annotationsReader * @return SandboxResponseManager */ private function createManager($force, $annotationsReader = false) { if (!$annotationsReader instanceof AnnotationReader) { $annotationsReader = new AnnotationReader(); } // Mocking the sandbox response manager dependencies $kernel = ShortifyPunit::mock('SandboxBundle\\Tests\\Managers\\AppKernel'); ShortifyPunit::when($kernel)->locateResource('@SandboxBundle/Resources/responses/token.xml')->returns(self::$XML_PATH); ShortifyPunit::when($kernel)->locateResource('@SandboxBundle/Resources/responses/token.json')->returns(self::$JSON_PATH); // Create manager return new SandboxResponseManager($kernel, $force, $annotationsReader); }
public function testLoad() { $containerBuilder = ShortifyPunit::mock('Symfony\\Component\\DependencyInjection\\ContainerBuilder'); $sandboxExtension = new SandboxExtension(); $sandboxExtension->load(array('sandbox' => array('response' => array('force' => true))), $containerBuilder); }
/** * Stubbing magic methods */ public function testStubbingMagicMethods() { $mock = ShortifyPunit::mock('MagicClass'); ShortifyPunit::when($mock)->__toString()->returns('mockString'); $this->assertEquals($mock->__toString(), 'mockString'); $this->assertEquals($mock, 'mockString'); }