Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CopyConstructorFactoryTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Catalog\Model\Product\CopyConstructorFactory;
9 
10 class CopyConstructorFactoryTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_model;
16 
21 
22  protected function setUp()
23  {
24  $this->_objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
25  $this->_model = new CopyConstructorFactory($this->_objectManagerMock);
26  }
27 
28  public function testCreateWithInvalidType()
29  {
30  $this->expectException('\InvalidArgumentException');
31  $this->expectExceptionMessage(
32  'Magento\Framework\DataObject does not implement \Magento\Catalog\Model\Product\CopyConstructorInterface'
33  );
34  $this->_objectManagerMock->expects($this->never())->method('create');
35  $this->_model->create(\Magento\Framework\DataObject::class);
36  }
37 
38  public function testCreateWithValidType()
39  {
40  $this->_objectManagerMock->expects(
41  $this->once()
42  )->method(
43  'create'
44  )->with(
45  \Magento\Catalog\Model\Product\CopyConstructor\Composite::class
46  )->will(
47  $this->returnValue('object')
48  );
49  $this->assertEquals(
50  'object',
51  $this->_model->create(\Magento\Catalog\Model\Product\CopyConstructor\Composite::class)
52  );
53  }
54 }