Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Test for Magento\Sitemap\Model\Config\Backend\Priority #26430

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Sitemap\Test\Unit\Model\Config\Backend;

use Magento\Sitemap\Model\Config\Backend\Priority;
use PHPUnit\Framework\MockObject\MockObject;

/**
* Tests for @see Priority
*/
class PriorityTest extends \PHPUnit\Framework\TestCase
{
/**
* @var Priority|MockObject
*/
private $priorityMock;

/**
* @inheritDoc
*/
protected function setUp()
{
$this->priorityMock = $this->getMockBuilder(Priority::class)
->disableOriginalConstructor()
->setMethods(['getValue'])
->getMock();
}

/**
* Verify before save in chainable
*
* @param string $value
* @dataProvider dataProviderTestBeforeSaveValueCorrect
*/
public function testBeforeSaveIsChainable($value)
{
$this->priorityMock->expects($this->once())
->method('getValue')
->willReturn($value);

$this->assertSame($this->priorityMock, $this->priorityMock->beforeSave());
}

/**
* Verify before save value out of range
*
* @param string $value
* @dataProvider dataProviderTestBeforeSaveValueOutOfRange
*/
public function testBeforeSaveValueOutOfRange($value)
{
$this->priorityMock->expects($this->once())
->method('getValue')
->willReturn($value);

$this->expectException(\Exception::class);
$this->expectExceptionMessage('The priority must be between 0 and 1.');

$this->priorityMock->beforeSave();
}

/**
* Data provider
*
* @return array
*/
public function dataProviderTestBeforeSaveValueCorrect()
{
return [
['0'], ['0.0'], ['0.5'], ['1']
];
}

/**
* Data provider
*
* @return array
*/
public function dataProviderTestBeforeSaveValueOutOfRange()
{
return [
['-1'], ['2'], ['nan']
];
}
}