-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-3065: [Backport] Sales: add missing unit tests for model classes
- Loading branch information
Showing
2 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
app/code/Magento/Sales/Test/Unit/Model/ValidatorResultMergerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Sales\Test\Unit\Model; | ||
|
||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Sales\Model\ValidatorResultInterface; | ||
use Magento\Sales\Model\ValidatorResultInterfaceFactory; | ||
use Magento\Sales\Model\ValidatorResultMerger; | ||
|
||
/** | ||
* @covers \Magento\Sales\Model\ValidatorResultMerger | ||
*/ | ||
class ValidatorResultMergerTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* Testable Object | ||
* | ||
* @var ValidatorResultMerger | ||
*/ | ||
private $validatorResultMerger; | ||
|
||
/** | ||
* Object Manager | ||
* | ||
* @var ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var ValidatorResultInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $validatorResultFactoryMock; | ||
|
||
/** | ||
* Set Up | ||
* | ||
* @return void | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->validatorResultFactoryMock = $this->getMockBuilder(ValidatorResultInterfaceFactory::class) | ||
->setMethods(['create'])->disableOriginalConstructor()->getMock(); | ||
$this->objectManager = new ObjectManager($this); | ||
$this->validatorResultMerger = $this->objectManager->getObject( | ||
ValidatorResultMerger::class, | ||
[ | ||
'validatorResultInterfaceFactory' => $this->validatorResultFactoryMock, | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Test merge method | ||
* | ||
* @return void | ||
*/ | ||
public function testMerge() | ||
{ | ||
$validatorResultMock = $this->createMock(ValidatorResultInterface::class); | ||
$validationResult = $this->createMock(ValidatorResultInterface::class); | ||
$cmValidationResult = $this->createMock(ValidatorResultInterface::class); | ||
$validationMessages = [['test04', 'test05'], ['test06']]; | ||
$this->validatorResultFactoryMock->expects($this->once())->method('create') | ||
->willReturn($validatorResultMock); | ||
$validationResult->expects($this->once())->method('getMessages')->willReturn(['test01', 'test02']); | ||
$cmValidationResult->expects($this->once())->method('getMessages')->willReturn(['test03']); | ||
|
||
$validatorResultMock->expects($this->at(0))->method('addMessage')->with('test01'); | ||
$validatorResultMock->expects($this->at(1))->method('addMessage')->with('test02'); | ||
$validatorResultMock->expects($this->at(2))->method('addMessage')->with('test03'); | ||
$validatorResultMock->expects($this->at(3))->method('addMessage')->with('test04'); | ||
$validatorResultMock->expects($this->at(4))->method('addMessage')->with('test05'); | ||
$validatorResultMock->expects($this->at(5))->method('addMessage')->with('test06'); | ||
$expected = $validatorResultMock; | ||
$actual = $this->validatorResultMerger->merge( | ||
$validationResult, | ||
$cmValidationResult, | ||
...$validationMessages | ||
); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
app/code/Magento/Sales/Test/Unit/Model/ValidatorResultTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Sales\Test\Unit\Model; | ||
|
||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Sales\Model\ValidatorResult; | ||
|
||
/** | ||
* @covers \Magento\Sales\Model\ValidatorResult | ||
*/ | ||
class ValidatorResultTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* Testable Object | ||
* | ||
* @var ValidatorResult | ||
*/ | ||
private $validatorResult; | ||
|
||
/** | ||
* Object Manager | ||
* | ||
* @var ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* Set Up | ||
* | ||
* @return void | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->objectManager = new ObjectManager($this); | ||
$this->validatorResult = $this->objectManager->getObject(ValidatorResult::class); | ||
} | ||
|
||
/** | ||
* Test addMessage method | ||
* | ||
* @return void | ||
*/ | ||
public function testAddMessages() | ||
{ | ||
$messageFirst = 'Sample message 01.'; | ||
$messageSecond = 'Sample messages 02.'; | ||
$messageThird = 'Sample messages 03.'; | ||
$expected = [$messageFirst, $messageSecond, $messageThird]; | ||
$this->validatorResult->addMessage($messageFirst); | ||
$this->validatorResult->addMessage($messageSecond); | ||
$this->validatorResult->addMessage($messageThird); | ||
$actual = $this->validatorResult->getMessages(); | ||
$this->assertEquals($expected, $actual); | ||
} | ||
|
||
/** | ||
* Test hasMessages method | ||
* | ||
* @return void | ||
*/ | ||
public function testHasMessages() | ||
{ | ||
$this->assertFalse($this->validatorResult->hasMessages()); | ||
$messageFirst = 'Sample message 01.'; | ||
$messageSecond = 'Sample messages 02.'; | ||
$this->validatorResult->addMessage($messageFirst); | ||
$this->validatorResult->addMessage($messageSecond); | ||
$this->assertTrue($this->validatorResult->hasMessages()); | ||
} | ||
} |