9
9
10
10
use Magento \Framework \ObjectManager \ObjectManager ;
11
11
use Magento \SalesRule \Model \Coupon ;
12
+ use Magento \SalesRule \Model \ResourceModel \Coupon \Collection as CouponCollection ;
13
+ use Magento \SalesRule \Model \ResourceModel \Coupon \CollectionFactory as CouponCollectionFactory ;
12
14
use Magento \SalesRule \Model \Rule ;
13
15
use Magento \Setup \Fixtures \CartPriceRulesFixture ;
14
16
use Magento \Setup \Fixtures \CouponCodesFixture ;
@@ -43,6 +45,11 @@ class CouponCodesFixtureTest extends TestCase
43
45
*/
44
46
private $ couponCodeFactoryMock ;
45
47
48
+ /**
49
+ * @var CouponCollectionFactory|MockObject
50
+ */
51
+ private $ couponCollectionFactoryMock ;
52
+
46
53
/**
47
54
* setUp
48
55
*/
@@ -54,10 +61,12 @@ protected function setUp(): void
54
61
\Magento \SalesRule \Model \CouponFactory::class,
55
62
['create ' ]
56
63
);
64
+ $ this ->couponCollectionFactoryMock = $ this ->createMock (CouponCollectionFactory::class);
57
65
$ this ->model = new CouponCodesFixture (
58
66
$ this ->fixtureModelMock ,
59
67
$ this ->ruleFactoryMock ,
60
- $ this ->couponCodeFactoryMock
68
+ $ this ->couponCodeFactoryMock ,
69
+ $ this ->couponCollectionFactoryMock
61
70
);
62
71
}
63
72
@@ -66,6 +75,14 @@ protected function setUp(): void
66
75
*/
67
76
public function testExecute ()
68
77
{
78
+ $ couponCollectionMock = $ this ->createMock (CouponCollection::class);
79
+ $ this ->couponCollectionFactoryMock ->expects ($ this ->once ())
80
+ ->method ('create ' )
81
+ ->willReturn ($ couponCollectionMock );
82
+ $ couponCollectionMock ->expects ($ this ->once ())
83
+ ->method ('getSize ' )
84
+ ->willReturn (0 );
85
+
69
86
$ websiteMock = $ this ->createMock (Website::class);
70
87
$ websiteMock ->expects ($ this ->once ())
71
88
->method ('getId ' )
@@ -127,6 +144,14 @@ public function testExecute()
127
144
*/
128
145
public function testNoFixtureConfigValue ()
129
146
{
147
+ $ couponCollectionMock = $ this ->createMock (CouponCollection::class);
148
+ $ this ->couponCollectionFactoryMock ->expects ($ this ->once ())
149
+ ->method ('create ' )
150
+ ->willReturn ($ couponCollectionMock );
151
+ $ couponCollectionMock ->expects ($ this ->once ())
152
+ ->method ('getSize ' )
153
+ ->willReturn (0 );
154
+
130
155
$ ruleMock = $ this ->createMock (Rule::class);
131
156
$ ruleMock ->expects ($ this ->never ())->method ('save ' );
132
157
@@ -148,6 +173,28 @@ public function testNoFixtureConfigValue()
148
173
$ this ->model ->execute ();
149
174
}
150
175
176
+ public function testFixtureAlreadyCreated ()
177
+ {
178
+ $ couponCollectionMock = $ this ->createMock (CouponCollection::class);
179
+ $ this ->couponCollectionFactoryMock ->expects ($ this ->once ())
180
+ ->method ('create ' )
181
+ ->willReturn ($ couponCollectionMock );
182
+ $ couponCollectionMock ->expects ($ this ->once ())
183
+ ->method ('getSize ' )
184
+ ->willReturn (1 );
185
+
186
+ $ this ->fixtureModelMock
187
+ ->expects ($ this ->once ())
188
+ ->method ('getValue ' )
189
+ ->willReturn (1 );
190
+
191
+ $ this ->fixtureModelMock ->expects ($ this ->never ())->method ('getObjectManager ' );
192
+ $ this ->ruleFactoryMock ->expects ($ this ->never ())->method ('create ' );
193
+ $ this ->couponCodeFactoryMock ->expects ($ this ->never ())->method ('create ' );
194
+
195
+ $ this ->model ->execute ();
196
+ }
197
+
151
198
/**
152
199
* testGetActionTitle
153
200
*/
0 commit comments