Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ValueHandlerPoolTest.php
Go to the documentation of this file.
1 <?php
7 
10 
11 class ValueHandlerPoolTest extends \PHPUnit\Framework\TestCase
12 {
13  public function testConstructorException()
14  {
15  $this->expectException('LogicException');
16  $tMapFactory = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMapFactory::class)
17  ->disableOriginalConstructor()
18  ->setMethods(['create'])
19  ->getMock();
20 
21  $tMapFactory->expects(static::never())
22  ->method('create');
23  new ValueHandlerPool($tMapFactory, []);
24  }
25 
26  public function testGet()
27  {
28  $defaultHandler = $this->getMockBuilder(\Magento\Payment\Gateway\Config\ValueHandlerInterface::class)
29  ->disableOriginalConstructor()
30  ->getMockForAbstractClass();
31  $someValueHandler = $this->getMockBuilder(\Magento\Payment\Gateway\Config\ValueHandlerInterface::class)
32  ->disableOriginalConstructor()
33  ->getMockForAbstractClass();
34  $tMapFactory = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMapFactory::class)
35  ->disableOriginalConstructor()
36  ->setMethods(['create'])
37  ->getMock();
38  $tMap = $this->getMockBuilder(\Magento\Framework\ObjectManager\TMap::class)
39  ->disableOriginalConstructor()
40  ->getMock();
41 
42  $tMapFactory->expects(static::once())
43  ->method('create')
44  ->with(
45  [
46  'array' => [
48  \Magento\Payment\Gateway\Config\ValueHandlerInterface::class,
49  'some_value' => \Magento\Payment\Gateway\Config\ValueHandlerInterface::class
50  ],
51  'type' => ValueHandlerInterface::class
52  ]
53  )
54  ->willReturn($tMap);
55  $tMap->expects(static::exactly(3))
56  ->method('offsetExists')
57  ->willReturnMap(
58  [
60  ['some_value', true]
61  ]
62  );
63  $tMap->expects(static::exactly(3))
64  ->method('offsetGet')
65  ->willReturnMap(
66  [
67  [ValueHandlerPool::DEFAULT_HANDLER, $defaultHandler],
68  ['some_value', $someValueHandler]
69  ]
70  );
71 
72  $pool = new ValueHandlerPool(
73  $tMapFactory,
74  [
75  ValueHandlerPool::DEFAULT_HANDLER => \Magento\Payment\Gateway\Config\ValueHandlerInterface::class,
76  'some_value' => \Magento\Payment\Gateway\Config\ValueHandlerInterface::class
77  ]
78  );
79  static::assertSame($someValueHandler, $pool->get('some_value'));
80  static::assertSame($defaultHandler, $pool->get(ValueHandlerPool::DEFAULT_HANDLER));
81  static::assertSame($defaultHandler, $pool->get('no_custom_logic_required'));
82  }
83 }