HandlerChainTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Test\Unit\Gateway\Response;
  7. use Magento\Payment\Gateway\Response\HandlerChain;
  8. use Magento\Payment\Gateway\Response\HandlerInterface;
  9. class HandlerChainTest extends \PHPUnit\Framework\TestCase
  10. {
  11. public function testHandle()
  12. {
  13. $handler1 = $this->getMockBuilder(\Magento\Payment\Gateway\Response\HandlerInterface::class)
  14. ->getMockForAbstractClass();
  15. $handler2 = $this->getMockBuilder(\Magento\Payment\Gateway\Response\HandlerInterface::class)
  16. ->getMockForAbstractClass();
  17. $tMapFactory = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMapFactory::class)
  18. ->disableOriginalConstructor()
  19. ->setMethods(['create'])
  20. ->getMock();
  21. $tMap = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMap::class)
  22. ->disableOriginalConstructor()
  23. ->getMock();
  24. $tMapFactory->expects(static::once())
  25. ->method('create')
  26. ->with(
  27. [
  28. 'array' => [
  29. 'handler1' => \Magento\Payment\Gateway\Response\HandlerInterface::class,
  30. 'handler2' => \Magento\Payment\Gateway\Response\HandlerInterface::class
  31. ],
  32. 'type' => HandlerInterface::class
  33. ]
  34. )
  35. ->willReturn($tMap);
  36. $tMap->expects(static::once())
  37. ->method('getIterator')
  38. ->willReturn(new \ArrayIterator([$handler1, $handler2]));
  39. $handlingSubject = [];
  40. $response = [];
  41. $handler1->expects(static::once())
  42. ->method('handle')
  43. ->with($handlingSubject, $response);
  44. $handler2->expects(static::once())
  45. ->method('handle')
  46. ->with($handlingSubject, $response);
  47. $chain = new HandlerChain(
  48. $tMapFactory,
  49. [
  50. 'handler1' => \Magento\Payment\Gateway\Response\HandlerInterface::class,
  51. 'handler2' => \Magento\Payment\Gateway\Response\HandlerInterface::class
  52. ]
  53. );
  54. $chain->handle($handlingSubject, $response);
  55. }
  56. }