Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
QueryResolverTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class QueryResolverTest extends \PHPUnit\Framework\TestCase
12 {
16  private $quoteResolver;
17 
21  private $configMock;
22 
26  private $cacheMock;
27 
31  private $serializer;
32 
33  protected function setUp()
34  {
35  $this->configMock = $this->createMock(\Magento\Framework\App\ResourceConnection\ConfigInterface::class);
36  $this->cacheMock = $this->createMock(\Magento\Framework\Config\CacheInterface::class);
37  $this->serializer = $this->getMockForAbstractClass(SerializerInterface::class);
38  $this->quoteResolver = new \Magento\Quote\Model\QueryResolver(
39  $this->configMock,
40  $this->cacheMock,
41  'connection_config_cache',
42  $this->serializer
43  );
44  }
45 
47  {
48  $serializedData = '{"checkout":true}';
49  $data = ['checkout' => true];
50  $this->cacheMock
51  ->expects($this->once())
52  ->method('load')
53  ->with('connection_config_cache')
54  ->willReturn($serializedData);
55  $this->serializer->expects($this->once())
56  ->method('unserialize')
57  ->with($serializedData)
58  ->willReturn($data);
59  $this->assertTrue($this->quoteResolver->isSingleQuery());
60  }
61 
68  public function testIsSingleQueryWhenDataNotCached($connectionName, $isSingleQuery)
69  {
70  $data = ['checkout' => $isSingleQuery];
71  $serializedData = '{"checkout":true}';
72  $this->cacheMock
73  ->expects($this->once())
74  ->method('load')
75  ->with('connection_config_cache')
76  ->willReturn(false);
77  $this->serializer->expects($this->never())
78  ->method('unserialize');
79  $this->configMock
80  ->expects($this->once())
81  ->method('getConnectionName')
82  ->with('checkout_setup')
83  ->willReturn($connectionName);
84  $this->serializer->expects($this->once())
85  ->method('serialize')
86  ->with($data)
87  ->willReturn($serializedData);
88  $this->cacheMock
89  ->expects($this->once())
90  ->method('save')
91  ->with($serializedData, 'connection_config_cache', []);
92  $this->assertEquals($isSingleQuery, $this->quoteResolver->isSingleQuery());
93  }
94 
99  {
100  return [
101  ['default', true],
102  ['checkout', false],
103  ];
104  }
105 }
testIsSingleQueryWhenDataNotCached($connectionName, $isSingleQuery)