Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataMapperFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
12 
13 class DataMapperFactoryTest extends \PHPUnit\Framework\TestCase
14 {
18  private $model;
19 
23  private $objectManagerMock;
24 
28  private $dataMappers;
29 
35  protected function setUp()
36  {
37  $this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class)
38  ->disableOriginalConstructor()
39  ->getMock();
40  $this->dataMappers = [
41  'product' => 'productDataMapper',
42  ];
43  $objectManager = new ObjectManagerHelper($this);
44  $this->model = $objectManager->getObject(
45  DataMapperFactory::class,
46  [
47  'objectManager' => $this->objectManagerMock,
48  'dataMappers' => $this->dataMappers
49  ]
50  );
51  }
52 
57  public function testCreateEmpty()
58  {
59  $this->model->create('');
60  }
61 
66  public function testCreateWrongType()
67  {
68  $this->model->create('wrong');
69  }
70 
75  public function testCreateFailure()
76  {
77  $this->objectManagerMock->expects($this->once())
78  ->method('create')
79  ->willReturn(new \stdClass());
80  $this->model->create('product');
81  }
82 
86  public function testCreate()
87  {
88  $this->objectManagerMock->expects($this->once())
89  ->method('create')
90  ->willReturn($this->createMock(BatchDataMapperInterface::class));
91  $this->assertInstanceOf(BatchDataMapperInterface::class, $this->model->create('product'));
92  }
93 }
$objectManager
Definition: bootstrap.php:17