ExtensionAttributesFactoryTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Api;
  7. class ExtensionAttributesFactoryTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /** @var \Magento\Framework\Api\ExtensionAttributesFactory */
  10. private $factory;
  11. protected function setUp()
  12. {
  13. /** @var \Magento\Framework\ObjectManagerInterface */
  14. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  15. $this->factory = $objectManager->create(
  16. \Magento\Framework\Api\ExtensionAttributesFactory::class,
  17. ['objectManager' => $objectManager]
  18. );
  19. }
  20. /**
  21. * @expectedException \LogicException
  22. */
  23. public function testCreateThrowExceptionIfInterfaceNotImplemented()
  24. {
  25. $this->factory->create(\Magento\Framework\Api\ExtensionAttributesFactoryTest::class);
  26. }
  27. /**
  28. * @expectedException \LogicException
  29. */
  30. public function testCreateThrowExceptionIfInterfaceNotOverridden()
  31. {
  32. $this->factory->create(\Magento\TestModuleExtensionAttributes\Model\Data\FakeExtensibleOne::class);
  33. }
  34. /**
  35. * @expectedException \LogicException
  36. */
  37. public function testCreateThrowExceptionIfReturnIsIncorrect()
  38. {
  39. $this->factory->create(\Magento\TestModuleExtensionAttributes\Model\Data\FakeExtensibleTwo::class);
  40. }
  41. public function testCreate()
  42. {
  43. $this->assertInstanceOf(
  44. \Magento\TestModuleExtensionAttributes\Api\Data\FakeRegionExtension::class,
  45. $this->factory->create(\Magento\TestModuleExtensionAttributes\Model\Data\FakeRegion::class)
  46. );
  47. }
  48. public function testCreateWithLogicException()
  49. {
  50. $this->expectException('LogicException');
  51. $this->expectExceptionMessage(
  52. "Class 'Magento\\Framework\\Api\\ExtensionAttributesFactoryTest' must implement an interface, "
  53. . "which extends from 'Magento\\Framework\\Api\\ExtensibleDataInterface'"
  54. );
  55. $this->factory->create(get_class($this));
  56. }
  57. }