Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
HandlerChainTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class HandlerChainTest extends \PHPUnit\Framework\TestCase
12 {
13  public function testHandle()
14  {
15  $handler1 = $this->getMockBuilder(\Magento\Payment\Gateway\Response\HandlerInterface::class)
16  ->getMockForAbstractClass();
17  $handler2 = $this->getMockBuilder(\Magento\Payment\Gateway\Response\HandlerInterface::class)
18  ->getMockForAbstractClass();
19  $tMapFactory = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMapFactory::class)
20  ->disableOriginalConstructor()
21  ->setMethods(['create'])
22  ->getMock();
23  $tMap = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMap::class)
24  ->disableOriginalConstructor()
25  ->getMock();
26 
27  $tMapFactory->expects(static::once())
28  ->method('create')
29  ->with(
30  [
31  'array' => [
32  'handler1' => \Magento\Payment\Gateway\Response\HandlerInterface::class,
33  'handler2' => \Magento\Payment\Gateway\Response\HandlerInterface::class
34  ],
35  'type' => HandlerInterface::class
36  ]
37  )
38  ->willReturn($tMap);
39  $tMap->expects(static::once())
40  ->method('getIterator')
41  ->willReturn(new \ArrayIterator([$handler1, $handler2]));
42 
43  $handlingSubject = [];
44  $response = [];
45  $handler1->expects(static::once())
46  ->method('handle')
47  ->with($handlingSubject, $response);
48  $handler2->expects(static::once())
49  ->method('handle')
50  ->with($handlingSubject, $response);
51 
52  $chain = new HandlerChain(
53  $tMapFactory,
54  [
55  'handler1' => \Magento\Payment\Gateway\Response\HandlerInterface::class,
56  'handler2' => \Magento\Payment\Gateway\Response\HandlerInterface::class
57  ]
58  );
59  $chain->handle($handlingSubject, $response);
60  }
61 }
$response
Definition: 404.php:11