|
6 | 6 | namespace Magento\Payment\Test\Unit\Model\Method;
|
7 | 7 |
|
8 | 8 | use Magento\Framework\Event\ManagerInterface;
|
| 9 | +use Magento\Payment\Gateway\Command\CommandManagerInterface; |
9 | 10 | use Magento\Payment\Gateway\Command\CommandPoolInterface;
|
| 11 | +use Magento\Payment\Gateway\CommandInterface; |
| 12 | +use Magento\Payment\Gateway\Config\ValueHandlerInterface; |
10 | 13 | use Magento\Payment\Gateway\Config\ValueHandlerPoolInterface;
|
11 | 14 | use Magento\Payment\Gateway\Data\PaymentDataObjectFactory;
|
| 15 | +use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; |
12 | 16 | use Magento\Payment\Gateway\Validator\ValidatorPoolInterface;
|
| 17 | +use Magento\Payment\Model\InfoInterface; |
13 | 18 | use Magento\Payment\Model\Method\Adapter;
|
14 | 19 |
|
15 | 20 | class AdapterTest extends \PHPUnit_Framework_TestCase
|
@@ -158,4 +163,133 @@ public function testIsAvailableEmptyQuote()
|
158 | 163 | $this->adapter->setInfoInstance($paymentInfo);
|
159 | 164 | static::assertTrue($this->adapter->isAvailable(null));
|
160 | 165 | }
|
| 166 | + |
| 167 | + public function testExecuteCommandWithCommandExecutor() |
| 168 | + { |
| 169 | + /** @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject $eventManager */ |
| 170 | + $eventManager = $this->getMock( |
| 171 | + ManagerInterface::class |
| 172 | + ); |
| 173 | + |
| 174 | + /** @var ValueHandlerPoolInterface|\PHPUnit_Framework_MockObject_MockObject $valueHandlerPool */ |
| 175 | + $valueHandlerPool = $this->getMock( |
| 176 | + ValueHandlerPoolInterface::class |
| 177 | + ); |
| 178 | + |
| 179 | + /** @var CommandManagerInterface|\PHPUnit_Framework_MockObject_MockObject $commandManager */ |
| 180 | + $commandManager = $this->getMock( |
| 181 | + CommandManagerInterface::class |
| 182 | + ); |
| 183 | + |
| 184 | + /** @var PaymentDataObjectFactory|\PHPUnit_Framework_MockObject_MockObject $paymentDataObjectFactory */ |
| 185 | + $paymentDataObjectFactory = $this->getMockBuilder( |
| 186 | + PaymentDataObjectFactory::class |
| 187 | + ) |
| 188 | + ->disableOriginalConstructor() |
| 189 | + ->getMock(); |
| 190 | + |
| 191 | + $paymentInfo = $this->getMock(InfoInterface::class); |
| 192 | + $paymentDO = $this->getMock(PaymentDataObjectInterface::class); |
| 193 | + |
| 194 | + $adapter = new Adapter( |
| 195 | + $eventManager, |
| 196 | + $valueHandlerPool, |
| 197 | + $paymentDataObjectFactory, |
| 198 | + 'CODE', |
| 199 | + '\FormBlock', |
| 200 | + '\InfoBlock', |
| 201 | + null, |
| 202 | + null, |
| 203 | + $commandManager |
| 204 | + ); |
| 205 | + |
| 206 | + $valueHandler = $this->getMock(ValueHandlerInterface::class); |
| 207 | + |
| 208 | + $valueHandlerPool->expects(static::once()) |
| 209 | + ->method('get') |
| 210 | + ->with('can_authorize') |
| 211 | + ->willReturn($valueHandler); |
| 212 | + $valueHandler->expects(static::once()) |
| 213 | + ->method('handle') |
| 214 | + ->with(['field' => 'can_authorize']) |
| 215 | + ->willReturn(true); |
| 216 | + |
| 217 | + $paymentDataObjectFactory->expects(static::once()) |
| 218 | + ->method('create') |
| 219 | + ->with($paymentInfo) |
| 220 | + ->willReturn($paymentDO); |
| 221 | + |
| 222 | + $commandManager->expects(static::once()) |
| 223 | + ->method('executeByCode') |
| 224 | + ->with('authorize', $paymentInfo, ['amount' => 10, 'payment' => $paymentDO]) |
| 225 | + ->willReturn(null); |
| 226 | + |
| 227 | + $adapter->authorize($paymentInfo, 10); |
| 228 | + } |
| 229 | + |
| 230 | + public function testExecuteCommandWithCommandPool() |
| 231 | + { |
| 232 | + /** @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject $eventManager */ |
| 233 | + $eventManager = $this->getMock( |
| 234 | + ManagerInterface::class |
| 235 | + ); |
| 236 | + |
| 237 | + /** @var ValueHandlerPoolInterface|\PHPUnit_Framework_MockObject_MockObject $valueHandlerPool */ |
| 238 | + $valueHandlerPool = $this->getMock( |
| 239 | + ValueHandlerPoolInterface::class |
| 240 | + ); |
| 241 | + |
| 242 | + /** @var CommandPoolInterface|\PHPUnit_Framework_MockObject_MockObject $commandPool */ |
| 243 | + $commandPool = $this->getMock( |
| 244 | + CommandPoolInterface::class |
| 245 | + ); |
| 246 | + |
| 247 | + /** @var PaymentDataObjectFactory|\PHPUnit_Framework_MockObject_MockObject $paymentDataObjectFactory */ |
| 248 | + $paymentDataObjectFactory = $this->getMockBuilder( |
| 249 | + PaymentDataObjectFactory::class |
| 250 | + ) |
| 251 | + ->disableOriginalConstructor() |
| 252 | + ->getMock(); |
| 253 | + |
| 254 | + $paymentInfo = $this->getMock(InfoInterface::class); |
| 255 | + $paymentDO = $this->getMock(PaymentDataObjectInterface::class); |
| 256 | + |
| 257 | + $adapter = new Adapter( |
| 258 | + $eventManager, |
| 259 | + $valueHandlerPool, |
| 260 | + $paymentDataObjectFactory, |
| 261 | + 'CODE', |
| 262 | + '\FormBlock', |
| 263 | + '\InfoBlock', |
| 264 | + $commandPool |
| 265 | + ); |
| 266 | + |
| 267 | + $valueHandler = $this->getMock(ValueHandlerInterface::class); |
| 268 | + $command = $this->getMock(CommandInterface::class); |
| 269 | + |
| 270 | + $valueHandlerPool->expects(static::once()) |
| 271 | + ->method('get') |
| 272 | + ->with('can_authorize') |
| 273 | + ->willReturn($valueHandler); |
| 274 | + $valueHandler->expects(static::once()) |
| 275 | + ->method('handle') |
| 276 | + ->with(['field' => 'can_authorize']) |
| 277 | + ->willReturn(true); |
| 278 | + |
| 279 | + $paymentDataObjectFactory->expects(static::once()) |
| 280 | + ->method('create') |
| 281 | + ->with($paymentInfo) |
| 282 | + ->willReturn($paymentDO); |
| 283 | + |
| 284 | + $commandPool->expects(static::once()) |
| 285 | + ->method('get') |
| 286 | + ->with('authorize') |
| 287 | + ->willReturn($command); |
| 288 | + $command->expects(static::once()) |
| 289 | + ->method('execute') |
| 290 | + ->with(['amount' => 10, 'payment' => $paymentDO]) |
| 291 | + ->willReturn(null); |
| 292 | + |
| 293 | + $adapter->authorize($paymentInfo, 10); |
| 294 | + } |
161 | 295 | }
|
0 commit comments