Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
QueryModifierFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
12 
13 class QueryModifierFactoryTest extends \PHPUnit\Framework\TestCase
14 {
18  private $objectManager;
19 
23  private $queryModifierFactory;
24 
28  private $objectManagerMock;
29 
33  private $inQueryModifierMock;
34 
35  protected function setUp()
36  {
37  $this->objectManager = new ObjectManager($this);
38  $this->objectManagerMock = $this->createMock(ObjectManagerInterface::class);
39  $this->inQueryModifierMock = $this->createMock(InQueryModifier::class);
40  }
41 
42  public function testCreate()
43  {
44  $params = ['foo' => 'bar'];
45  $this->queryModifierFactory = $this->objectManager->getObject(
46  QueryModifierFactory::class,
47  [
48  'objectManager' => $this->objectManagerMock,
49  'queryModifiers' => [
50  'in' => InQueryModifier::class
51  ]
52  ]
53  );
54  $this->objectManagerMock->expects($this->once())
55  ->method('create')
56  ->with(
57  InQueryModifier::class,
58  $params
59  )
60  ->willReturn($this->inQueryModifierMock);
61  $this->queryModifierFactory->create('in', $params);
62  }
63 
68  {
69  $params = ['foo' => 'bar'];
70  $this->queryModifierFactory = $this->objectManager->getObject(
71  QueryModifierFactory::class,
72  [
73  'objectManager' => $this->objectManagerMock,
74  'queryModifiers' => []
75  ]
76  );
77  $this->objectManagerMock->expects($this->never())
78  ->method('create');
79  $this->queryModifierFactory->create('in', $params);
80  }
81 
86  {
87  $params = ['foo' => 'bar'];
88  $this->queryModifierFactory = $this->objectManager->getObject(
89  QueryModifierFactory::class,
90  [
91  'objectManager' => $this->objectManagerMock,
92  'queryModifiers' => [
93  'in' => \stdClass::class
94  ]
95  ]
96  );
97  $this->objectManagerMock->expects($this->once())
98  ->method('create')
99  ->with(
100  \stdClass::class,
101  $params
102  )
103  ->willReturn(new \stdClass());
104  $this->queryModifierFactory->create('in', $params);
105  }
106 }
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18