forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add Documentation - phpcs fixes - Impelement phpunit test for ValidatorChain
- Loading branch information
larsroettig
committed
Oct 3, 2017
1 parent
0e48a30
commit 8dcbe34
Showing
7 changed files
with
145 additions
and
12 deletions.
There are no files selected for viewing
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
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
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
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
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
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
127 changes: 127 additions & 0 deletions
127
app/code/Magento/InventoryImportExport/Test/Unit/Model/ValidatorChainTest.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,127 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Inventory\Test\Unit\Model; | ||
|
||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Framework\Validation\ValidationResultFactory; | ||
use Magento\InventoryImportExport\Model\Import\Validator\ValidatorChain; | ||
use Magento\InventoryImportExport\Model\Import\Validator\ValidatorInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ValidatorChainTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @var ValidatorInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $qtyValidator; | ||
|
||
/** | ||
* @var ValidatorInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $skuValidator; | ||
|
||
/** | ||
* @var ValidationResultFactory|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $validationResultFactory; | ||
|
||
/** | ||
* @var ValidatorChain | ||
*/ | ||
private $validatorChain; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->validationResultFactory = $this->getMockBuilder(ValidationResultFactory::class)->getMock(); | ||
$this->qtyValidator = $this->getMockBuilder(ValidatorInterface::class)->getMock(); | ||
$this->skuValidator = $this->getMockBuilder(ValidatorInterface::class)->getMock(); | ||
} | ||
|
||
public function testValidateWithOutValidators() | ||
{ | ||
$emptyValidatorResult = $this->createMock(\Magento\Framework\Validation\ValidationResult::class); | ||
$this->validationResultFactory->expects($this->once()) | ||
->method('create') | ||
->with(['errors' =>[]]) | ||
->willReturn($emptyValidatorResult); | ||
|
||
$this->validatorChain = (new ObjectManager($this))->getObject( | ||
ValidatorChain::class, | ||
[ | ||
'validationResultFactory' => $this->validationResultFactory, | ||
'validators' => [] | ||
] | ||
); | ||
|
||
|
||
$result = $this->validatorChain->validate([], 1); | ||
$this->assertEquals($emptyValidatorResult, $result); | ||
} | ||
|
||
public function testValidateWithOutErros() | ||
{ | ||
$emptyValidatorResult = $this->createMock(\Magento\Framework\Validation\ValidationResult::class); | ||
$emptyValidatorResult->expects($this->once())->method('isValid') | ||
->willReturn(true); | ||
|
||
$this->validationResultFactory->expects($this->once()) | ||
->method('create') | ||
->with(['errors' => []]) | ||
->willReturn($emptyValidatorResult); | ||
|
||
$this->qtyValidator->method('validate') | ||
->willReturn($emptyValidatorResult); | ||
|
||
$this->validatorChain = (new ObjectManager($this))->getObject( | ||
ValidatorChain::class, | ||
[ | ||
'validationResultFactory' => $this->validationResultFactory, | ||
'validators' => [$this->qtyValidator] | ||
] | ||
); | ||
|
||
$result = $this->validatorChain->validate([], 1); | ||
$this->assertEquals($emptyValidatorResult, $result); | ||
} | ||
|
||
|
||
public function testValidateWithErros() | ||
{ | ||
$validatorResult = $this->createMock(\Magento\Framework\Validation\ValidationResult::class); | ||
|
||
$validatorResult->expects($this->once())->method('isValid') | ||
->willReturn(false); | ||
|
||
$validatorResult->expects($this->once()) | ||
->method('getErrors') | ||
->willReturn(['Qty can not negative', 'Additional error']); | ||
|
||
$this->qtyValidator->expects($this->once())->method('validate') | ||
->willReturn($validatorResult); | ||
|
||
$this->validationResultFactory->expects($this->once()) | ||
->method('create') | ||
->with(['errors' => ['Qty can not negative', 'Additional error']]) | ||
->willReturn($validatorResult); | ||
|
||
|
||
$this->validatorChain = (new ObjectManager($this))->getObject( | ||
ValidatorChain::class, | ||
[ | ||
'validationResultFactory' => $this->validationResultFactory, | ||
'validators' => [$this->qtyValidator] | ||
] | ||
); | ||
|
||
$result = $this->validatorChain->validate([-1], 1); | ||
$this->assertEquals($validatorResult, $result); | ||
} | ||
} |