Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
FactoryTest.php
Go to the documentation of this file.
1 <?php
7 
8 class FactoryTest extends \PHPUnit\Framework\TestCase
9 {
14 
18  protected $_factory;
19 
20  protected function setUp()
21  {
22  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
23 
24  $this->_objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
25  $this->_factory = $helper->getObject(
26  \Magento\Persistent\Model\Factory::class,
27  ['objectManager' => $this->_objectManagerMock]
28  );
29  }
30 
31  public function testCreate()
32  {
33  $className = 'SomeModel';
34 
35  $classMock = $this->getMockBuilder('SomeModel')
36  ->disableOriginalConstructor()
37  ->getMock();
38  $this->_objectManagerMock->expects(
39  $this->once()
40  )->method(
41  'create'
42  )->with(
43  $className,
44  []
45  )->will(
46  $this->returnValue($classMock)
47  );
48 
49  $this->assertEquals($classMock, $this->_factory->create($className));
50  }
51 
52  public function testCreateWithArguments()
53  {
54  $className = 'SomeModel';
55  $data = ['param1', 'param2'];
56 
57  $classMock = $this->createMock('SomeModel');
58  $this->_objectManagerMock->expects(
59  $this->once()
60  )->method(
61  'create'
62  )->with(
63  $className,
64  $data
65  )->will(
66  $this->returnValue($classMock)
67  );
68 
69  $this->assertEquals($classMock, $this->_factory->create($className, $data));
70  }
71 }
$helper
Definition: iframe.phtml:13
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31