mirror of
https://github.com/bdnugget/magento2.git
synced 2026-11-07 09:17:35 +00:00
80 lines
1.9 KiB
PHP
80 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Copyright © Magento, Inc. All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace Magento\Persistent\Test\Unit\Model;
|
|
|
|
use Magento\Framework\ObjectManagerInterface;
|
|
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
|
|
use Magento\Persistent\Model\Factory;
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class FactoryTest extends TestCase
|
|
{
|
|
/**
|
|
* @var ObjectManagerInterface|MockObject
|
|
*/
|
|
protected $_objectManagerMock;
|
|
|
|
/**
|
|
* @var Factory
|
|
*/
|
|
protected $_factory;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$helper = new ObjectManager($this);
|
|
|
|
$this->_objectManagerMock = $this->getMockForAbstractClass(ObjectManagerInterface::class);
|
|
$this->_factory = $helper->getObject(
|
|
Factory::class,
|
|
['objectManager' => $this->_objectManagerMock]
|
|
);
|
|
}
|
|
|
|
public function testCreate()
|
|
{
|
|
$className = 'SomeModel';
|
|
|
|
$classMock = $this->getMockBuilder('SomeModel')
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$this->_objectManagerMock->expects(
|
|
$this->once()
|
|
)->method(
|
|
'create'
|
|
)->with(
|
|
$className,
|
|
[]
|
|
)->willReturn(
|
|
$classMock
|
|
);
|
|
|
|
$this->assertEquals($classMock, $this->_factory->create($className));
|
|
}
|
|
|
|
public function testCreateWithArguments()
|
|
{
|
|
$className = 'SomeModel';
|
|
$data = ['param1', 'param2'];
|
|
|
|
$classMock = $this->createMock('SomeModel');
|
|
$this->_objectManagerMock->expects(
|
|
$this->once()
|
|
)->method(
|
|
'create'
|
|
)->with(
|
|
$className,
|
|
$data
|
|
)->willReturn(
|
|
$classMock
|
|
);
|
|
|
|
$this->assertEquals($classMock, $this->_factory->create($className, $data));
|
|
}
|
|
}
|