Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConditionFactoryTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class ConditionFactoryTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $conditionFactory;
17 
22 
26  protected $objectManagerMock;
27 
28  protected function setUp()
29  {
30  $this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
31 
32  $this->objectManagerHelper = new ObjectManagerHelper($this);
33  $this->conditionFactory = $this->objectManagerHelper->getObject(
34  \Magento\Rule\Model\ConditionFactory::class,
35  [
36  'objectManager' => $this->objectManagerMock
37  ]
38  );
39  }
40 
42  {
43  $type = \Magento\Rule\Model\Condition\Combine::class;
44  $origin = $this->getMockBuilder($type)
45  ->disableOriginalConstructor()
46  ->getMock();
47 
48  $this->objectManagerMock
49  ->expects($this->once())
50  ->method('create')
51  ->with($type)
52  ->willReturn($origin);
53 
54  $this->conditionFactory->create($type);
55  }
56 
57  public function testExceptingClonedObject()
58  {
59  $type = \Magento\Rule\Model\Condition\Combine::class;
60  $origin = $this->getMockBuilder($type)
61  ->disableOriginalConstructor()
62  ->getMock();
63 
64  $this->objectManagerMock->expects($this->once())
65  ->method('create')
66  ->with($type)
67  ->willReturn($origin);
68 
69  $cloned = $this->conditionFactory->create($type);
70 
71  $this->assertNotSame($cloned, $origin);
72  }
73 
74  public function testCreateExceptionClass()
75  {
76  $type = 'type';
77  $this->objectManagerMock
78  ->expects($this->never())
79  ->method('create');
80 
81  $this->expectException(\InvalidArgumentException::class);
82  $this->expectExceptionMessage('Class does not exist');
83 
84  $this->conditionFactory->create($type);
85  }
86 
87  public function testCreateExceptionType()
88  {
89  $type = \Magento\Rule\Model\ConditionFactory::class;
90 
91  $this->objectManagerMock
92  ->expects($this->never())
93  ->method('create')
94  ->with($type)
95  ->willReturn(new \stdClass());
96  $this->expectException(\InvalidArgumentException::class);
97  $this->expectExceptionMessage('Class does not implement condition interface');
98  $this->conditionFactory->create($type);
99  }
100 }
$type
Definition: item.phtml:13