ExtensionAttributesGenerationTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Framework\Api\ExtensionAttribute;
  8. use Magento\Catalog\Api\Data\ProductInterface;
  9. use Magento\Catalog\Api\Data\ProductExtensionInterface;
  10. use Magento\Customer\Api\Data\CustomerInterface;
  11. use Magento\Customer\Api\Data\CustomerExtensionInterface;
  12. /**
  13. * Class to test the automatic generation of extension attributes object.
  14. */
  15. class ExtensionAttributesGenerationTest extends \PHPUnit\Framework\TestCase
  16. {
  17. /**
  18. * Test extension attributes generation for extensible models.
  19. *
  20. * Make sure that extension attributes object is not empty after instantiation
  21. * of objects inherited from @see \Magento\Framework\Model\AbstractExtensibleModel.
  22. *
  23. * In addition, verify that empty objects are not generated for complex extension attributes.
  24. */
  25. public function testAttributeObjectGenerationForExtensibleModel()
  26. {
  27. /** @var \Magento\Framework\ObjectManagerInterface */
  28. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  29. /** @var ProductInterface $product */
  30. $product = $objectManager->get(ProductInterface::class);
  31. $extensionAttributes = $product->getExtensionAttributes();
  32. $this->assertInstanceOf(ProductExtensionInterface::class, $extensionAttributes);
  33. $stockItemExtensionAttribute = $extensionAttributes->getStockItem();
  34. $this->assertNull($stockItemExtensionAttribute);
  35. }
  36. /**
  37. * Test extension attributes generation for extensible objects.
  38. *
  39. * Make sure that extension attributes object is not empty after instantiation
  40. * of objects inherited from @see \Magento\Framework\Api\AbstractExtensibleObject
  41. */
  42. public function testAttributeObjectGenerationForExtensibleObject()
  43. {
  44. /** @var \Magento\Framework\ObjectManagerInterface */
  45. $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  46. /** @var CustomerInterface $customer */
  47. $customer = $objectManager->get(CustomerInterface::class);
  48. $extensionAttributes = $customer->getExtensionAttributes();
  49. $this->assertInstanceOf(CustomerExtensionInterface::class, $extensionAttributes);
  50. }
  51. }