FactoryTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Persistent\Test\Unit\Model;
  7. class FactoryTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Framework\ObjectManagerInterface|PHPUnit_Framework_MockObject_MockObject
  11. */
  12. protected $_objectManagerMock;
  13. /**
  14. * @var \Magento\Persistent\Model\Factory
  15. */
  16. protected $_factory;
  17. protected function setUp()
  18. {
  19. $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  20. $this->_objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
  21. $this->_factory = $helper->getObject(
  22. \Magento\Persistent\Model\Factory::class,
  23. ['objectManager' => $this->_objectManagerMock]
  24. );
  25. }
  26. public function testCreate()
  27. {
  28. $className = 'SomeModel';
  29. $classMock = $this->getMockBuilder('SomeModel')
  30. ->disableOriginalConstructor()
  31. ->getMock();
  32. $this->_objectManagerMock->expects(
  33. $this->once()
  34. )->method(
  35. 'create'
  36. )->with(
  37. $className,
  38. []
  39. )->will(
  40. $this->returnValue($classMock)
  41. );
  42. $this->assertEquals($classMock, $this->_factory->create($className));
  43. }
  44. public function testCreateWithArguments()
  45. {
  46. $className = 'SomeModel';
  47. $data = ['param1', 'param2'];
  48. $classMock = $this->createMock('SomeModel');
  49. $this->_objectManagerMock->expects(
  50. $this->once()
  51. )->method(
  52. 'create'
  53. )->with(
  54. $className,
  55. $data
  56. )->will(
  57. $this->returnValue($classMock)
  58. );
  59. $this->assertEquals($classMock, $this->_factory->create($className, $data));
  60. }
  61. }