Skip to content

Commit de69bd1

Browse files
author
Oliver Klee
committed
[FEATURE] Repository methods for querying subscriptions
- SubscriptionRepository.findBySubscriber - SubscriptionRepository.findBySubscriberList
1 parent d6c0035 commit de69bd1

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

Classes/Domain/Repository/Subscription/SubscriptionRepository.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33

44
namespace PhpList\PhpList4\Domain\Repository\Subscription;
55

6+
use PhpList\PhpList4\Domain\Model\Messaging\SubscriberList;
7+
use PhpList\PhpList4\Domain\Model\Subscription\Subscriber;
68
use PhpList\PhpList4\Domain\Model\Subscription\Subscription;
79
use PhpList\PhpList4\Domain\Repository\AbstractRepository;
810

911
/**
1012
* Repository for Subscription models.
1113
*
12-
* @method Subscription[] findBySubscriber(int $subscriberId)
13-
* @method Subscription[] findBySubscriberList(int $listId)
14+
* @method Subscription[] findBySubscriber(Subscriber $subscriber)
15+
* @method Subscription[] findBySubscriberList(SubscriberList $list)
1416
*
1517
* @author Oliver Klee <oliver@phplist.com>
1618
*/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
id,entered,modified,email,confirmed,blacklisted,bouncecount,uniqid,htmlemail,disabled
22
1,"2016-07-22 15:01:17","2016-08-23 19:50:43","oliver@example.com",1,1,17,"95feb7fe7e06e6c11ca8d0c48cb46e89",1,1
3+
2,"2016-08-22 15:01:17","2017-08-23 19:50:43","sam@example.com",1,1,17,"95feb7fe7e06e6c11ca8d0c48cb46e81",1,0
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
userid,listid,entered,modified
22
1,2,"2016-07-22 15:01:17","2016-08-23 19:50:43"
3+
2,2,"2016-08-22 15:01:17","2016-09-23 19:50:43"
4+
2,1,"2016-09-22 15:01:17","2016-10-23 19:50:43"

Tests/Integration/Domain/Repository/Subscription/SubscriptionRepositoryTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,46 @@ public function modificationDateOfNewModelIsSetToNowOnPersist()
174174

175175
self::assertSimilarDates($expectedModificationDate, $model->getModificationDate());
176176
}
177+
178+
/**
179+
* @test
180+
*/
181+
public function findBySubscriberFindsSubscriptionOnlyWithTheGivenSubscriber()
182+
{
183+
$this->getDataSet()->addTable(self::SUBSCRIBER_TABLE_NAME, __DIR__ . '/../Fixtures/Subscriber.csv');
184+
$this->getDataSet()->addTable(self::TABLE_NAME, __DIR__ . '/../Fixtures/Subscription.csv');
185+
$this->touchDatabaseTable(self::TABLE_NAME);
186+
$this->applyDatabaseChanges();
187+
188+
/** @var Subscriber $subscriber */
189+
$subscriber = $this->subscriberRepository->find(1);
190+
191+
$result = $this->subject->findBySubscriber($subscriber);
192+
193+
/** @var Subscription $subscription */
194+
foreach ($result as $subscription) {
195+
self::assertSame($subscriber, $subscription->getSubscriber());
196+
}
197+
}
198+
199+
/**
200+
* @test
201+
*/
202+
public function findBySubscriberListFindsSubscriptionOnlyWithTheGivenSubscriberList()
203+
{
204+
$this->getDataSet()->addTable(self::SUBSCRIBER_TABLE_NAME, __DIR__ . '/../Fixtures/Subscriber.csv');
205+
$this->getDataSet()->addTable(self::TABLE_NAME, __DIR__ . '/../Fixtures/Subscription.csv');
206+
$this->touchDatabaseTable(self::TABLE_NAME);
207+
$this->applyDatabaseChanges();
208+
209+
/** @var SubscriberList $subscriberList */
210+
$subscriberList = $this->subscriberListRepository->find(1);
211+
212+
$result = $this->subject->findBySubscriberList($subscriberList);
213+
214+
/** @var Subscription $subscription */
215+
foreach ($result as $subscription) {
216+
self::assertSame($subscriberList, $subscription->getSubscriberList());
217+
}
218+
}
177219
}

0 commit comments

Comments
 (0)