Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CollectorFactoryTest.php
Go to the documentation of this file.
1 <?php
8 
14 use PHPUnit_Framework_MockObject_MockObject as MockObject;
15 use stdClass;
16 
17 class CollectorFactoryTest extends \PHPUnit\Framework\TestCase
18 {
22  private $objectManagerMock;
23 
27  private $model;
28 
32  protected function setUp()
33  {
34  $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
35  ->getMockForAbstractClass();
36 
37  $this->model = new CollectorFactory(
38  $this->objectManagerMock,
39  [
40  CollectorFactory::TYPE_SIMPLE => SimpleCollector::class,
41  CollectorFactory::TYPE_INTERACTIVE => InteractiveCollector::class,
42  'wrongType' => stdClass::class,
43  ]
44  );
45  }
46 
47  public function testCreate()
48  {
49  $collectorMock = $this->getMockBuilder(CollectorInterface::class)
50  ->getMockForAbstractClass();
51  $this->objectManagerMock->expects($this->once())
52  ->method('create')
53  ->with(SimpleCollector::class)
54  ->willReturn($collectorMock);
55 
56  $this->assertInstanceOf(
57  CollectorInterface::class,
58  $this->model->create(CollectorFactory::TYPE_SIMPLE)
59  );
60  }
61 
66  public function testCreateNonExisted()
67  {
68  $this->model->create('dummyType');
69  }
70 
76  {
77  $type = 'wrongType';
78  $this->objectManagerMock->expects($this->once())
79  ->method('create')
80  ->with(stdClass::class)
81  ->willReturn(new stdClass());
82 
83  $this->model->create($type);
84  }
85 }
$type
Definition: item.phtml:13