Skip to content

Commit 74ad5dd

Browse files
committed
Unit Test for Magento\Sitemap\Model\Config\Backend\Priority
1 parent 3e4db87 commit 74ad5dd

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sitemap\Test\Unit\Model\Config\Backend;
8+
9+
use Magento\Sitemap\Model\Config\Backend\Priority;
10+
use PHPUnit\Framework\MockObject\MockObject;
11+
12+
/**
13+
* Tests for @see Priority
14+
*/
15+
class PriorityTest extends \PHPUnit\Framework\TestCase
16+
{
17+
/**
18+
* @var Priority|MockObject
19+
*/
20+
private $priorityMock;
21+
22+
/**
23+
* @inheritDoc
24+
*/
25+
protected function setUp()
26+
{
27+
$this->priorityMock = $this->getMockBuilder(Priority::class)
28+
->disableOriginalConstructor()
29+
->setMethods(['getValue'])
30+
->getMock();
31+
}
32+
33+
/**
34+
* @param string $value
35+
* @dataProvider dataProviderTestBeforeSaveValueCorrect
36+
*/
37+
public function testBeforeSave($value)
38+
{
39+
$this->priorityMock->expects($this->once())
40+
->method('getValue')
41+
->willReturn($value);
42+
43+
$this->assertSame($this->priorityMock, $this->priorityMock->beforeSave());
44+
}
45+
46+
/**
47+
* @param string $value
48+
* @dataProvider dataProviderTestBeforeSaveValueOutOfRange
49+
*/
50+
public function testBeforeSaveValueOutOfRange($value)
51+
{
52+
$this->priorityMock->expects($this->once())
53+
->method('getValue')
54+
->willReturn($value);
55+
56+
$this->expectException(\Exception::class);
57+
$this->expectExceptionMessage('The priority must be between 0 and 1.');
58+
59+
$this->priorityMock->beforeSave();
60+
}
61+
62+
/**
63+
* @return array
64+
*/
65+
public function dataProviderTestBeforeSaveValueCorrect()
66+
{
67+
return [
68+
['0'], ['0.0'], ['0.5'], ['1']
69+
];
70+
}
71+
72+
/**
73+
* @return array
74+
*/
75+
public function dataProviderTestBeforeSaveValueOutOfRange()
76+
{
77+
return [
78+
['-1'], ['2'], ['nan']
79+
];
80+
}
81+
}

0 commit comments

Comments
 (0)