Skip to content

Commit c4a3c00

Browse files
committed
Cover changes with unit test
1 parent 529c46f commit c4a3c00

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Shipping\Test\Unit\Model;
7+
8+
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Shipping\Model\Carrier\AbstractCarrierInterface;
10+
use Magento\Shipping\Model\Config;
11+
use Magento\Shipping\Model\Config\Source\Allmethods;
12+
use PHPUnit\Framework\MockObject\MockObject;
13+
14+
/**
15+
* Tests for Allmethods Class
16+
*/
17+
class InfoTest extends \PHPUnit\Framework\TestCase
18+
{
19+
/**
20+
* @var ScopeConfigInterface|MockObject $scopeConfig
21+
*/
22+
private $scopeConfig;
23+
24+
/**
25+
* @var Config|MockObject $shippingConfig
26+
*/
27+
private $shippingConfig;
28+
29+
/**
30+
* @var Allmethods $allmethods
31+
*/
32+
private $allmethods;
33+
34+
/**
35+
* @var MockObject
36+
*/
37+
private $carriersMock;
38+
39+
/**
40+
* @inheritdoc
41+
*/
42+
protected function setUp()
43+
{
44+
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
45+
$this->shippingConfig = $this->createMock(Config::class);
46+
$this->carriersMock = $this->getMockBuilder(AbstractCarrierInterface::class)
47+
->setMethods(
48+
[
49+
'isActive',
50+
'getAllowedMethods'
51+
]
52+
)->getMockForAbstractClass();
53+
54+
$this->allmethods = new Allmethods(
55+
$this->scopeConfig,
56+
$this->shippingConfig
57+
);
58+
}
59+
60+
/**
61+
* Ensure that options converted correctly
62+
*
63+
* @dataProvider getCarriersMethodsProvider
64+
* @param array $expectedArray
65+
* @return void
66+
*/
67+
public function testToOptionArray(array $expectedArray): void
68+
{
69+
$expectedArray['getAllCarriers'] = [$this->carriersMock];
70+
71+
$this->shippingConfig->expects($this->once())
72+
->method('getAllCarriers')
73+
->willReturn($expectedArray['getAllCarriers']);
74+
$this->carriersMock->expects($this->once())
75+
->method('isActive')
76+
->willReturn(true);
77+
$this->carriersMock->expects($this->once())
78+
->method('getAllowedMethods')
79+
->willReturn($expectedArray['allowedMethods']);
80+
$this->assertEquals([$expectedArray['expected_result']], $this->allmethods->toOptionArray());
81+
}
82+
83+
/**
84+
* Returns providers data for test
85+
*
86+
* @return array
87+
*/
88+
public function getCarriersMethodsProvider(): array
89+
{
90+
return [
91+
[
92+
[
93+
'allowedMethods' => [null => 'method_title'],
94+
'expected_result' => [ 'value' => [], 'label' => null],
95+
'getAllCarriers' => []
96+
],
97+
[
98+
'allowedMethods' => ['method_code' => 'method_title'],
99+
'expected_result' => [ 'value' => [], 'label' => 'method_code'],
100+
'getAllCarriers' => []
101+
]
102+
103+
]
104+
];
105+
}
106+
}

0 commit comments

Comments
 (0)