public function testIsAvailableEmptyQuote() { $activeValueHandler = $this->getMock('Magento\\Payment\\Gateway\\Config\\ValueHandlerInterface'); $availabilityValidator = $this->getMock('Magento\\Payment\\Gateway\\Validator\\ValidatorInterface'); $paymentDO = $this->getMock('Magento\\Payment\\Gateway\\Data\\PaymentDataObjectInterface'); $validationResult = $this->getMock('Magento\\Payment\\Gateway\\Validator\\ResultInterface'); $paymentInfo = $this->getMock('Magento\\Payment\\Model\\InfoInterface'); $this->valueHandlerPool->expects(static::once())->method('get')->with('active')->willReturn($activeValueHandler); $activeValueHandler->expects(static::once())->method('handle')->with(['field' => 'active', 'payment' => $paymentDO])->willReturn(true); $this->validatorPool->expects(static::once())->method('get')->with('availability')->willReturn($availabilityValidator); $this->paymentDataObjectFactory->expects(static::exactly(2))->method('create')->with($paymentInfo)->willReturn($paymentDO); $availabilityValidator->expects(static::once())->method('validate')->willReturn($validationResult); $validationResult->expects(static::once())->method('isValid')->willReturn(true); $this->eventManager->expects(static::once())->method('dispatch'); $this->adapter->setInfoInstance($paymentInfo); static::assertTrue($this->adapter->isAvailable(null)); }
public function testExecuteCommandWithCommandPool() { /** @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject $eventManager */ $eventManager = $this->getMock(ManagerInterface::class); /** @var ValueHandlerPoolInterface|\PHPUnit_Framework_MockObject_MockObject $valueHandlerPool */ $valueHandlerPool = $this->getMock(ValueHandlerPoolInterface::class); /** @var CommandPoolInterface|\PHPUnit_Framework_MockObject_MockObject $commandPool */ $commandPool = $this->getMock(CommandPoolInterface::class); /** @var PaymentDataObjectFactory|\PHPUnit_Framework_MockObject_MockObject $paymentDataObjectFactory */ $paymentDataObjectFactory = $this->getMockBuilder(PaymentDataObjectFactory::class)->disableOriginalConstructor()->getMock(); $paymentInfo = $this->getMock(InfoInterface::class); $paymentDO = $this->getMock(PaymentDataObjectInterface::class); $adapter = new Adapter($eventManager, $valueHandlerPool, $paymentDataObjectFactory, 'CODE', '\\FormBlock', '\\InfoBlock', $commandPool); $valueHandler = $this->getMock(ValueHandlerInterface::class); $command = $this->getMock(CommandInterface::class); $valueHandlerPool->expects(static::once())->method('get')->with('can_authorize')->willReturn($valueHandler); $valueHandler->expects(static::once())->method('handle')->with(['field' => 'can_authorize'])->willReturn(true); $paymentDataObjectFactory->expects(static::once())->method('create')->with($paymentInfo)->willReturn($paymentDO); $commandPool->expects(static::once())->method('get')->with('authorize')->willReturn($command); $command->expects(static::once())->method('execute')->with(['amount' => 10, 'payment' => $paymentDO])->willReturn(null); $adapter->authorize($paymentInfo, 10); }