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/Console/Test/Unit/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

namespace Magento\Framework\Console\Test\Unit;

use Magento\Framework\Console\Cli;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
 *  Test for Magento\Framework\Console\Cli class.
 */
class CliTest extends TestCase
{
    /**
     * @var Cli
     */
    private $cli;

    /**
     * @var InputInterface|MockObject
     */
    private $inputMock;

    /**
     * @var OutputInterface|MockObject
     */
    private $outputMock;

    /**
     * @inheritdoc
     */
    protected function setUp(): void
    {
        $this->inputMock = $this->getMockBuilder(InputInterface::class)
            ->getMockForAbstractClass();
        $this->outputMock = $this->getMockBuilder(OutputInterface::class)
            ->getMockForAbstractClass();
        $this->cli = new Cli();
    }

    /**
     * Make sure exception message is displayed and trace is logged.
     */
    public function testDoRunExceptionLogging()
    {
        $this->expectException('Exception');
        $this->expectExceptionMessage('Test message');
        $e = new \Exception('Test message');
        $this->inputMock->expects($this->once())->method('getFirstArgument')->willThrowException($e);
        $loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
        $loggerMock->expects($this->once())
            ->method('error')
            ->with($e->getMessage() . PHP_EOL . $e->getTraceAsString());
        $this->injectMock($loggerMock, 'logger');

        $this->cli->doRun($this->inputMock, $this->outputMock);
    }

    /**
     * Inject mock to Cli property.
     *
     * @param MockObject $mockObject
     * @param string $propertyName
     * @throws \ReflectionException
     */
    private function injectMock(MockObject $mockObject, string $propertyName): void
    {
        $reflection = new \ReflectionClass(Cli::class);
        $reflectionProperty = $reflection->getProperty($propertyName);
        $reflectionProperty->setAccessible(true);
        $reflectionProperty->setValue($this->cli, $mockObject);
    }
}

Spamworldpro Mini