Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

namespace PhpList\PhpList4\Domain\Repository\Subscription;

use PhpList\PhpList4\Domain\Model\Messaging\SubscriberList;
use PhpList\PhpList4\Domain\Model\Subscription\Subscriber;
use PhpList\PhpList4\Domain\Model\Subscription\Subscription;
use PhpList\PhpList4\Domain\Repository\AbstractRepository;

/**
* Repository for Subscription models.
*
* @method Subscription[] findBySubscriber(int $subscriberId)
* @method Subscription[] findBySubscriberList(int $listId)
* @method Subscription[] findBySubscriber(Subscriber $subscriber)
* @method Subscription[] findBySubscriberList(SubscriberList $list)
*
* @author Oliver Klee <oliver@phplist.com>
*/
Expand Down
2 changes: 2 additions & 0 deletions Tests/Integration/Domain/Repository/Fixtures/Subscriber.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
id,entered,modified,email,confirmed,blacklisted,bouncecount,uniqid,htmlemail,disabled
1,"2016-07-22 15:01:17","2016-08-23 19:50:43","oliver@example.com",1,1,17,"95feb7fe7e06e6c11ca8d0c48cb46e89",1,1
2,"2016-08-22 15:01:17","2017-08-23 19:50:43","sam@example.com",1,1,17,"95feb7fe7e06e6c11ca8d0c48cb46e81",1,0
3,"2016-08-22 15:01:17","2017-08-23 19:50:43","elena@example.com",1,1,17,"95feb7fe7e06e6c11ca8d0c48cb46e84",1,0
3 changes: 3 additions & 0 deletions Tests/Integration/Domain/Repository/Fixtures/Subscription.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
userid,listid,entered,modified
1,2,"2016-07-22 15:01:17","2016-08-23 19:50:43"
2,2,"2016-08-22 15:01:17","2016-09-23 19:50:43"
2,1,"2016-09-22 15:01:17","2016-10-23 19:50:43"
3,1,"2017-09-22 15:01:17","2017-10-23 19:50:43"
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,46 @@ public function modificationDateOfNewModelIsSetToNowOnPersist()

self::assertSimilarDates($expectedModificationDate, $model->getModificationDate());
}

/**
* @test
*/
public function findBySubscriberFindsSubscriptionOnlyWithTheGivenSubscriber()
{
$this->getDataSet()->addTable(self::SUBSCRIBER_TABLE_NAME, __DIR__ . '/../Fixtures/Subscriber.csv');
$this->getDataSet()->addTable(self::TABLE_NAME, __DIR__ . '/../Fixtures/Subscription.csv');
$this->touchDatabaseTable(self::TABLE_NAME);
$this->applyDatabaseChanges();

/** @var Subscriber $subscriber */
$subscriber = $this->subscriberRepository->find(1);

$result = $this->subject->findBySubscriber($subscriber);

/** @var Subscription $subscription */
foreach ($result as $subscription) {
self::assertSame($subscriber, $subscription->getSubscriber());
}
}

/**
* @test
*/
public function findBySubscriberListFindsSubscriptionOnlyWithTheGivenSubscriberList()
{
$this->getDataSet()->addTable(self::SUBSCRIBER_TABLE_NAME, __DIR__ . '/../Fixtures/Subscriber.csv');
$this->getDataSet()->addTable(self::TABLE_NAME, __DIR__ . '/../Fixtures/Subscription.csv');
$this->touchDatabaseTable(self::TABLE_NAME);
$this->applyDatabaseChanges();

/** @var SubscriberList $subscriberList */
$subscriberList = $this->subscriberListRepository->find(1);

$result = $this->subject->findBySubscriberList($subscriberList);

/** @var Subscription $subscription */
foreach ($result as $subscription) {
self::assertSame($subscriberList, $subscription->getSubscriberList());
}
}
}