33 $this->ruleResourceMock = $this->createMock(\
Magento\CatalogRule\Model\
ResourceModel\Rule::class);
34 $this->ruleFactoryMock = $this->createPartialMock(\
Magento\CatalogRule\Model\RuleFactory::class, [
'create']);
35 $this->ruleMock = $this->createMock(\
Magento\CatalogRule\Model\Rule::class);
36 $this->repository = new \Magento\CatalogRule\Model\CatalogRuleRepository(
37 $this->ruleResourceMock,
38 $this->ruleFactoryMock
44 $this->ruleMock->expects($this->once())->method(
'getRuleId')->willReturn(
null);
45 $this->ruleMock->expects($this->once())->method(
'getId')->willReturn(1);
46 $this->ruleResourceMock->expects($this->once())->method(
'save')->with($this->ruleMock);
47 $this->assertEquals($this->ruleMock, $this->repository->save($this->ruleMock));
54 $this->ruleMock->expects($this->once())->method(
'getData')->willReturn(
$ruleData);
56 $this->ruleMock->expects($this->exactly(2))->method(
'getRuleId')->willReturn(
$ruleId);
58 $this->ruleFactoryMock->expects($this->once())->method(
'create')->willReturn(
$ruleMock);
61 $this->ruleResourceMock->expects($this->once())->method(
'save')->with(
$ruleMock)->willReturn(
$ruleMock);
63 $this->assertEquals(
$ruleMock, $this->repository->save($this->ruleMock));
72 $this->ruleMock->expects($this->at(0))->method(
'getRuleId')->willReturn(
null);
73 $this->ruleMock->expects($this->at(1))->method(
'getRuleId')->willReturn(1);
74 $this->ruleMock->expects($this->never())->method(
'getId');
75 $this->ruleResourceMock
76 ->expects($this->once())
78 ->with($this->ruleMock)->willThrowException(
new \Exception());
79 $this->repository->save($this->ruleMock);
84 $this->ruleMock->expects($this->once())->method(
'getId')->willReturn(1);
85 $this->ruleResourceMock
86 ->expects($this->once())
88 ->with($this->ruleMock);
89 $this->assertEquals(
true, $this->repository->delete($this->ruleMock));
96 $this->ruleFactoryMock->expects($this->once())->method(
'create')->willReturn(
$ruleMock);
100 $this->ruleResourceMock
101 ->expects($this->once())
104 $this->assertEquals(
true, $this->repository->deleteById(
$ruleId));
113 $this->ruleMock->expects($this->once())->method(
'getRuleId')->willReturn(1);
114 $this->ruleResourceMock
115 ->expects($this->once())
117 ->with($this->ruleMock)->willThrowException(
new \Exception());
118 $this->repository->delete($this->ruleMock);
125 $this->ruleFactoryMock->expects($this->once())->method(
'create')->willReturn(
$ruleMock);
127 $ruleMock->expects($this->once())->method(
'getRuleId')->willReturn(
$ruleId);
141 $this->ruleFactoryMock->expects($this->once())->method(
'create')->willReturn(
$ruleMock);
143 $ruleMock->expects($this->once())->method(
'getRuleId')->willReturn(
null);