Skip to content

Commit

Permalink
Covered case when simple product is being validated
Browse files Browse the repository at this point in the history
  • Loading branch information
novikor committed Aug 9, 2018
1 parent 90ff989 commit c52e0e8
Showing 1 changed file with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ private function createValidator(): SalesRuleProduct
->setMethods(['loadAllAttributes', 'getConnection', 'getTable'])
->getMock();
$productMock->expects($this->any())
->method('loadAllAttributes')
->willReturn($attributeLoaderInterfaceMock);
->method('loadAllAttributes')
->willReturn($attributeLoaderInterfaceMock);
/** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
$collectionMock = $this->getMockBuilder(Collection::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -195,4 +195,35 @@ private function createProductMock(): \PHPUnit_Framework_MockObject_MockObject

return $productMock;
}

public function testChildIsNotUsedForValidation()
{
$simpleProductMock = $this->createProductMock();
$simpleProductMock
->expects($this->any())
->method('getTypeId')
->willReturn(Type::TYPE_SIMPLE);
$simpleProductMock
->expects($this->any())
->method('hasData')
->with($this->equalTo('special_price'))
->willReturn(true);

/* @var AbstractItem|\PHPUnit_Framework_MockObject_MockObject $item */
$item = $this->getMockBuilder(AbstractItem::class)
->disableOriginalConstructor()
->setMethods(['setProduct', 'getProduct'])
->getMockForAbstractClass();
$item->expects($this->any())
->method('getProduct')
->willReturn($simpleProductMock);

$item->expects($this->once())
->method('setProduct')
->with($this->identicalTo($simpleProductMock));

$this->validator->setAttribute('special_price');

$this->validatorPlugin->beforeValidate($this->validator, $item);
}
}

0 comments on commit c52e0e8

Please sign in to comment.