AttributeFactoryTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Eav\Test\Unit\Model;
  7. class AttributeFactoryTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Eav\Model\AttributeFactory
  11. */
  12. protected $_factory;
  13. /**
  14. * @var array
  15. */
  16. protected $_arguments = ['test1', 'test2'];
  17. /**
  18. * @var string
  19. */
  20. protected $_className = 'Test_Class';
  21. protected function setUp()
  22. {
  23. /** @var $objectManagerMock \Magento\Framework\ObjectManagerInterface */
  24. $objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
  25. $objectManagerMock->expects(
  26. $this->any()
  27. )->method(
  28. 'create'
  29. )->will(
  30. $this->returnCallback([$this, 'getModelInstance'])
  31. );
  32. $this->_factory = new \Magento\Eav\Model\AttributeFactory($objectManagerMock);
  33. }
  34. protected function tearDown()
  35. {
  36. unset($this->_factory);
  37. }
  38. /**
  39. * @covers \Magento\Eav\Model\AttributeFactory::createAttribute
  40. */
  41. public function testCreateAttribute()
  42. {
  43. $this->assertEquals($this->_className, $this->_factory->createAttribute($this->_className, $this->_arguments));
  44. }
  45. /**
  46. * @param $className
  47. * @param $arguments
  48. * @return mixed
  49. */
  50. public function getModelInstance($className, $arguments)
  51. {
  52. $this->assertInternalType('array', $arguments);
  53. $this->assertArrayHasKey('data', $arguments);
  54. $this->assertEquals($this->_arguments, $arguments['data']);
  55. return $className;
  56. }
  57. }