/** * @param TblCronTask[] $cronTasks * @return \Trovit\CronManagerBundle\Repository\TblCronTaskRepository|\PHPUnit_Framework_MockObject_MockObject */ public function getReadMock(array $cronTasks) { $mock = $this->getBasicMock(); $mock->expects($this->_testCase->once())->method('findAll')->willReturn($cronTasks); $mock->expects($this->_testCase->once())->method('getActiveCronTasks')->willReturn($cronTasks); return $mock; }
/** * Return mocks with expected invokes * * First element is quoteIdMaskFactoryMock, second one is quoteIdMaskMock * * @param $maskedCartId * @param $cartId * @return array */ public function mockQuoteIdMask($maskedCartId, $cartId) { $quoteIdMaskMock = $this->testCase->getMock('Magento\\Quote\\Model\\QuoteIdMask', ['load', 'getQuoteId', 'getMaskedId'], [], '', false); $quoteIdMaskFactoryMock = $this->testCase->getMockBuilder('Magento\\Quote\\Model\\QuoteIdMaskFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock(); $quoteIdMaskFactoryMock->expects($this->testCase->once())->method('create')->willReturn($quoteIdMaskMock); $quoteIdMaskMock->expects($this->testCase->once())->method('load')->with($maskedCartId)->willReturnSelf(); $quoteIdMaskMock->expects($this->testCase->once())->method('getQuoteId')->willReturn($cartId); return [$quoteIdMaskFactoryMock, $quoteIdMaskMock]; }
/** * Create a new mock of the curlbuilder and return * the given filename as content * * @access public * @param PHPUnit_Framework_TestCase $instance * @return mock */ public static function create($instance) { $reflection = new \ReflectionMethod($instance, $instance->getName()); $doc_block = $reflection->getDocComment(); $responsefile = self::parseDocBlock($doc_block, '@responsefile'); $responsecode = self::parseDocBlock($doc_block, '@responsecode'); $defaultheaders = array("X-Ratelimit-Limit" => "1000", "X-Ratelimit-Remaining" => "998", "X-Varnish" => "4059929980"); $skipmock = self::parseDocBlock($doc_block, '@skipmock'); if (empty($responsecode)) { $responsecode = [201]; } if (empty($responsefile)) { $responsefile = [$instance->getName()]; } // Setup Curlbuilder mock $curlbuilder = $instance->getMockBuilder("\\DirkGroenen\\Pinterest\\Utils\\CurlBuilder")->getMock(); $curlbuilder->expects($instance->any())->method('create')->will($instance->returnSelf()); // Build response file path $responseFilePath = __DIR__ . '/../responses/' . (new \ReflectionClass($instance))->getShortName() . '/' . $responsefile[0] . ".json"; if (file_exists($responseFilePath)) { $curlbuilder->expects($instance->once())->method('execute')->will($instance->returnValue(file_get_contents($responseFilePath))); } $curlbuilder->expects($instance->any())->method('getInfo')->will($instance->returnValue($responsecode[0])); return $curlbuilder; }
/** * @test */ public function getFormattedMessage() { $formatter = $this->getFormatterMock(); $record = $this->getRecordMock(); $formatter->expects(parent::once())->method('format')->with($record)->willReturn('foobar'); $this->formatterContainer->setFormatter($formatter); parent::assertSame('foobar', $this->formatterContainer->getFormattedMessage($record)); }
/** * Create a new mock of the curlbuilder and return * the given filename as content * * @access public * @param PHPUnit_Framework_TestCase $instance * @return mock */ public static function create($instance) { $reflection = new \ReflectionMethod($instance, $instance->getName()); $doc_block = $reflection->getDocComment(); $responsefile = self::parseDocBlock($doc_block, '@responsefile'); $responsecode = self::parseDocBlock($doc_block, '@responsecode'); if (empty($responsecode)) { $responsecode = [201]; } if (empty($responsefile)) { $responsefile = [$instance->getName()]; } // Setup Curlbuilder mock $curlbuilder = $instance->getMockBuilder("\\DirkGroenen\\Pinterest\\Utils\\CurlBuilder")->getMock(); $curlbuilder->expects($instance->once())->method('create')->will($instance->returnSelf()); $curlbuilder->expects($instance->once())->method('execute')->will($instance->returnValue(file_get_contents(__DIR__ . '/../responses/' . (new \ReflectionClass($instance))->getShortName() . '/' . $responsefile[0] . ".json"))); $curlbuilder->expects($instance->any())->method('getInfo')->will($instance->returnValue($responsecode[0])); return $curlbuilder; }
/** * @param \PHPUnit_Framework_MockObject_MockObject * @param \PHPUnit_Framework_MockObject_MockObject * * @return \PHPUnit_Framework_MockObject_MockObject */ public function getRedirectPluginMock($toRouteResponse = null, $toUrlResponse = null) { $mockBuilder = new MockBuilder($this->testCase, 'Zend\\Mvc\\Controller\\Plugin\\Redirect'); $mockBuilder->setMethods(['toRoute', 'toUrl']); $mockBuilder->disableOriginalConstructor(); $redirectMock = $mockBuilder->getMock(); if ($toRouteResponse) { $redirectMock->expects($this->testCase->once())->method('toRoute')->willReturn($toRouteResponse); } if ($toUrlResponse) { $redirectMock->expects($this->testCase->once())->method('toUrl')->willReturn($toUrlResponse); } return $redirectMock; }
/** * Returns a matcher that matches when the method it is evaluated for * is executed exactly once. * * @return PHPUnit_Framework_MockObject_Matcher_InvokedCount * @since Method available since Release 3.0.0 */ function once() { return PHPUnit_Framework_TestCase::once(); }
/** * @param bool $commandExistsReturn * @return \Trovit\CronManagerBundle\Model\CommandValidator|\PHPUnit_Framework_MockObject_MockObject */ public function getCreateCronTaskTestMock($commandExistsReturn) { $mock = $this->getBasicMock(); $mock->expects($this->_testCase->once())->method('commandExists')->willReturn($commandExistsReturn); return $mock; }
/** * @return \PHPUnit_Framework_MockObject_MockObject|ProcessorInterface */ protected function getProcessorWithRunOnce() { $processor = $this->getProcessorMock(); $processor->expects(parent::once())->method('process'); return $processor; }
public function expectsCall($method) { return $this->expects($method, $this->testCase->once()); }
/** * @inheritdoc */ public function setUp() { $this->ipProvider = $this->getMockBuilder(IpProviderInterface::class)->setMethods(['getCurrentIpAddress'])->getMock(); $this->ipProvider->expects(parent::once())->method('getCurrentIpAddress')->willReturn(self::$ipAddress); }