1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Meanbee\MagentoRoyalmail\Test\Unit\Model\Config\Source; |
4
|
|
|
|
5
|
|
|
use Meanbee\MagentoRoyalmail\Model\Config\Source\RoundingRule; |
6
|
|
|
use Meanbee\MagentoRoyalmail\Model\Rounder; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class RoundingRuleTest |
10
|
|
|
*/ |
11
|
|
|
class RoundingRuleTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var Rounder|\PHPUnit_Framework_MockObject_MockObject |
15
|
|
|
*/ |
16
|
|
|
protected $rounder; |
17
|
|
|
/** |
18
|
|
|
* @var RoundingRule|\PHPUnit_Framework_MockObject_MockObject |
19
|
|
|
*/ |
20
|
|
|
protected $roundingRule; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @inheritdoc |
24
|
|
|
*/ |
25
|
|
|
protected function setUp() |
26
|
|
|
{ |
27
|
|
|
$this->rounder = $this->getMockBuilder('Meanbee\MagentoRoyalmail\Model\Rounder') |
28
|
|
|
->disableOriginalConstructor() |
29
|
|
|
->getMock(); |
30
|
|
|
|
31
|
|
|
$this->roundingRule = new RoundingRule($this->rounder); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testToOptionArray() |
35
|
|
|
{ |
36
|
|
|
$rules = ['none' => 'No rounding performed']; |
37
|
|
|
$this->mockGetRoundingRules($rules); |
38
|
|
|
|
39
|
|
|
$options = $this->roundingRule->toOptionArray(); |
40
|
|
|
$this->assertEquals(1, count($options)); |
41
|
|
|
|
42
|
|
|
$option = array_pop($options); |
43
|
|
|
$this->assertEquals('none', $option['value']); |
44
|
|
|
$this->assertEquals('No rounding performed', $option['label']); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testToArray() |
48
|
|
|
{ |
49
|
|
|
$rules = ['none' => 'No rounding performed']; |
50
|
|
|
$this->mockGetRoundingRules($rules); |
51
|
|
|
|
52
|
|
|
$options = $this->roundingRule->toArray(); |
53
|
|
|
|
54
|
|
View Code Duplication |
foreach ($options as $option) { |
|
|
|
|
55
|
|
|
$this->assertInternalType('array', $option); |
56
|
|
|
foreach ($option as $key => $value) { |
57
|
|
|
$this->assertInternalType('string', $key); |
58
|
|
|
$this->assertInstanceOf(\Magento\Framework\Phrase::class, $value); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
protected function mockGetRoundingRules($rules) |
65
|
|
|
{ |
66
|
|
|
$this->rounder |
67
|
|
|
->expects($this->once()) |
68
|
|
|
->method('getRoundingRules') |
69
|
|
|
->willReturn($rules); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.