Spamworldpro Mini Shell
Spamworldpro


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/dev/tests/integration/testsuite/Magento/Framework/Model/Entity/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/dev/tests/integration/testsuite/Magento/Framework/Model/Entity/HydratorTest.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Framework\Model\Entity;

class HydratorTest extends \PHPUnit\Framework\TestCase
{
    const CUSTOM_ATTRIBUTE_CODE = 'description';

    /**
     * @var \Magento\Framework\ObjectManagerInterface
     */
    private $objectManager;

    protected function setUp(): void
    {
        $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
    }

    public function testExtractAndHydrate()
    {
        /** @var \Magento\Framework\EntityManager\Hydrator $hydrator */
        $hydrator = $this->objectManager->create(\Magento\Framework\EntityManager\Hydrator::class);

        /** @var \Magento\Framework\Api\AttributeInterface $customAttribute */
        $customAttribute = $this->objectManager->create(\Magento\Framework\Api\AttributeInterface::class);
        $customAttribute->setAttributeCode(self::CUSTOM_ATTRIBUTE_CODE)
            ->setValue('Product description');

        /** @var \Magento\CatalogInventory\Api\Data\StockItemInterface $extensionAttribute */
        $stockItem = $this->objectManager->create(
            \Magento\CatalogInventory\Api\Data\StockItemInterface::class
        );
        $stockItem->setProductId(1)
            ->setQty(100);

        /** @var \Magento\Catalog\Api\Data\ProductExtension $productExtension */
        $productExtension = $this->objectManager->create(\Magento\Catalog\Api\Data\ProductExtension::class);
        $productExtension->setStockItem($stockItem);

        /** @var \Magento\Catalog\Api\Data\ProductLinkInterface $productLink */
        $productLink = $this->objectManager->create(\Magento\Catalog\Api\Data\ProductLinkInterface::class);
        $productLink->setSku('sku')
            ->setLinkedProductSku('linked-sku');

        /** @var \Magento\Catalog\Api\Data\ProductInterface $product */
        $product = $this->objectManager->create(\Magento\Catalog\Api\Data\ProductInterface::class);
        $product->setSku('sku')
            ->setName('Product name')
            ->setCustomAttributes([self::CUSTOM_ATTRIBUTE_CODE => $customAttribute])
            ->setExtensionAttributes($productExtension)
            ->setProductLinks([$productLink]);

        $productData = $hydrator->extract($product);
        /** @var \Magento\Catalog\Api\Data\ProductInterface $newProduct */
        $newProduct = $this->objectManager->create(\Magento\Catalog\Api\Data\ProductInterface::class);
        $newProduct = $hydrator->hydrate($newProduct, $productData);
        $newProductData = $hydrator->extract($newProduct);

        $this->assertEquals($productData, $newProductData);
    }
}

Spamworldpro Mini