44
55namespace PhpList \Core \Tests \Unit \Domain \Subscription \Service ;
66
7- use Doctrine \Common \Collections \ArrayCollection ;
87use Doctrine \ORM \EntityManagerInterface ;
98use PhpList \Core \Domain \Analytics \Repository \LinkTrackUmlClickRepository ;
109use PhpList \Core \Domain \Analytics \Repository \UserMessageViewRepository ;
2322use PhpList \Core \Domain \Subscription \Repository \SubscriberAttributeValueRepository ;
2423use PhpList \Core \Domain \Subscription \Repository \SubscriberHistoryRepository ;
2524use PhpList \Core \Domain \Subscription \Repository \SubscriberRepository ;
25+ use PhpList \Core \Domain \Subscription \Repository \SubscriptionRepository ;
2626use PhpList \Core \Domain \Subscription \Service \SubscriberDeletionService ;
2727use PHPUnit \Framework \MockObject \MockObject ;
2828use PHPUnit \Framework \TestCase ;
@@ -32,36 +32,36 @@ class SubscriberDeletionServiceTest extends TestCase
3232 private LinkTrackUmlClickRepository &MockObject $ linkTrackUmlClickRepository ;
3333 private EntityManagerInterface &MockObject $ entityManager ;
3434 private UserMessageRepository &MockObject $ userMessageRepository ;
35- private SubscriberRepository &MockObject $ subscriberRepository ;
3635 private SubscriberAttributeValueRepository &MockObject $ subscriberAttributeValueRepository ;
3736 private SubscriberHistoryRepository &MockObject $ subscriberHistoryRepository ;
3837 private UserMessageBounceRepository &MockObject $ userMessageBounceRepository ;
3938 private UserMessageForwardRepository &MockObject $ userMessageForwardRepository ;
4039 private UserMessageViewRepository &MockObject $ userMessageViewRepository ;
40+ private SubscriptionRepository &MockObject $ subscriptionRepository ;
4141 private SubscriberDeletionService $ service ;
4242
4343 protected function setUp (): void
4444 {
4545 $ this ->linkTrackUmlClickRepository = $ this ->createMock (LinkTrackUmlClickRepository::class);
4646 $ this ->entityManager = $ this ->createMock (EntityManagerInterface::class);
4747 $ this ->userMessageRepository = $ this ->createMock (UserMessageRepository::class);
48- $ this ->subscriberRepository = $ this ->createMock (SubscriberRepository::class);
4948 $ this ->subscriberAttributeValueRepository = $ this ->createMock (SubscriberAttributeValueRepository::class);
5049 $ this ->subscriberHistoryRepository = $ this ->createMock (SubscriberHistoryRepository::class);
5150 $ this ->userMessageBounceRepository = $ this ->createMock (UserMessageBounceRepository::class);
5251 $ this ->userMessageForwardRepository = $ this ->createMock (UserMessageForwardRepository::class);
5352 $ this ->userMessageViewRepository = $ this ->createMock (UserMessageViewRepository::class);
53+ $ this ->subscriptionRepository = $ this ->createMock (SubscriptionRepository::class);
5454
5555 $ this ->service = new SubscriberDeletionService (
5656 $ this ->linkTrackUmlClickRepository ,
5757 $ this ->entityManager ,
5858 $ this ->userMessageRepository ,
59- $ this ->subscriberRepository ,
6059 $ this ->subscriberAttributeValueRepository ,
6160 $ this ->subscriberHistoryRepository ,
6261 $ this ->userMessageBounceRepository ,
6362 $ this ->userMessageForwardRepository ,
64- $ this ->userMessageViewRepository
63+ $ this ->userMessageViewRepository ,
64+ $ this ->subscriptionRepository
6565 );
6666 }
6767
@@ -72,88 +72,56 @@ public function testDeleteLeavingBlacklistRemovesAllRelatedData(): void
7272 $ subscriber ->method ('getId ' )->willReturn ($ subscriberId );
7373
7474 $ 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 ]);
7779
7880 $ linkTrackUmlClick = $ this ->createMock (LinkTrackUmlClick::class);
7981 $ this ->linkTrackUmlClickRepository
8082 ->method ('findBy ' )
81- ->with (['userid ' => $ subscriberId ])
83+ ->with (['userId ' => $ subscriberId ])
8284 ->willReturn ([$ linkTrackUmlClick ]);
83- $ this ->linkTrackUmlClickRepository
84- ->expects ($ this ->once ())
85- ->method ('remove ' )
86- ->with ($ linkTrackUmlClick );
8785
8886 $ this ->entityManager
89- ->expects ($ this ->once ())
90- ->method ('remove ' )
91- ->with ($ subscription );
87+ ->expects ($ this ->atLeast (1 ))
88+ ->method ('remove ' );
9289
9390 $ userMessage = $ this ->createMock (UserMessage::class);
9491 $ this ->userMessageRepository
9592 ->method ('findBy ' )
9693 ->with (['user ' => $ subscriber ])
9794 ->willReturn ([$ userMessage ]);
98- $ this ->userMessageRepository
99- ->expects ($ this ->once ())
100- ->method ('remove ' )
101- ->with ($ userMessage );
10295
10396 $ subscriberAttribute = $ this ->createMock (SubscriberAttributeValue::class);
10497 $ this ->subscriberAttributeValueRepository
10598 ->method ('findBy ' )
10699 ->with (['subscriber ' => $ subscriber ])
107100 ->willReturn ([$ subscriberAttribute ]);
108- $ this ->subscriberAttributeValueRepository
109- ->expects ($ this ->once ())
110- ->method ('remove ' )
111- ->with ($ subscriberAttribute );
112101
113102 $ subscriberHistory = $ this ->createMock (SubscriberHistory::class);
114103 $ this ->subscriberHistoryRepository
115104 ->method ('findBy ' )
116105 ->with (['subscriber ' => $ subscriber ])
117106 ->willReturn ([$ subscriberHistory ]);
118- $ this ->subscriberHistoryRepository
119- ->expects ($ this ->once ())
120- ->method ('remove ' )
121- ->with ($ subscriberHistory );
122107
123108 $ userMessageBounce = $ this ->createMock (UserMessageBounce::class);
124109 $ this ->userMessageBounceRepository
125110 ->method ('findBy ' )
126111 ->with (['userId ' => $ subscriberId ])
127112 ->willReturn ([$ userMessageBounce ]);
128- $ this ->userMessageBounceRepository
129- ->expects ($ this ->once ())
130- ->method ('remove ' )
131- ->with ($ userMessageBounce );
132113
133114 $ userMessageForward = $ this ->createMock (UserMessageForward::class);
134115 $ this ->userMessageForwardRepository
135116 ->method ('findBy ' )
136117 ->with (['userId ' => $ subscriberId ])
137118 ->willReturn ([$ userMessageForward ]);
138- $ this ->userMessageForwardRepository
139- ->expects ($ this ->once ())
140- ->method ('remove ' )
141- ->with ($ userMessageForward );
142119
143120 $ userMessageView = $ this ->createMock (UserMessageView::class);
144121 $ this ->userMessageViewRepository
145122 ->method ('findBy ' )
146- ->with (['userid ' => $ subscriberId ])
123+ ->with (['userId ' => $ subscriberId ])
147124 ->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 );
157125
158126 $ this ->service ->deleteLeavingBlacklist ($ subscriber );
159127 }
@@ -164,16 +132,15 @@ public function testDeleteLeavingBlacklistHandlesEmptyRelatedData(): void
164132 $ subscriberId = 123 ;
165133 $ subscriber ->method ('getId ' )->willReturn ($ subscriberId );
166134
167- $ emptySubscriptions = new ArrayCollection ();
168- $ subscriber ->method ('getSubscriptions ' )->willReturn ($ emptySubscriptions );
135+ $ this ->subscriptionRepository
136+ ->method ('findBy ' )
137+ ->with (['subscriber ' => $ subscriber ])
138+ ->willReturn ([]);
169139
170140 $ this ->linkTrackUmlClickRepository
171141 ->method ('findBy ' )
172- ->with (['userid ' => $ subscriberId ])
142+ ->with (['userId ' => $ subscriberId ])
173143 ->willReturn ([]);
174- $ this ->linkTrackUmlClickRepository
175- ->expects ($ this ->never ())
176- ->method ('remove ' );
177144
178145 $ this ->userMessageRepository
179146 ->method ('findBy ' )
@@ -217,13 +184,13 @@ public function testDeleteLeavingBlacklistHandlesEmptyRelatedData(): void
217184
218185 $ this ->userMessageViewRepository
219186 ->method ('findBy ' )
220- ->with (['userid ' => $ subscriberId ])
187+ ->with (['userId ' => $ subscriberId ])
221188 ->willReturn ([]);
222189 $ this ->userMessageViewRepository
223190 ->expects ($ this ->never ())
224191 ->method ('remove ' );
225192
226- $ this ->subscriberRepository
193+ $ this ->entityManager
227194 ->expects ($ this ->once ())
228195 ->method ('remove ' )
229196 ->with ($ subscriber );
0 commit comments