![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-persistent/Test/Unit/Model/ |
<?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)); } }