Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CommandPoolTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class CommandPoolTest extends \PHPUnit\Framework\TestCase
12 {
13  public function testGet()
14  {
15  $commandI = $this->getMockBuilder(\Magento\Payment\Gateway\CommandInterface::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 
25  $tMapFactory->expects(static::once())
26  ->method('create')
27  ->with(
28  [
29  'array' => [\Magento\Payment\Gateway\CommandInterface::class],
30  'type' => CommandInterface::class
31  ]
32  )
33  ->willReturn($tMap);
34  $tMap->expects(static::once())
35  ->method('offsetExists')
36  ->with('command')
37  ->willReturn(true);
38  $tMap->expects(static::once())
39  ->method('offsetGet')
40  ->with('command')
41  ->willReturn($commandI);
42 
43  $pool = new CommandPool($tMapFactory, [\Magento\Payment\Gateway\CommandInterface::class]);
44 
45  static::assertSame($commandI, $pool->get('command'));
46  }
47 
48  public function testGetException()
49  {
50  $this->expectException(\Magento\Framework\Exception\NotFoundException::class);
51 
52  $tMapFactory = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMapFactory::class)
53  ->disableOriginalConstructor()
54  ->setMethods(['create'])
55  ->getMock();
56  $tMap = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMap::class)
57  ->disableOriginalConstructor()
58  ->getMock();
59 
60  $tMapFactory->expects(static::once())
61  ->method('create')
62  ->with(
63  [
64  'array' => [],
65  'type' => CommandInterface::class
66  ]
67  )
68  ->willReturn($tMap);
69  $tMap->expects(static::once())
70  ->method('offsetExists')
71  ->with('command')
72  ->willReturn(false);
73 
74  $pool = new CommandPool($tMapFactory, []);
75  $pool->get('command');
76  }
77 }