4
4
5
5
namespace PhpList \Core \Tests \Unit \Domain \Subscription \Service ;
6
6
7
- use Doctrine \Common \Collections \ArrayCollection ;
8
7
use Doctrine \ORM \EntityManagerInterface ;
9
8
use PhpList \Core \Domain \Analytics \Repository \LinkTrackUmlClickRepository ;
10
9
use PhpList \Core \Domain \Analytics \Repository \UserMessageViewRepository ;
23
22
use PhpList \Core \Domain \Subscription \Repository \SubscriberAttributeValueRepository ;
24
23
use PhpList \Core \Domain \Subscription \Repository \SubscriberHistoryRepository ;
25
24
use PhpList \Core \Domain \Subscription \Repository \SubscriberRepository ;
25
+ use PhpList \Core \Domain \Subscription \Repository \SubscriptionRepository ;
26
26
use PhpList \Core \Domain \Subscription \Service \SubscriberDeletionService ;
27
27
use PHPUnit \Framework \MockObject \MockObject ;
28
28
use PHPUnit \Framework \TestCase ;
@@ -32,36 +32,36 @@ class SubscriberDeletionServiceTest extends TestCase
32
32
private LinkTrackUmlClickRepository &MockObject $ linkTrackUmlClickRepository ;
33
33
private EntityManagerInterface &MockObject $ entityManager ;
34
34
private UserMessageRepository &MockObject $ userMessageRepository ;
35
- private SubscriberRepository &MockObject $ subscriberRepository ;
36
35
private SubscriberAttributeValueRepository &MockObject $ subscriberAttributeValueRepository ;
37
36
private SubscriberHistoryRepository &MockObject $ subscriberHistoryRepository ;
38
37
private UserMessageBounceRepository &MockObject $ userMessageBounceRepository ;
39
38
private UserMessageForwardRepository &MockObject $ userMessageForwardRepository ;
40
39
private UserMessageViewRepository &MockObject $ userMessageViewRepository ;
40
+ private SubscriptionRepository &MockObject $ subscriptionRepository ;
41
41
private SubscriberDeletionService $ service ;
42
42
43
43
protected function setUp (): void
44
44
{
45
45
$ this ->linkTrackUmlClickRepository = $ this ->createMock (LinkTrackUmlClickRepository::class);
46
46
$ this ->entityManager = $ this ->createMock (EntityManagerInterface::class);
47
47
$ this ->userMessageRepository = $ this ->createMock (UserMessageRepository::class);
48
- $ this ->subscriberRepository = $ this ->createMock (SubscriberRepository::class);
49
48
$ this ->subscriberAttributeValueRepository = $ this ->createMock (SubscriberAttributeValueRepository::class);
50
49
$ this ->subscriberHistoryRepository = $ this ->createMock (SubscriberHistoryRepository::class);
51
50
$ this ->userMessageBounceRepository = $ this ->createMock (UserMessageBounceRepository::class);
52
51
$ this ->userMessageForwardRepository = $ this ->createMock (UserMessageForwardRepository::class);
53
52
$ this ->userMessageViewRepository = $ this ->createMock (UserMessageViewRepository::class);
53
+ $ this ->subscriptionRepository = $ this ->createMock (SubscriptionRepository::class);
54
54
55
55
$ this ->service = new SubscriberDeletionService (
56
56
$ this ->linkTrackUmlClickRepository ,
57
57
$ this ->entityManager ,
58
58
$ this ->userMessageRepository ,
59
- $ this ->subscriberRepository ,
60
59
$ this ->subscriberAttributeValueRepository ,
61
60
$ this ->subscriberHistoryRepository ,
62
61
$ this ->userMessageBounceRepository ,
63
62
$ this ->userMessageForwardRepository ,
64
- $ this ->userMessageViewRepository
63
+ $ this ->userMessageViewRepository ,
64
+ $ this ->subscriptionRepository
65
65
);
66
66
}
67
67
@@ -72,88 +72,56 @@ public function testDeleteLeavingBlacklistRemovesAllRelatedData(): void
72
72
$ subscriber ->method ('getId ' )->willReturn ($ subscriberId );
73
73
74
74
$ subscription = $ this ->createMock (Subscription::class);
75
- $ subscriptions = new ArrayCollection ([$ subscription ]);
76
- $ subscriber ->method ('getSubscriptions ' )->willReturn ($ subscriptions );
75
+ $ this ->subscriptionRepository
76
+ ->method ('findBy ' )
77
+ ->with (['subscriber ' => $ subscriber ])
78
+ ->willReturn ([$ subscription ]);
77
79
78
80
$ linkTrackUmlClick = $ this ->createMock (LinkTrackUmlClick::class);
79
81
$ this ->linkTrackUmlClickRepository
80
82
->method ('findBy ' )
81
- ->with (['userid ' => $ subscriberId ])
83
+ ->with (['userId ' => $ subscriberId ])
82
84
->willReturn ([$ linkTrackUmlClick ]);
83
- $ this ->linkTrackUmlClickRepository
84
- ->expects ($ this ->once ())
85
- ->method ('remove ' )
86
- ->with ($ linkTrackUmlClick );
87
85
88
86
$ this ->entityManager
89
- ->expects ($ this ->once ())
90
- ->method ('remove ' )
91
- ->with ($ subscription );
87
+ ->expects ($ this ->atLeast (1 ))
88
+ ->method ('remove ' );
92
89
93
90
$ userMessage = $ this ->createMock (UserMessage::class);
94
91
$ this ->userMessageRepository
95
92
->method ('findBy ' )
96
93
->with (['user ' => $ subscriber ])
97
94
->willReturn ([$ userMessage ]);
98
- $ this ->userMessageRepository
99
- ->expects ($ this ->once ())
100
- ->method ('remove ' )
101
- ->with ($ userMessage );
102
95
103
96
$ subscriberAttribute = $ this ->createMock (SubscriberAttributeValue::class);
104
97
$ this ->subscriberAttributeValueRepository
105
98
->method ('findBy ' )
106
99
->with (['subscriber ' => $ subscriber ])
107
100
->willReturn ([$ subscriberAttribute ]);
108
- $ this ->subscriberAttributeValueRepository
109
- ->expects ($ this ->once ())
110
- ->method ('remove ' )
111
- ->with ($ subscriberAttribute );
112
101
113
102
$ subscriberHistory = $ this ->createMock (SubscriberHistory::class);
114
103
$ this ->subscriberHistoryRepository
115
104
->method ('findBy ' )
116
105
->with (['subscriber ' => $ subscriber ])
117
106
->willReturn ([$ subscriberHistory ]);
118
- $ this ->subscriberHistoryRepository
119
- ->expects ($ this ->once ())
120
- ->method ('remove ' )
121
- ->with ($ subscriberHistory );
122
107
123
108
$ userMessageBounce = $ this ->createMock (UserMessageBounce::class);
124
109
$ this ->userMessageBounceRepository
125
110
->method ('findBy ' )
126
111
->with (['userId ' => $ subscriberId ])
127
112
->willReturn ([$ userMessageBounce ]);
128
- $ this ->userMessageBounceRepository
129
- ->expects ($ this ->once ())
130
- ->method ('remove ' )
131
- ->with ($ userMessageBounce );
132
113
133
114
$ userMessageForward = $ this ->createMock (UserMessageForward::class);
134
115
$ this ->userMessageForwardRepository
135
116
->method ('findBy ' )
136
117
->with (['userId ' => $ subscriberId ])
137
118
->willReturn ([$ userMessageForward ]);
138
- $ this ->userMessageForwardRepository
139
- ->expects ($ this ->once ())
140
- ->method ('remove ' )
141
- ->with ($ userMessageForward );
142
119
143
120
$ userMessageView = $ this ->createMock (UserMessageView::class);
144
121
$ this ->userMessageViewRepository
145
122
->method ('findBy ' )
146
- ->with (['userid ' => $ subscriberId ])
123
+ ->with (['userId ' => $ subscriberId ])
147
124
->willReturn ([$ userMessageView ]);
148
- $ this ->userMessageViewRepository
149
- ->expects ($ this ->once ())
150
- ->method ('remove ' )
151
- ->with ($ userMessageView );
152
-
153
- $ this ->subscriberRepository
154
- ->expects ($ this ->once ())
155
- ->method ('remove ' )
156
- ->with ($ subscriber );
157
125
158
126
$ this ->service ->deleteLeavingBlacklist ($ subscriber );
159
127
}
@@ -164,16 +132,15 @@ public function testDeleteLeavingBlacklistHandlesEmptyRelatedData(): void
164
132
$ subscriberId = 123 ;
165
133
$ subscriber ->method ('getId ' )->willReturn ($ subscriberId );
166
134
167
- $ emptySubscriptions = new ArrayCollection ();
168
- $ subscriber ->method ('getSubscriptions ' )->willReturn ($ emptySubscriptions );
135
+ $ this ->subscriptionRepository
136
+ ->method ('findBy ' )
137
+ ->with (['subscriber ' => $ subscriber ])
138
+ ->willReturn ([]);
169
139
170
140
$ this ->linkTrackUmlClickRepository
171
141
->method ('findBy ' )
172
- ->with (['userid ' => $ subscriberId ])
142
+ ->with (['userId ' => $ subscriberId ])
173
143
->willReturn ([]);
174
- $ this ->linkTrackUmlClickRepository
175
- ->expects ($ this ->never ())
176
- ->method ('remove ' );
177
144
178
145
$ this ->userMessageRepository
179
146
->method ('findBy ' )
@@ -217,13 +184,13 @@ public function testDeleteLeavingBlacklistHandlesEmptyRelatedData(): void
217
184
218
185
$ this ->userMessageViewRepository
219
186
->method ('findBy ' )
220
- ->with (['userid ' => $ subscriberId ])
187
+ ->with (['userId ' => $ subscriberId ])
221
188
->willReturn ([]);
222
189
$ this ->userMessageViewRepository
223
190
->expects ($ this ->never ())
224
191
->method ('remove ' );
225
192
226
- $ this ->subscriberRepository
193
+ $ this ->entityManager
227
194
->expects ($ this ->once ())
228
195
->method ('remove ' )
229
196
->with ($ subscriber );
0 commit comments