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