Skip to content

Commit 5b9b163

Browse files
committed
[Fedex] covered model source generic by unit test & removed deprecated class
1 parent 06a0dd0 commit 5b9b163

File tree

2 files changed

+100
-3
lines changed

2 files changed

+100
-3
lines changed

app/code/Magento/Fedex/Model/Source/Generic.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Fedex\Model\Source;
77

8-
class Generic implements \Magento\Framework\Option\ArrayInterface
8+
class Generic implements \Magento\Framework\Data\OptionSourceInterface
99
{
1010
/**
1111
* @var \Magento\Fedex\Model\Carrier
@@ -36,9 +36,12 @@ public function toOptionArray()
3636
{
3737
$configData = $this->_shippingFedex->getCode($this->_code);
3838
$arr = [];
39-
foreach ($configData as $code => $title) {
40-
$arr[] = ['value' => $code, 'label' => $title];
39+
if($configData) {
40+
foreach ($configData as $code => $title) {
41+
$arr[] = ['value' => $code, 'label' => $title];
42+
}
4143
}
44+
4245
return $arr;
4346
}
4447
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Magento\Fedex\Test\Unit\Model\Source;
11+
12+
use Magento\Fedex\Model\Source\Generic;
13+
use PHPUnit\Framework\TestCase;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use Magento\Fedex\Model\Carrier;
16+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
17+
18+
/**
19+
* Unit test for Magento\Fedex\Test\Unit\Model\Source\Generic
20+
*/
21+
class GenericTest extends TestCase
22+
{
23+
/**
24+
* @var Generic
25+
*/
26+
private $model;
27+
28+
/**
29+
* @var Carrier|MockObject
30+
*/
31+
private $shippingFedexMock;
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
protected function setUp(): void
37+
{
38+
$this->shippingFedexMock = $this->createMock(Carrier::class);
39+
40+
$objectManager = new ObjectManagerHelper($this);
41+
$this->model = $objectManager->getObject(
42+
Generic::class,
43+
[
44+
'shippingFedex' => $this->shippingFedexMock
45+
]
46+
);
47+
}
48+
49+
/**
50+
* Test toOptionArray
51+
*
52+
* @param string $code
53+
* @param array|false $methods
54+
* @param array $result
55+
* @return void
56+
* @dataProvider toOptionArrayDataProvider
57+
*/
58+
public function testToOptionArray($code, $methods, $result): void
59+
{
60+
$this->model->code = $code;
61+
$this->shippingFedexMock->expects($this->once())
62+
->method('getCode')
63+
->willReturn($methods);
64+
65+
$this->assertEquals($result, $this->model->toOptionArray());
66+
}
67+
68+
/**
69+
* Data provider for testToOptionArray()
70+
*
71+
* @return array
72+
*/
73+
public function toOptionArrayDataProvider(): array
74+
{
75+
return [
76+
[
77+
'method',
78+
[
79+
'FEDEX_GROUND' => __('Ground'),
80+
'FIRST_OVERNIGHT' => __('First Overnight')
81+
],
82+
[
83+
['value' => 'FEDEX_GROUND', 'label' => __('Ground')],
84+
['value' => 'FIRST_OVERNIGHT', 'label' => __('First Overnight')]
85+
]
86+
],
87+
[
88+
'',
89+
false,
90+
[]
91+
]
92+
];
93+
}
94+
}

0 commit comments

Comments
 (0)