diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e427b11..bebb09f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -51,16 +51,12 @@ jobs:
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
- continue-on-error: ${{matrix.php-versions == '8.0' }} # Temporal until full support for php8 === [temp-php8]
- name: Validating composer.json
run: composer validate --no-check-all --no-check-lock --strict;
- continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
- name: Linting all php files
run: find src/ tests/ public/ -name ''*.php'' -print0 | xargs -0 -n 1 -P 4 php -l; php -l bin/*;
- continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
- name: Run units tests with phpunit
run: vendor/bin/phpunit tests/Unit/
- continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
- name: Run integration tests with phpunit
run: |
export PHPLIST_DATABASE_NAME=${{ env.DB_DATABASE }}
@@ -69,16 +65,11 @@ jobs:
export PHPLIST_DATABASE_PORT=${{ job.services.mysql.ports['3306'] }}
export PHPLIST_DATABASE_HOST=127.0.0.1
vendor/bin/phpunit tests/Integration/
- continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
- name: Running the system tests
run: vendor/bin/phpunit tests/System/;
- continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
- name: Running static analysis
run: vendor/bin/phpstan analyse -c phpstan.neon;
- continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
- name: Running PHPMD
run: vendor/bin/phpmd src/ text config/PHPMD/rules.xml;
- continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
- name: Running PHP_CodeSniffer
run: vendor/bin/phpcs --standard=config/PhpCodeSniffer/ bin/ src/ tests/ public/;
- continue-on-error: ${{matrix.php-versions == '8.0' }} # [temp-php8]
diff --git a/.github/workflows/core-docs.yml b/.github/workflows/core-docs.yml
index bbf31ae..e4884d8 100644
--- a/.github/workflows/core-docs.yml
+++ b/.github/workflows/core-docs.yml
@@ -1,4 +1,4 @@
-name: Publish Core Docs
+name: Publish Core Docs
on: [push, pull_request]
jobs:
make-restapi-docs:
@@ -10,7 +10,7 @@ jobs:
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
- php-version: 7.4
+ php-version: 8.1
extensions: mbstring, dom, fileinfo, mysql
- name: Get composer cache directory
id: composer-cache
@@ -25,11 +25,13 @@ jobs:
restore-keys: ${{ runner.os }}-composer-
- name: Install current dependencies from composer.lock
run: composer install
- - name: Install phpDocumentor
+ - name: Install phpDocumentor
run: |
wget https://phpdoc.org/phpDocumentor.phar
chmod +x phpDocumentor.phar
mv phpDocumentor.phar /usr/local/bin/phpDocumentor
+ - name: Verify phpDocumentor version
+ run: phpDocumentor --version
- name: Generate documentation
run: composer run-php-documentor
- name: zip phpdocumentor dir
@@ -44,40 +46,40 @@ jobs:
runs-on: ubuntu-20.04
needs: make-restapi-docs
steps:
- - name: Checkout phplist/core-docs
- uses: actions/checkout@v2
- with:
- repository: phpList/core-docs
- fetch-depth: 0
- token: ${{ secrets.PUSH_CORE_DOCS }}
- - name: Restore REST API Spec
- uses: actions/download-artifact@v2
- with:
- name: doc-files
- - name: unzip phpdocumentor
- run: |
- unzip phpdocumentor.zip
- rm phpdocumentor.zip
- - name: List Files
- run: ls
- - name: Sync old files with newly generated ones.
- run: rsync -av docs/phpdocumentor/* .
- - name: Removed temp dirs
- run: rm -rf docs
- - name: Check if updates/changes.
- run: git status --porcelain > repo-changes.txt
- - name: Check changes file
- run: cat repo-changes.txt
- - name: Verify updates.
- id: allow-deploy
- run: |
- if [ -s repo-changes.txt ]; then echo "Updates made to documentation"; echo '::set-output name=DEPLOY::true'; else echo "No updates made to documentation deployment would be skipped."; echo '::set-output name=DEPLOY::false'; fi
- - name: Commit changes and deply
- if: ${{ steps.allow-deploy.outputs.DEPLOY == 'true' }}
- run: |
- rm repo-changes.txt
- git config user.name "github-actions"
- git config user.email "github-actions@restapi-docs.workflow"
- git add .
- git commit -s -m "phplist/core docs deployment `date`"
- git push
\ No newline at end of file
+ - name: Checkout phplist/core-docs
+ uses: actions/checkout@v2
+ with:
+ repository: phpList/core-docs
+ fetch-depth: 0
+ token: ${{ secrets.PUSH_CORE_DOCS }}
+ - name: Restore REST API Spec
+ uses: actions/download-artifact@v2
+ with:
+ name: doc-files
+ - name: unzip phpdocumentor
+ run: |
+ unzip phpdocumentor.zip
+ rm phpdocumentor.zip
+ - name: List Files
+ run: ls
+ - name: Sync old files with newly generated ones.
+ run: rsync -av docs/phpdocumentor/* .
+ - name: Removed temp dirs
+ run: rm -rf docs
+ - name: Check if updates/changes.
+ run: git status --porcelain > repo-changes.txt
+ - name: Check changes file
+ run: cat repo-changes.txt
+ - name: Verify updates.
+ id: allow-deploy
+ run: |
+ if [ -s repo-changes.txt ]; then echo "Updates made to documentation"; echo '::set-output name=DEPLOY::true'; else echo "No updates made to documentation deployment would be skipped."; echo '::set-output name=DEPLOY::false'; fi
+ - name: Commit changes and deply
+ if: ${{ steps.allow-deploy.outputs.DEPLOY == 'true' }}
+ run: |
+ rm repo-changes.txt
+ git config user.name "github-actions"
+ git config user.email "github-actions@restapi-docs.workflow"
+ git add .
+ git commit -s -m "phplist/core docs deployment `date`"
+ git push
diff --git a/composer.json b/composer.json
index be3be26..baa6dc9 100644
--- a/composer.json
+++ b/composer.json
@@ -48,7 +48,8 @@
"symfony/form": "^6.4",
"symfony/validator": "^6.4",
"doctrine/doctrine-fixtures-bundle": "^3.7",
- "doctrine/instantiator": "^2.0"
+ "doctrine/instantiator": "^2.0",
+ "masterminds/html5": "^2.9"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
@@ -101,7 +102,7 @@
},
"extra": {
"branch-alias": {
- "dev-ISSUE-337": "v5.0.x-dev"
+ "dev-master": "5.0.x-dev"
},
"symfony-app-dir": "",
"symfony-bin-dir": "bin",
diff --git a/config/config_dev.yml b/config/config_dev.yml
index 0e0dd41..2b30e97 100644
--- a/config/config_dev.yml
+++ b/config/config_dev.yml
@@ -20,10 +20,10 @@ monolog:
channels: ['!event', '!doctrine', '!console']
# To follow logs in real time, execute the following command:
# `bin/console server:log -vv`
- server_log:
- type: server_log
- process_psr_3_messages: false
- host: 127.0.0.1:9911
+# server_log:
+# type: server_log
+# process_psr_3_messages: false
+# host: 127.0.0.1:9911
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server configuration
#firephp:
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 12e03ee..ccf4fa1 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -9,6 +9,7 @@
>
+
diff --git a/public/app.php b/public/app.php
index fc4c466..8e58c4f 100644
--- a/public/app.php
+++ b/public/app.php
@@ -1,4 +1,5 @@
disabled = false;
+ $this->superUser = false;
+ $this->passwordChangeDate = null;
+ $this->loginName = '';
+ $this->passwordHash = '';
+ $this->modificationDate = null;
+ $this->emailAddress = '';
+ }
public function getLoginName(): string
{
diff --git a/src/Domain/Model/Messaging/SubscriberList.php b/src/Domain/Model/Messaging/SubscriberList.php
index f664934..1adf0a7 100644
--- a/src/Domain/Model/Messaging/SubscriberList.php
+++ b/src/Domain/Model/Messaging/SubscriberList.php
@@ -8,6 +8,7 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
+use PhpList\Core\Domain\Model\Subscription\Subscription;
use Symfony\Component\Serializer\Annotation\Ignore;
use Symfony\Component\Serializer\Annotation\SerializedName;
use PhpList\Core\Domain\Model\Identity\Administrator;
@@ -28,6 +29,8 @@
*/
#[ORM\Entity(repositoryClass: "PhpList\Core\Domain\Repository\Messaging\SubscriberListRepository")]
#[ORM\Table(name: "phplist_list")]
+#[ORM\Index(name: "nameidx", columns: ["name"])]
+#[ORM\Index(name: "listorderidx", columns: ["listorder"])]
#[ORM\HasLifecycleCallbacks]
class SubscriberList implements DomainModel, Identity, CreationDate, ModificationDate
{
@@ -66,11 +69,13 @@ class SubscriberList implements DomainModel, Identity, CreationDate, Modificatio
#[ORM\Column(name: "active", type: "boolean")]
#[SerializedName("public")]
- private bool $public = false;
+ #[Groups(['SubscriberList'])]
+ private bool $public;
#[ORM\Column]
#[SerializedName("category")]
- private string $category = '';
+ #[Groups(['SubscriberList'])]
+ private string $category;
#[ORM\ManyToOne(targetEntity: "PhpList\Core\Domain\Model\Identity\Administrator")]
#[ORM\JoinColumn(name: "owner")]
@@ -80,30 +85,19 @@ class SubscriberList implements DomainModel, Identity, CreationDate, Modificatio
#[ORM\OneToMany(
targetEntity: "PhpList\Core\Domain\Model\Subscription\Subscription",
mappedBy: "subscriberList",
- cascade: ["remove"]
+ cascade: ["remove"],
+ orphanRemoval: true,
)]
#[MaxDepth(1)]
private Collection $subscriptions;
- #[ORM\ManyToMany(
- targetEntity: "PhpList\Core\Domain\Model\Subscription\Subscriber",
- inversedBy: "subscribedLists",
- fetch: "EXTRA_LAZY"
- )]
- #[ORM\JoinTable(
- name: "phplist_listuser",
- joinColumns: [new ORM\JoinColumn(name: "listid")],
- inverseJoinColumns: [new ORM\JoinColumn(name: "userid")]
- )]
- #[MaxDepth(1)]
- private Collection $subscribers;
-
public function __construct()
{
$this->subscriptions = new ArrayCollection();
- $this->subscribers = new ArrayCollection();
$this->listPosition = 0;
$this->subjectPrefix = '';
+ $this->category = '';
+ $this->public = false;
}
public function getName(): string
@@ -181,18 +175,32 @@ public function getSubscriptions(): Collection
return $this->subscriptions;
}
- public function setSubscriptions(Collection $subscriptions): void
+ public function addSubscription(Subscription $subscription): self
{
- $this->subscriptions = $subscriptions;
+ if (!$this->subscriptions->contains($subscription)) {
+ $this->subscriptions->add($subscription);
+ $subscription->setSubscriberList($this);
+ }
+
+ return $this;
}
- public function getSubscribers(): Collection
+ public function removeSubscription(Subscription $subscription): self
{
- return $this->subscribers;
+ if ($this->subscriptions->removeElement($subscription)) {
+ $subscription->setSubscriberList(null);
+ }
+
+ return $this;
}
- public function setSubscribers(Collection $subscribers): void
+ public function getSubscribers(): Collection
{
- $this->subscribers = $subscribers;
+ $result = new ArrayCollection();
+ foreach ($this->subscriptions as $subscription) {
+ $result->add($subscription->getSubscriber());
+ }
+
+ return $result;
}
}
diff --git a/src/Domain/Model/Subscription/Subscriber.php b/src/Domain/Model/Subscription/Subscriber.php
index fb8d078..fd84076 100644
--- a/src/Domain/Model/Subscription/Subscriber.php
+++ b/src/Domain/Model/Subscription/Subscriber.php
@@ -26,6 +26,10 @@
*/
#[ORM\Entity(repositoryClass: "PhpList\Core\Domain\Repository\Subscription\SubscriberRepository")]
#[ORM\Table(name: "phplist_user_user")]
+#[ORM\Index(name: "idxuniqid", columns: ["uniqid"])]
+#[ORM\Index(name: "enteredindex", columns: ["entered"])]
+#[ORM\Index(name: "confidx", columns: ["confirmed"])]
+#[ORM\Index(name: "blidx", columns: ["blacklisted"])]
#[ORM\HasLifecycleCallbacks]
class Subscriber implements DomainModel, Identity, CreationDate, ModificationDate
{
@@ -84,20 +88,14 @@ class Subscriber implements DomainModel, Identity, CreationDate, ModificationDat
#[ORM\OneToMany(
targetEntity: "PhpList\Core\Domain\Model\Subscription\Subscription",
mappedBy: "subscriber",
- cascade: ["remove"]
+ cascade: ["remove"],
+ orphanRemoval: true,
)]
private Collection $subscriptions;
- #[ORM\ManyToMany(
- targetEntity: "PhpList\Core\Domain\Model\Messaging\SubscriberList",
- mappedBy: "subscribers"
- )]
- private Collection $subscribedLists;
-
public function __construct()
{
$this->subscriptions = new ArrayCollection();
- $this->subscribedLists = new ArrayCollection();
$this->extraData = '';
}
@@ -192,23 +190,40 @@ public function setExtraData(string $extraData): void
$this->extraData = $extraData;
}
+ /**
+ * @return Collection
+ */
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
- public function setSubscriptions(Collection $subscriptions): void
+ public function addSubscription(Subscription $subscription): self
{
- $this->subscriptions = $subscriptions;
+ if (!$this->subscriptions->contains($subscription)) {
+ $this->subscriptions->add($subscription);
+ $subscription->setSubscriber($this);
+ }
+
+ return $this;
}
- public function getSubscribedLists(): Collection
+ public function removeSubscription(Subscription $subscription): self
{
- return $this->subscribedLists;
+ if ($this->subscriptions->removeElement($subscription)) {
+ $subscription->setSubscriber(null);
+ }
+
+ return $this;
}
- public function setSubscribedLists(Collection $subscribedLists): void
+ public function getSubscribedLists(): Collection
{
- $this->subscribedLists = $subscribedLists;
+ $result = new ArrayCollection();
+ foreach ($this->subscriptions as $subscription) {
+ $result->add($subscription->getSubscriberList());
+ }
+
+ return $result;
}
}
diff --git a/src/Domain/Model/Subscription/Subscription.php b/src/Domain/Model/Subscription/Subscription.php
index 1283569..99e711b 100644
--- a/src/Domain/Model/Subscription/Subscription.php
+++ b/src/Domain/Model/Subscription/Subscription.php
@@ -23,6 +23,10 @@
*/
#[ORM\Entity(repositoryClass: "PhpList\Core\Domain\Repository\Subscription\SubscriptionRepository")]
#[ORM\Table(name: "phplist_listuser")]
+#[ORM\Index(name: "userenteredidx", columns: ["userid", "entered"])]
+#[ORM\Index(name: "userlistenteredidx", columns: ["userid", "entered", "listid"])]
+#[ORM\Index(name: "useridx", columns: ["userid"])]
+#[ORM\Index(name: "listidx", columns: ["listid"])]
#[ORM\HasLifecycleCallbacks]
class Subscription implements DomainModel, CreationDate, ModificationDate
{
@@ -51,7 +55,7 @@ class Subscription implements DomainModel, CreationDate, ModificationDate
targetEntity: "PhpList\Core\Domain\Model\Messaging\SubscriberList",
inversedBy: "subscriptions"
)]
- #[ORM\JoinColumn(name: "listid")]
+ #[ORM\JoinColumn(name: "listid", onDelete: "CASCADE")]
#[Ignore]
private ?SubscriberList $subscriberList = null;
@@ -60,7 +64,7 @@ public function getSubscriber(): Subscriber|Proxy|null
return $this->subscriber;
}
- public function setSubscriber(Subscriber $subscriber): void
+ public function setSubscriber(?Subscriber $subscriber): void
{
$this->subscriber = $subscriber;
}
@@ -70,7 +74,7 @@ public function getSubscriberList(): ?SubscriberList
return $this->subscriberList;
}
- public function setSubscriberList(SubscriberList $subscriberList): void
+ public function setSubscriberList(?SubscriberList $subscriberList): void
{
$this->subscriberList = $subscriberList;
}
diff --git a/src/Domain/Model/Traits/IdentityTrait.php b/src/Domain/Model/Traits/IdentityTrait.php
index 945f485..98b3862 100644
--- a/src/Domain/Model/Traits/IdentityTrait.php
+++ b/src/Domain/Model/Traits/IdentityTrait.php
@@ -21,7 +21,7 @@ trait IdentityTrait
#[ORM\Column(type: "integer")]
#[ORM\GeneratedValue]
#[SerializedName("id")]
- #[Groups(['SubscriberList'])]
+ #[Groups(['SubscriberList', 'SubscriberListMembers'])]
private int $id;
public function getId(): int
diff --git a/src/Domain/Repository/Messaging/SubscriberListRepository.php b/src/Domain/Repository/Messaging/SubscriberListRepository.php
index 25c0685..92ce1bc 100644
--- a/src/Domain/Repository/Messaging/SubscriberListRepository.php
+++ b/src/Domain/Repository/Messaging/SubscriberListRepository.php
@@ -17,4 +17,15 @@
*/
class SubscriberListRepository extends AbstractRepository
{
+ public function findWithSubscription($id)
+ {
+ return $this->createQueryBuilder('sl')
+ ->innerJoin('sl.subscriptions', 's')
+ ->addSelect('s')
+ ->where('sl.id = :id')
+ ->setParameter('id', $id)
+ ->getQuery()
+ ->getOneOrNullResult()
+ ;
+ }
}
diff --git a/src/Domain/Repository/Subscription/SubscriberRepository.php b/src/Domain/Repository/Subscription/SubscriberRepository.php
index fca6e6d..c467e9b 100644
--- a/src/Domain/Repository/Subscription/SubscriberRepository.php
+++ b/src/Domain/Repository/Subscription/SubscriberRepository.php
@@ -16,19 +16,39 @@
*/
class SubscriberRepository extends AbstractRepository
{
- /**
- * Get subscribers by subscribed lists.
- *
- * @param int $listId The ID of the subscription list.
- * @return Subscriber[] Returns an array of Subscriber entities.
- */
- public function findSubscribersBySubscribedList(int $listId): array
+ public function findSubscribersBySubscribedList(int $listId): ?Subscriber
{
return $this->createQueryBuilder('s')
- ->innerJoin('s.subscribedLists', 'l')
- ->where('l.id = :listId')
+ ->innerJoin('s.subscriptions', 'subscription')
+ ->innerJoin('subscription.subscriberList', 'list')
+ ->where('list.id = :listId')
+ ->setParameter('listId', $listId)
+ ->getQuery()
+ ->getOneOrNullResult();
+ }
+
+ /** @return Subscriber[] */
+ public function getSubscribersBySubscribedListId(int $listId): array
+ {
+ return $this->createQueryBuilder('s')
+ ->innerJoin('s.subscriptions', 'subscription')
+ ->innerJoin('subscription.subscriberList', 'list')
+ ->where('list.id = :listId')
->setParameter('listId', $listId)
->getQuery()
->getResult();
}
+
+ public function findSubscriberWithSubscriptions(int $id): ?Subscriber
+ {
+ return $this->createQueryBuilder('s')
+ ->innerJoin('s.subscriptions', 'subscription')
+ ->innerJoin('subscription.subscriberList', 'list')
+ ->addSelect('subscription')
+ ->addSelect('list')
+ ->where('s.id = :id')
+ ->setParameter('id', $id)
+ ->getQuery()
+ ->getOneOrNullResult();
+ }
}
diff --git a/src/TestingSupport/Traits/DatabaseTestTrait.php b/src/TestingSupport/Traits/DatabaseTestTrait.php
index 1448e35..6385a93 100644
--- a/src/TestingSupport/Traits/DatabaseTestTrait.php
+++ b/src/TestingSupport/Traits/DatabaseTestTrait.php
@@ -4,7 +4,6 @@
namespace PhpList\Core\TestingSupport\Traits;
-use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\ORM\Tools\ToolsException;
@@ -28,7 +27,6 @@ trait DatabaseTestTrait
protected function setUpDatabaseTest(): void
{
$this->initializeBootstrap();
- $this->clearDatabase();
}
/**
@@ -58,19 +56,6 @@ private function initializeBootstrap(): void
}
}
- /**
- * Clears the database using ORMPurger.
- */
- private function clearDatabase(): void
- {
- if (!$this->entityManager) {
- throw new RuntimeException('EntityManager not initialized.');
- }
-
- $purger = new ORMPurger($this->entityManager);
- $purger->purge();
- }
-
/**
* Loads data fixtures into the database.
*
diff --git a/src/TestingSupport/Traits/SymfonyServerTrait.php b/src/TestingSupport/Traits/SymfonyServerTrait.php
index 76f1c58..35f2ebd 100644
--- a/src/TestingSupport/Traits/SymfonyServerTrait.php
+++ b/src/TestingSupport/Traits/SymfonyServerTrait.php
@@ -7,20 +7,20 @@
use InvalidArgumentException;
use PhpList\Core\Core\ApplicationStructure;
use RuntimeException;
-use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
/**
* Trait for running the Symfony server in the background.
+ *
+ * @author Oliver Klee
*/
trait SymfonyServerTrait
{
private ?Process $serverProcess = null;
- private static array $validEnvironments = ['test', 'dev', 'prod'];
private static string $lockFileName = '.web-server-pid';
- private static int $maximumWaitTimeForServerLockFile = 5000000; // microseconds
- private static int $waitTimeBetweenServerCommands = 50000; // microseconds
+ private static int $maximumWaitTimeForServerLockFile = 5000000;
+ private static int $waitTimeBetweenServerCommands = 50000;
private static ?ApplicationStructure $applicationStructure = null;
@@ -29,34 +29,26 @@ trait SymfonyServerTrait
*
* @throws InvalidArgumentException|RuntimeException
*/
- protected function startSymfonyServer(string $environment): void
+ protected function startSymfonyServer(): void
{
- if (!in_array($environment, self::$validEnvironments, true)) {
- throw new InvalidArgumentException(sprintf('"%s" is not a valid environment.', $environment));
- }
-
if ($this->lockFileExists()) {
throw new RuntimeException(
sprintf(
- 'The server lock file "%s" already exists. A Symfony server might already be running. Please stop the server or delete the lock file.',
+ 'The server lock file "%s" already exists.',
self::$lockFileName
)
);
}
$this->serverProcess = new Process(
- $this->getSymfonyServerStartCommand($environment),
+ $this->getSymfonyServerStartCommand(),
$this->getApplicationRoot()
);
+ $this->serverProcess->start();
- try {
- $this->serverProcess->start();
- } catch (ProcessFailedException $exception) {
- throw new RuntimeException('Failed to start the Symfony server.', 0, $exception);
- }
-
+ usleep(self::$waitTimeBetweenServerCommands);
$this->waitForServerLockFileToAppear();
- usleep(75000); // Allow the server time to initialize
+ usleep(self::$waitTimeBetweenServerCommands);
}
private function lockFileExists(): bool
@@ -81,14 +73,26 @@ protected function getBaseUrl(): string
private function waitForServerLockFileToAppear(): void
{
$currentWaitTime = 0;
-
- while (!$this->lockFileExists() && $currentWaitTime < self::$maximumWaitTimeForServerLockFile) {
- usleep(self::$waitTimeBetweenServerCommands);
- $currentWaitTime += self::$waitTimeBetweenServerCommands;
+ while (!$this->lockFileExists() && $currentWaitTime < static::$maximumWaitTimeForServerLockFile) {
+ $process = new Process(['symfony', 'server:status', '--no-ansi']);
+ $process->run();
+
+ if ($process->isSuccessful()) {
+ $output = $process->getOutput();
+ if (preg_match('/Listening on (http[s]?:\/\/127\.0\.0\.1:(\d+))/', $output, $matches)) {
+ $port = $matches[2];
+ file_put_contents(self::$lockFileName, trim($port));
+ }
+ }
+ usleep(static::$waitTimeBetweenServerCommands);
+ $currentWaitTime += static::$waitTimeBetweenServerCommands;
}
if (!$this->lockFileExists()) {
- throw new RuntimeException(sprintf('Symfony server lock file "%s" did not appear.', self::$lockFileName));
+ throw new RuntimeException(
+ 'There is no symfony server lock file "' . static::$lockFileName . '".',
+ 1516625236
+ );
}
}
@@ -108,7 +112,7 @@ protected function stopSymfonyServer(): void
}
}
- private function getSymfonyServerStartCommand(string $environment): array
+ private function getSymfonyServerStartCommand(): array
{
$documentRoot = $this->getApplicationRoot() . '/public/';
$this->checkDocumentRoot($documentRoot);
@@ -117,8 +121,6 @@ private function getSymfonyServerStartCommand(string $environment): array
'symfony',
'server:start',
'--daemon',
- '--document-root=' . $documentRoot,
- '--env=' . $environment,
];
}
diff --git a/tests/Integration/Domain/Repository/Fixtures/Administrator.csv b/tests/Integration/Domain/Repository/Fixtures/Administrator.csv
index bacb62f..d1bc43a 100644
--- a/tests/Integration/Domain/Repository/Fixtures/Administrator.csv
+++ b/tests/Integration/Domain/Repository/Fixtures/Administrator.csv
@@ -2,3 +2,4 @@ id,loginname,email,created,modified,password,passwordchanged,disabled,superuser
1,"john.doe","john@example.com","2017-06-22 15:01:17","2017-06-23 19:50:43","1491a3c7e7b23b9a6393323babbb095dee0d7d81b2199617b487bd0fb5236f3c","2017-06-28",0,1
2,"max.doe","john@example.com","2017-06-22 15:01:17","2017-06-23 19:50:43","1491a3c7e7b23b9a6393323babbb095dee0d7d81b2199617b487bd0fb5236f3c","2017-06-28",0,0
3,"disabled.admin","disabled.admin@example.com","2017-06-22 15:01:17","2017-06-23 19:50:43","1491a3c7e7b23b9a6393323babbb095dee0d7d81b2199617b487bd0fb5236f3c","2017-06-28",1,1
+999,"last.admin","last.admin@example.com","2017-06-22 15:01:17","2017-06-23 19:50:43","1491a3c7e7b23b9a6393323babbb095dee0d7d81b2199617b487bd0fb5236f3c","2017-06-28",1,1
diff --git a/tests/Integration/Domain/Repository/Fixtures/AdministratorFixture.php b/tests/Integration/Domain/Repository/Fixtures/AdministratorFixture.php
index e597509..b89fcaf 100644
--- a/tests/Integration/Domain/Repository/Fixtures/AdministratorFixture.php
+++ b/tests/Integration/Domain/Repository/Fixtures/AdministratorFixture.php
@@ -33,6 +33,7 @@ public function load(ObjectManager $manager): void
$row = array_combine($headers, $data);
$admin = new Administrator();
+ $this->setSubjectId($admin, (int)$row['id']);
$admin->setLoginName($row['loginname']);
$admin->setEmailAddress($row['email']);
$this->setSubjectProperty($admin,'creationDate', new DateTime($row['created']));
@@ -40,6 +41,7 @@ public function load(ObjectManager $manager): void
$this->setSubjectProperty($admin,'passwordChangeDate', new DateTime($row['passwordchanged']));
$admin->setDisabled((bool) $row['disabled']);
$admin->setSuperUser((bool) $row['superuser']);
+
$manager->persist($admin);
}
diff --git a/tests/Integration/Domain/Repository/Fixtures/AdministratorTokenWithAdministratorFixture.php b/tests/Integration/Domain/Repository/Fixtures/AdministratorTokenWithAdministratorFixture.php
index ae0acef..7058499 100644
--- a/tests/Integration/Domain/Repository/Fixtures/AdministratorTokenWithAdministratorFixture.php
+++ b/tests/Integration/Domain/Repository/Fixtures/AdministratorTokenWithAdministratorFixture.php
@@ -30,16 +30,20 @@ public function load(ObjectManager $manager): void
}
$headers = fgetcsv($handle);
+ $adminRepository = $manager->getRepository(Administrator::class);
while (($data = fgetcsv($handle)) !== false) {
$row = array_combine($headers, $data);
- $admin = new Administrator();
- $this->setSubjectId($admin,(int)$data['adminid']);
- $manager->persist($admin);
+ $admin = $adminRepository->find($row['adminid']);
+ if ($admin === null) {
+ $admin = new Administrator();
+ $this->setSubjectId($admin,(int)$row['adminid']);
+ $manager->persist($admin);
+ }
$adminToken = new AdministratorToken();
- $this->setSubjectId($adminToken,(int)$data['id']);
+ $this->setSubjectId($adminToken,(int)$row['id']);
$adminToken->setKey($row['value']);
$this->setSubjectProperty($adminToken,'expiry', new DateTime($row['expires']));
$this->setSubjectProperty($adminToken, 'creationDate', (bool) $row['entered']);
diff --git a/tests/Integration/Domain/Repository/Fixtures/SubscriberFixture.php b/tests/Integration/Domain/Repository/Fixtures/SubscriberFixture.php
index c9641d5..42623f6 100644
--- a/tests/Integration/Domain/Repository/Fixtures/SubscriberFixture.php
+++ b/tests/Integration/Domain/Repository/Fixtures/SubscriberFixture.php
@@ -35,17 +35,20 @@ public function load(ObjectManager $manager): void
$subscriber = new Subscriber();
$this->setSubjectId($subscriber,(int)$row['id']);
- $this->setSubjectProperty($subscriber,'creationDate', new DateTime($row['entered']));
- $this->setSubjectProperty($subscriber,'modificationDate', new DateTime($row['modified']));
+
$subscriber->setEmail($row['email']);
$subscriber->setConfirmed((bool) $row['confirmed']);
$subscriber->setBlacklisted((bool) $row['blacklisted']);
$subscriber->setBounceCount((int) $row['bouncecount']);
- $subscriber->setUniqueId($row['uniqueid']);
$subscriber->setHtmlEmail((bool) $row['htmlemail']);
$subscriber->setDisabled((bool) $row['disabled']);
$subscriber->setExtraData($row['extradata']);
+
$manager->persist($subscriber);
+ // avoid pre-persist
+ $subscriber->setUniqueId($row['uniqueid']);
+ $this->setSubjectProperty($subscriber,'creationDate', new DateTime($row['entered']));
+ $this->setSubjectProperty($subscriber,'modificationDate', new DateTime($row['modified']));
}
fclose($handle);
diff --git a/tests/Integration/Domain/Repository/Fixtures/SubscriberListFixture.php b/tests/Integration/Domain/Repository/Fixtures/SubscriberListFixture.php
index 983628c..a41734f 100644
--- a/tests/Integration/Domain/Repository/Fixtures/SubscriberListFixture.php
+++ b/tests/Integration/Domain/Repository/Fixtures/SubscriberListFixture.php
@@ -30,10 +30,16 @@ public function load(ObjectManager $manager): void
$headers = fgetcsv($handle);
+ $adminRepository = $manager->getRepository(Administrator::class);
+
while (($data = fgetcsv($handle)) !== false) {
$row = array_combine($headers, $data);
- $admin = new Administrator();
- $this->setSubjectId($admin,(int)$row['owner']);
+ $admin = $adminRepository->find($row['owner']);
+ if ($admin === null) {
+ $admin = new Administrator();
+ $this->setSubjectId($admin,(int)$row['owner']);
+ $manager->persist($admin);
+ }
$subscriberList = new SubscriberList();
$this->setSubjectId($subscriberList,(int)$row['id']);
@@ -47,7 +53,6 @@ public function load(ObjectManager $manager): void
$subscriberList->setCategory($row['category']);
$subscriberList->setOwner($admin);
- $manager->persist($admin);
$manager->persist($subscriberList);
}
diff --git a/tests/Integration/Domain/Repository/Fixtures/SubscriptionFixture.php b/tests/Integration/Domain/Repository/Fixtures/SubscriptionFixture.php
index 7f5e08b..12779d4 100644
--- a/tests/Integration/Domain/Repository/Fixtures/SubscriptionFixture.php
+++ b/tests/Integration/Domain/Repository/Fixtures/SubscriptionFixture.php
@@ -42,11 +42,13 @@ public function load(ObjectManager $manager): void
$subscriberList = $subscriberListRepository->find((int)$row['listid']);
$subscription = new Subscription();
- $this->setSubjectProperty($subscription,'subscriber', $subscriber);
- $this->setSubjectProperty($subscription,'subscriberList', $subscriberList);
+ $subscriberList->addSubscription($subscription);
+ $subscriber->addSubscription($subscription);
+
+ $manager->persist($subscription);
+
$this->setSubjectProperty($subscription,'creationDate', new DateTime($row['entered']));
$this->setSubjectProperty($subscription,'modificationDate', new DateTime($row['modified']));
- $manager->persist($subscription);
}
fclose($handle);
diff --git a/tests/Integration/Domain/Repository/Messaging/SubscriberListRepositoryTest.php b/tests/Integration/Domain/Repository/Messaging/SubscriberListRepositoryTest.php
index 622968d..9f77ca0 100644
--- a/tests/Integration/Domain/Repository/Messaging/SubscriberListRepositoryTest.php
+++ b/tests/Integration/Domain/Repository/Messaging/SubscriberListRepositoryTest.php
@@ -8,6 +8,7 @@
use Doctrine\ORM\Tools\SchemaTool;
use PhpList\Core\Domain\Model\Identity\Administrator;
use PhpList\Core\Domain\Model\Messaging\SubscriberList;
+use PhpList\Core\Domain\Model\Subscription\Subscriber;
use PhpList\Core\Domain\Model\Subscription\Subscription;
use PhpList\Core\Domain\Repository\Identity\AdministratorRepository;
use PhpList\Core\Domain\Repository\Messaging\SubscriberListRepository;
@@ -31,9 +32,10 @@ class SubscriberListRepositoryTest extends KernelTestCase
use DatabaseTestTrait;
use SimilarDatesAssertionTrait;
- private ?AdministratorRepository $administratorRepository = null;
- private ?SubscriberRepository $subscriberRepository = null;
- private ?SubscriptionRepository $subscriptionRepository = null;
+ private SubscriberListRepository $subscriberListRepository;
+ private AdministratorRepository $administratorRepository;
+ private SubscriberRepository $subscriberRepository;
+ private SubscriptionRepository $subscriptionRepository;
protected function setUp(): void
{
@@ -161,16 +163,15 @@ public function testFindByOwnerIgnoresSubscriberListFromOtherOwner()
public function testFindsAssociatedSubscriptions()
{
- $this->loadFixtures([SubscriptionFixture::class]);
+ $this->loadFixtures([SubscriberListFixture::class, SubscriberFixture::class, SubscriptionFixture::class]);
$id = 2;
- /** @var SubscriberList $model */
- $model = $this->subscriberListRepository->find($id);
- $subscriptions = $model->getSubscriptions();
+ /** @var Subscription[] $model */
+ $subscriptions = $this->subscriptionRepository->findBySubscriberList($id);
- self::assertFalse($subscriptions->isEmpty());
+ self::assertNotEmpty($subscriptions);
/** @var Subscription $firstSubscription */
- $firstSubscription = $subscriptions->first();
+ $firstSubscription = $subscriptions[0];
self::assertInstanceOf(Subscription::class, $firstSubscription);
$expectedSubscriberId = 1;
self::assertSame($expectedSubscriberId, $firstSubscription->getSubscriber()->getId());
@@ -181,14 +182,13 @@ public function testFindsAssociatedSubscribers()
$this->loadFixtures([SubscriberListFixture::class, SubscriberFixture::class, SubscriptionFixture::class]);
$id = 2;
- /** @var SubscriberList $model */
- $model = $this->subscriberListRepository->find($id);
- $subscribers = $model->getSubscribers();
+ /** @var Subscriber[] $model */
+ $subscribers = $this->subscriberRepository->getSubscribersBySubscribedListId($id);
$expectedSubscriber = $this->subscriberRepository->find(1);
$unexpectedSubscriber = $this->subscriberRepository->find(3);
- self::assertTrue($subscribers->contains($expectedSubscriber));
- self::assertFalse($subscribers->contains($unexpectedSubscriber));
+ self::assertTrue(in_array($expectedSubscriber, $subscribers, true));
+ self::assertFalse(in_array($unexpectedSubscriber, $subscribers, true));
}
public function testRemoveAlsoRemovesAssociatedSubscriptions()
@@ -199,14 +199,16 @@ public function testRemoveAlsoRemovesAssociatedSubscriptions()
$id = 2;
/** @var SubscriberList $model */
- $model = $this->subscriberListRepository->find($id);
+ $subscriberList = $this->subscriberListRepository->findWithSubscription($id);
- $numberOfAssociatedSubscriptions = count($model->getSubscriptions());
+ $numberOfAssociatedSubscriptions = count($subscriberList->getSubscriptions());
self::assertGreaterThan(0, $numberOfAssociatedSubscriptions);
- $this->subscriberListRepository->remove($model);
+ $this->entityManager->remove($subscriberList);
+ $this->entityManager->flush();
$newNumberOfSubscriptions = count($this->subscriptionRepository->findAll());
+
$numberOfRemovedSubscriptions = $initialNumberOfSubscriptions - $newNumberOfSubscriptions;
self::assertSame($numberOfAssociatedSubscriptions, $numberOfRemovedSubscriptions);
}
diff --git a/tests/Integration/Domain/Repository/Subscription/SubscriberRepositoryTest.php b/tests/Integration/Domain/Repository/Subscription/SubscriberRepositoryTest.php
index 3b56efc..fc7b50f 100644
--- a/tests/Integration/Domain/Repository/Subscription/SubscriberRepositoryTest.php
+++ b/tests/Integration/Domain/Repository/Subscription/SubscriberRepositoryTest.php
@@ -5,8 +5,11 @@
namespace PhpList\Core\Tests\Integration\Domain\Repository\Subscription;
use DateTime;
+use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\ORM\Tools\SchemaTool;
+use PhpList\Core\Domain\Model\Identity\Administrator;
use PhpList\Core\Domain\Model\Subscription\Subscriber;
use PhpList\Core\Domain\Model\Subscription\Subscription;
use PhpList\Core\Domain\Repository\Messaging\SubscriberListRepository;
@@ -14,6 +17,7 @@
use PhpList\Core\Domain\Repository\Subscription\SubscriptionRepository;
use PhpList\Core\TestingSupport\Traits\DatabaseTestTrait;
use PhpList\Core\TestingSupport\Traits\SimilarDatesAssertionTrait;
+use PhpList\Core\Tests\Integration\Domain\Repository\Fixtures\AdministratorFixture;
use PhpList\Core\Tests\Integration\Domain\Repository\Fixtures\SubscriberFixture;
use PhpList\Core\Tests\Integration\Domain\Repository\Fixtures\SubscriberListFixture;
use PhpList\Core\Tests\Integration\Domain\Repository\Fixtures\SubscriptionFixture;
@@ -175,11 +179,15 @@ public function testFindOneByEmailIgnoresSubscriberWithNonMatchingEmail()
public function testFindsAssociatedSubscriptions()
{
- $this->loadFixtures([SubscriberFixture::class, SubscriberListFixture::class, SubscriptionFixture::class]);
+ $this->loadFixtures([
+ AdministratorFixture::class,
+ SubscriberFixture::class,
+ SubscriberListFixture::class,
+ SubscriptionFixture::class,
+ ]);
$id = 1;
- /** @var Subscriber $model */
- $model = $this->subscriberRepository->find($id);
+ $model = $this->subscriberRepository->findSubscriberWithSubscriptions($id);
$subscriptions = $model->getSubscriptions();
self::assertFalse($subscriptions->isEmpty());
@@ -196,13 +204,16 @@ public function testFindsAssociatedSubscribedLists()
$id = 1;
/** @var Subscriber $model */
- $model = $this->subscriberRepository->find($id);
- $subscribedLists = $model->getSubscribedLists();
+ $model = $this->subscriberRepository->findSubscriberWithSubscriptions($id);
+ $subscriberLists = new ArrayCollection();
+ foreach ($model->getSubscriptions() as $subscription) {
+ $subscriberLists->add($subscription->getSubscriberList());
+ }
$expectedList = $this->subscriberListRepository->find(2);
$unexpectedList = $this->subscriberListRepository->find(1);
- self::assertTrue($subscribedLists->contains($expectedList));
- self::assertFalse($subscribedLists->contains($unexpectedList));
+ self::assertTrue($subscriberLists->contains($expectedList));
+ self::assertFalse($subscriberLists->contains($unexpectedList));
}
public function testRemoveAlsoRemovesAssociatedSubscriptions()
@@ -213,7 +224,7 @@ public function testRemoveAlsoRemovesAssociatedSubscriptions()
$id = 2;
/** @var Subscriber $model */
- $model = $this->subscriberRepository->find($id);
+ $model = $this->subscriberRepository->findSubscriberWithSubscriptions($id);
$numberOfAssociatedSubscriptions = count($model->getSubscriptions());
self::assertGreaterThan(0, $numberOfAssociatedSubscriptions);
diff --git a/tests/Integration/Domain/Repository/Subscription/SubscriptionRepositoryTest.php b/tests/Integration/Domain/Repository/Subscription/SubscriptionRepositoryTest.php
index c209575..a3099dc 100644
--- a/tests/Integration/Domain/Repository/Subscription/SubscriptionRepositoryTest.php
+++ b/tests/Integration/Domain/Repository/Subscription/SubscriptionRepositoryTest.php
@@ -54,7 +54,7 @@ protected function tearDown(): void
public function testFindAllReadsModelsFromDatabase()
{
- $this->loadFixtures([SubscriptionFixture::class]);
+ $this->loadFixtures([SubscriberFixture::class, SubscriberListFixture::class, SubscriptionFixture::class]);
$creationDate = new DateTime('2016-07-22 15:01:17');
$modificationDate = new DateTime('2016-08-23 19:50:43');
@@ -72,7 +72,7 @@ public function testFindAllReadsModelsFromDatabase()
public function testCreatesSubscriberAssociationAsProxy()
{
- $this->loadFixtures([SubscriberFixture::class, SubscriptionFixture::class]);
+ $this->loadFixtures([SubscriberFixture::class, SubscriberListFixture::class, SubscriptionFixture::class]);
$subscriberId = 1;
/** @var Subscription $model */
@@ -84,20 +84,6 @@ public function testCreatesSubscriberAssociationAsProxy()
self::assertSame($subscriberId, $subscriber->getId());
}
- public function testCreatesSubscriberListAssociationAsProxy()
- {
- $this->loadFixtures([SubscriberFixture::class, SubscriptionFixture::class]);
-
- $subscriberListId = 2;
- /** @var Subscription $model */
- $model = $this->subscriberRepository->findAll()[0];
- $subscriberList = $model->getSubscriberList();
-
- self::assertInstanceOf(SubscriberList::class, $subscriberList);
- self::assertInstanceOf(Proxy::class, $subscriberList);
- self::assertSame($subscriberListId, $subscriberList->getId());
- }
-
public function testCreationDateOfNewModelIsSetToNowOnPersist()
{
$this->loadFixtures([SubscriberFixture::class, SubscriberListFixture::class]);
@@ -118,7 +104,7 @@ public function testCreationDateOfNewModelIsSetToNowOnPersist()
public function testModificationDateOfNewModelIsSetToNowOnPersist()
{
- $this->loadFixtures([SubscriberFixture::class, SubscriberLIstFixture::class]);
+ $this->loadFixtures([SubscriberFixture::class, SubscriberListFixture::class]);
$model = new Subscription();
/** @var Subscriber $subscriber */
@@ -136,7 +122,7 @@ public function testModificationDateOfNewModelIsSetToNowOnPersist()
public function testFindBySubscriberFindsSubscriptionOnlyWithTheGivenSubscriber()
{
- $this->loadFixtures([SubscriberFixture::class, SubscriptionFixture::class]);
+ $this->loadFixtures([SubscriberFixture::class, SubscriberListFixture::class, SubscriptionFixture::class]);
/** @var Subscriber $subscriber */
$subscriber = $this->subscriberRepository->find(1);
@@ -151,7 +137,7 @@ public function testFindBySubscriberFindsSubscriptionOnlyWithTheGivenSubscriber(
public function testFindBySubscriberListFindsSubscriptionOnlyWithTheGivenSubscriberList()
{
- $this->loadFixtures([SubscriberFixture::class, SubscriptionFixture::class]);
+ $this->loadFixtures([SubscriberFixture::class, SubscriberListFixture::class, SubscriptionFixture::class]);
/** @var SubscriberList $subscriberList */
$subscriberList = $this->subscriberListRepository->find(1);
@@ -184,7 +170,7 @@ public function testSavePersistsAndFlushesModel()
public function testRemoveRemovesModel()
{
- $this->loadFixtures([SubscriptionFixture::class]);
+ $this->loadFixtures([SubscriberFixture::class, SubscriberListFixture::class, SubscriptionFixture::class]);
/** @var Subscription[] $allModels */
$allModels = $this->subscriptionRepository->findAll();
diff --git a/tests/Integration/EmptyStartPageBundle/Controller/DefaultControllerTest.php b/tests/Integration/EmptyStartPageBundle/Controller/DefaultControllerTest.php
index 06f5281..3e86216 100644
--- a/tests/Integration/EmptyStartPageBundle/Controller/DefaultControllerTest.php
+++ b/tests/Integration/EmptyStartPageBundle/Controller/DefaultControllerTest.php
@@ -32,8 +32,6 @@ public function testIndexActionReturnsResponseWithHelloWorld(): void
$response = $client->getResponse();
- dump($response->getContent());
-
self::assertTrue($response->isSuccessful());
self::assertStringContainsString(
'This page has been intentionally left empty.',
diff --git a/tests/Integration/Routing/ExtraLoaderTest.php b/tests/Integration/Routing/ExtraLoaderTest.php
index 73534ae..542c6a8 100644
--- a/tests/Integration/Routing/ExtraLoaderTest.php
+++ b/tests/Integration/Routing/ExtraLoaderTest.php
@@ -36,9 +36,9 @@ protected function setUp(): void
$this->kernel->boot();
$locator = new FileLocator([
+ $this->kernel->getProjectDir() . '/src/EmptyStartPageBundle/Controller',
+ $this->kernel->getProjectDir() . '/src/EmptyStartPageBundle',
$this->kernel->getProjectDir() . '/config',
- $this->kernel->getProjectDir() . '/composer.json',
- $this->kernel->getProjectDir() . '/src/EmptyStartPageBundle/Controller/'
]);
$attributeLoader = new AttributeRouteControllerLoader();
@@ -61,8 +61,11 @@ protected function tearDown(): void
Bootstrap::purgeInstance();
}
- public function testLoadReturnsRouteCollection(): void
+ public function loadReturnsRouteCollection(): void
{
- self::assertInstanceOf(RouteCollection::class, $this->subject->load('', 'extra'));
+ $routeCollection = $this->subject->load('@EmptyStartPageBundle/Controller/', 'extra');
+
+ self::assertInstanceOf(RouteCollection::class, $routeCollection);
+ self::assertNotNull($routeCollection->get('empty_start_page'));
}
}
diff --git a/tests/Integration/Security/AuthenticationTest.php b/tests/Integration/Security/AuthenticationTest.php
index f873a45..dfb5508 100644
--- a/tests/Integration/Security/AuthenticationTest.php
+++ b/tests/Integration/Security/AuthenticationTest.php
@@ -78,7 +78,7 @@ public function testAuthenticateByApiKeyWithValidApiKeyAndDisabledAdministratorR
public function testAuthenticateByApiKeyWithValidApiKeyForInexistentAdministratorReturnsNull()
{
- $this->loadFixtures([AdministratorTokenWithAdministratorFixture::class]);
+ $this->loadFixtures([AdministratorFixture::class, AdministratorTokenWithAdministratorFixture::class]);
$apiKey = 'cfdf64eecbbf336628b0f3071adba763';
$request = new Request();
@@ -91,7 +91,7 @@ public function testAuthenticateByApiKeyWithValidApiKeyForInexistentAdministrato
public function testAuthenticateByApiKeyWithValidApiKeyForNonSuperUserAdministratorReturnsNull()
{
- $this->loadFixtures([AdministratorTokenWithAdministratorFixture::class]);
+ $this->loadFixtures([AdministratorFixture::class, AdministratorTokenWithAdministratorFixture::class]);
$apiKey = 'cfdf64eecbbf336628b0f3071adba764';
$request = new Request();
diff --git a/tests/System/ApplicationBundle/PhpListApplicationBundleTest.php b/tests/System/ApplicationBundle/PhpListApplicationBundleTest.php
index 24492a5..aeac196 100644
--- a/tests/System/ApplicationBundle/PhpListApplicationBundleTest.php
+++ b/tests/System/ApplicationBundle/PhpListApplicationBundleTest.php
@@ -22,6 +22,10 @@ class PhpListApplicationBundleTest extends TestCase
protected function setUp(): void
{
parent::setUp();
+
+ putenv('APP_ENV=test');
+ $_ENV['APP_ENV'] = 'test';
+ $_SERVER['APP_ENV'] = 'test';
$this->httpClient = new Client(['http_errors' => false]);
}
@@ -32,40 +36,14 @@ protected function tearDown(): void
parent::tearDown();
}
- /**
- * @return string[][]
- */
- public function environmentDataProvider(): array
+ public function testHomepageReturnsSuccess(): void
{
- return [
- 'test' => ['test'],
- 'dev' => ['dev'],
- ];
- }
-
- /**
- * @param string $environment
- * @dataProvider environmentDataProvider
- */
- public function testHomepageReturnsSuccess(string $environment): void
- {
- $this->startSymfonyServer($environment);
-
- $response = $this->httpClient->get('/', ['base_uri' => $this->getBaseUrl()]);
+ $this->startSymfonyServer();
+ $response = $this->httpClient->get('/api/v2', [
+ 'base_uri' => $this->getBaseUrl(),
+ ]);
self::assertSame(200, $response->getStatusCode());
- }
-
- /**
- * @param string $environment
- * @dataProvider environmentDataProvider
- */
- public function testHomepageReturnsDummyContent(string $environment): void
- {
- $this->startSymfonyServer($environment);
-
- $response = $this->httpClient->get('/', ['base_uri' => $this->getBaseUrl()]);
-
self::assertStringContainsString(
'This page has been intentionally left empty.',
$response->getBody()->getContents()
diff --git a/tests/Unit/Domain/Model/Messaging/SubscriberListTest.php b/tests/Unit/Domain/Model/Messaging/SubscriberListTest.php
index b07e52c..eb8209c 100644
--- a/tests/Unit/Domain/Model/Messaging/SubscriberListTest.php
+++ b/tests/Unit/Domain/Model/Messaging/SubscriberListTest.php
@@ -10,6 +10,8 @@
use PhpList\Core\Domain\Model\Identity\Administrator;
use PhpList\Core\Domain\Model\Interfaces\DomainModel;
use PhpList\Core\Domain\Model\Messaging\SubscriberList;
+use PhpList\Core\Domain\Model\Subscription\Subscriber;
+use PhpList\Core\Domain\Model\Subscription\Subscription;
use PhpList\Core\TestingSupport\Traits\ModelTestTrait;
use PhpList\Core\TestingSupport\Traits\SimilarDatesAssertionTrait;
use PHPUnit\Framework\TestCase;
@@ -24,160 +26,160 @@ class SubscriberListTest extends TestCase
use ModelTestTrait;
use SimilarDatesAssertionTrait;
- private SubscriberList $subject;
+ private SubscriberList $subscriberList;
protected function setUp(): void
{
- $this->subject = new SubscriberList();
+ $this->subscriberList = new SubscriberList();
}
public function testIsDomainModel(): void
{
- self::assertInstanceOf(DomainModel::class, $this->subject);
+ self::assertInstanceOf(DomainModel::class, $this->subscriberList);
}
public function testGetIdReturnsId(): void
{
$id = 123456;
- $this->setSubjectId($this->subject, $id);
+ $this->setSubjectId($this->subscriberList, $id);
- self::assertSame($id, $this->subject->getId());
+ self::assertSame($id, $this->subscriberList->getId());
}
public function testGetCreationDateInitiallyReturnsNull(): void
{
- self::assertNull($this->subject->getCreationDate());
+ self::assertNull($this->subscriberList->getCreationDate());
}
public function testUpdateCreationDateSetsCreationDateToNow(): void
{
- $this->subject->updateCreationDate();
+ $this->subscriberList->updateCreationDate();
- self::assertSimilarDates(new DateTime(), $this->subject->getCreationDate());
+ self::assertSimilarDates(new DateTime(), $this->subscriberList->getCreationDate());
}
public function testGetModificationDateInitiallyReturnsNull(): void
{
- self::assertNull($this->subject->getModificationDate());
+ self::assertNull($this->subscriberList->getModificationDate());
}
public function testUpdateModificationDateSetsModificationDateToNow(): void
{
- $this->subject->updateModificationDate();
+ $this->subscriberList->updateModificationDate();
- self::assertSimilarDates(new DateTime(), $this->subject->getModificationDate());
+ self::assertSimilarDates(new DateTime(), $this->subscriberList->getModificationDate());
}
public function testGetNameInitiallyReturnsEmptyString(): void
{
- self::assertSame('', $this->subject->getName());
+ self::assertSame('', $this->subscriberList->getName());
}
public function testSetNameSetsName(): void
{
$value = 'phpList releases';
- $this->subject->setName($value);
+ $this->subscriberList->setName($value);
- self::assertSame($value, $this->subject->getName());
+ self::assertSame($value, $this->subscriberList->getName());
}
public function testGetDescriptionInitiallyReturnsEmptyString(): void
{
- self::assertSame('', $this->subject->getDescription());
+ self::assertSame('', $this->subscriberList->getDescription());
}
public function testSetDescriptionSetsDescription(): void
{
$value = 'Subscribe to this list when you would like to be notified of new phpList releases.';
- $this->subject->setDescription($value);
+ $this->subscriberList->setDescription($value);
- self::assertSame($value, $this->subject->getDescription());
+ self::assertSame($value, $this->subscriberList->getDescription());
}
public function testGetListPositionInitiallyReturnsZero(): void
{
- self::assertSame(0, $this->subject->getListPosition());
+ self::assertSame(0, $this->subscriberList->getListPosition());
}
public function testSetListPositionSetsListPosition(): void
{
$value = 123456;
- $this->subject->setListPosition($value);
+ $this->subscriberList->setListPosition($value);
- self::assertSame($value, $this->subject->getListPosition());
+ self::assertSame($value, $this->subscriberList->getListPosition());
}
public function testGetSubjectPrefixInitiallyReturnsEmptyString(): void
{
- self::assertSame('', $this->subject->getSubjectPrefix());
+ self::assertSame('', $this->subscriberList->getSubjectPrefix());
}
public function testSetSubjectPrefixSetsSubjectPrefix(): void
{
$value = 'Club-Mate';
- $this->subject->setSubjectPrefix($value);
+ $this->subscriberList->setSubjectPrefix($value);
- self::assertSame($value, $this->subject->getSubjectPrefix());
+ self::assertSame($value, $this->subscriberList->getSubjectPrefix());
}
public function testIsPublicInitiallyReturnsFalse(): void
{
- self::assertFalse($this->subject->isPublic());
+ self::assertFalse($this->subscriberList->isPublic());
}
public function testSetPublicSetsPublic(): void
{
- $this->subject->setPublic(true);
+ $this->subscriberList->setPublic(true);
- self::assertTrue($this->subject->isPublic());
+ self::assertTrue($this->subscriberList->isPublic());
}
public function testGetCategoryInitiallyReturnsEmptyString(): void
{
- self::assertSame('', $this->subject->getCategory());
+ self::assertSame('', $this->subscriberList->getCategory());
}
public function testSetCategorySetsCategory(): void
{
$value = 'Club-Mate';
- $this->subject->setCategory($value);
+ $this->subscriberList->setCategory($value);
- self::assertSame($value, $this->subject->getCategory());
+ self::assertSame($value, $this->subscriberList->getCategory());
}
public function testGetOwnerInitiallyReturnsNull(): void
{
- self::assertNull($this->subject->getOwner());
+ self::assertNull($this->subscriberList->getOwner());
}
public function testSetOwnerSetsOwner(): void
{
$model = new Administrator();
- $this->subject->setOwner($model);
+ $this->subscriberList->setOwner($model);
- self::assertSame($model, $this->subject->getOwner());
+ self::assertSame($model, $this->subscriberList->getOwner());
}
public function testGetSubscriptionsByDefaultReturnsEmptyCollection(): void
{
- $result = $this->subject->getSubscriptions();
+ $result = $this->subscriberList->getSubscriptions();
self::assertInstanceOf(Collection::class, $result);
self::assertTrue($result->isEmpty());
}
- public function testSetSubscriptionsSetsSubscriptions(): void
+ public function testAddSubscriptionsSetsSubscriptions(): void
{
- $subscriptions = new ArrayCollection();
+ $subscription = new Subscription();
- $this->subject->setSubscriptions($subscriptions);
+ $this->subscriberList->addSubscription($subscription);
- self::assertSame($subscriptions, $this->subject->getSubscriptions());
+ self::assertTrue($this->subscriberList->getSubscriptions()->contains($subscription));
}
public function testGetSubscribersByDefaultReturnsEmptyCollection(): void
{
- $result = $this->subject->getSubscribers();
+ $result = $this->subscriberList->getSubscribers();
self::assertInstanceOf(Collection::class, $result);
self::assertTrue($result->isEmpty());
@@ -185,10 +187,12 @@ public function testGetSubscribersByDefaultReturnsEmptyCollection(): void
public function testSetSubscribersSetsSubscribers(): void
{
- $subscriptions = new ArrayCollection();
+ $subscriber = new Subscriber();
+ $subscription = new Subscription();
+ $subscription->setSubscriber($subscriber);
- $this->subject->setSubscribers($subscriptions);
+ $this->subscriberList->addSubscription($subscription);
- self::assertSame($subscriptions, $this->subject->getSubscribers());
+ self::assertTrue($this->subscriberList->getSubscribers()->contains($subscriber));
}
}
diff --git a/tests/Unit/Domain/Model/Subscription/SubscriberTest.php b/tests/Unit/Domain/Model/Subscription/SubscriberTest.php
index edc3222..edac579 100644
--- a/tests/Unit/Domain/Model/Subscription/SubscriberTest.php
+++ b/tests/Unit/Domain/Model/Subscription/SubscriberTest.php
@@ -7,7 +7,9 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use PhpList\Core\Domain\Model\Interfaces\DomainModel;
+use PhpList\Core\Domain\Model\Messaging\SubscriberList;
use PhpList\Core\Domain\Model\Subscription\Subscriber;
+use PhpList\Core\Domain\Model\Subscription\Subscription;
use PhpList\Core\TestingSupport\Traits\ModelTestTrait;
use PhpList\Core\TestingSupport\Traits\SimilarDatesAssertionTrait;
use PHPUnit\Framework\TestCase;
@@ -22,171 +24,171 @@ class SubscriberTest extends TestCase
use ModelTestTrait;
use SimilarDatesAssertionTrait;
- private Subscriber $subject;
+ private Subscriber $subscriber;
protected function setUp(): void
{
- $this->subject = new Subscriber();
+ $this->subscriber = new Subscriber();
}
public function testIsDomainModel(): void
{
- self::assertInstanceOf(DomainModel::class, $this->subject);
+ self::assertInstanceOf(DomainModel::class, $this->subscriber);
}
public function testGetIdReturnsId(): void
{
$id = 123456;
- $this->setSubjectId($this->subject, $id);
+ $this->setSubjectId($this->subscriber, $id);
- self::assertSame($id, $this->subject->getId());
+ self::assertSame($id, $this->subscriber->getId());
}
public function testGetCreationDateInitiallyReturnsNull(): void
{
- self::assertNull($this->subject->getCreationDate());
+ self::assertNull($this->subscriber->getCreationDate());
}
public function testUpdateCreationDateSetsCreationDateToNow(): void
{
- $this->subject->updateCreationDate();
+ $this->subscriber->updateCreationDate();
- self::assertSimilarDates(new \DateTime(), $this->subject->getCreationDate());
+ self::assertSimilarDates(new \DateTime(), $this->subscriber->getCreationDate());
}
public function testGetModificationDateInitiallyReturnsNull(): void
{
- self::assertNull($this->subject->getModificationDate());
+ self::assertNull($this->subscriber->getModificationDate());
}
public function testUpdateModificationDateSetsModificationDateToNow(): void
{
- $this->subject->updateModificationDate();
+ $this->subscriber->updateModificationDate();
- self::assertSimilarDates(new \DateTime(), $this->subject->getModificationDate());
+ self::assertSimilarDates(new \DateTime(), $this->subscriber->getModificationDate());
}
public function testGetEmailInitiallyReturnsEmptyString(): void
{
- self::assertSame('', $this->subject->getEmail());
+ self::assertSame('', $this->subscriber->getEmail());
}
public function testSetEmailSetsEmail(): void
{
$value = 'Club-Mate';
- $this->subject->setEmail($value);
+ $this->subscriber->setEmail($value);
- self::assertSame($value, $this->subject->getEmail());
+ self::assertSame($value, $this->subscriber->getEmail());
}
public function testIsConfirmedInitiallyReturnsFalse(): void
{
- self::assertFalse($this->subject->isConfirmed());
+ self::assertFalse($this->subscriber->isConfirmed());
}
public function testSetConfirmedSetsConfirmed(): void
{
- $this->subject->setConfirmed(true);
+ $this->subscriber->setConfirmed(true);
- self::assertTrue($this->subject->isConfirmed());
+ self::assertTrue($this->subscriber->isConfirmed());
}
public function testIsBlacklistedInitiallyReturnsFalse(): void
{
- self::assertFalse($this->subject->isBlacklisted());
+ self::assertFalse($this->subscriber->isBlacklisted());
}
public function testSetBlacklistedSetsBlacklisted(): void
{
- $this->subject->setBlacklisted(true);
+ $this->subscriber->setBlacklisted(true);
- self::assertTrue($this->subject->isBlacklisted());
+ self::assertTrue($this->subscriber->isBlacklisted());
}
public function testGetBounceCountInitiallyReturnsZero(): void
{
- self::assertSame(0, $this->subject->getBounceCount());
+ self::assertSame(0, $this->subscriber->getBounceCount());
}
public function testSetBounceCountSetsBounceCount(): void
{
$value = 123456;
- $this->subject->setBounceCount($value);
+ $this->subscriber->setBounceCount($value);
- self::assertSame($value, $this->subject->getBounceCount());
+ self::assertSame($value, $this->subscriber->getBounceCount());
}
public function testAddToBounceCountAddsToBounceCount(): void
{
$initialValue = 4;
- $this->subject->setBounceCount($initialValue);
+ $this->subscriber->setBounceCount($initialValue);
$delta = 2;
- $this->subject->addToBounceCount($delta);
+ $this->subscriber->addToBounceCount($delta);
- self::assertSame($initialValue + $delta, $this->subject->getBounceCount());
+ self::assertSame($initialValue + $delta, $this->subscriber->getBounceCount());
}
public function testGetUniqueIdInitiallyReturnsEmptyString(): void
{
- self::assertSame('', $this->subject->getUniqueId());
+ self::assertSame('', $this->subscriber->getUniqueId());
}
public function testSetUniqueIdSetsUniqueId(): void
{
$value = 'Club-Mate';
- $this->subject->setUniqueId($value);
+ $this->subscriber->setUniqueId($value);
- self::assertSame($value, $this->subject->getUniqueId());
+ self::assertSame($value, $this->subscriber->getUniqueId());
}
public function testGenerateUniqueIdGeneratesUniqueId(): void
{
- $this->subject->generateUniqueId();
+ $this->subscriber->generateUniqueId();
- self::assertMatchesRegularExpression('/^[0-9a-f]{32}$/', $this->subject->getUniqueId());
+ self::assertMatchesRegularExpression('/^[0-9a-f]{32}$/', $this->subscriber->getUniqueId());
}
public function testHasHtmlEmailInitiallyReturnsFalse(): void
{
- self::assertFalse($this->subject->hasHtmlEmail());
+ self::assertFalse($this->subscriber->hasHtmlEmail());
}
public function testSetHtmlEmailSetsWantsHtmlEmail(): void
{
- $this->subject->setHtmlEmail(true);
+ $this->subscriber->setHtmlEmail(true);
- self::assertTrue($this->subject->hasHtmlEmail());
+ self::assertTrue($this->subscriber->hasHtmlEmail());
}
public function testIsDisabledInitiallyReturnsFalse(): void
{
- self::assertFalse($this->subject->isDisabled());
+ self::assertFalse($this->subscriber->isDisabled());
}
public function testSetDisabledSetsDisabled(): void
{
- $this->subject->setDisabled(true);
+ $this->subscriber->setDisabled(true);
- self::assertTrue($this->subject->isDisabled());
+ self::assertTrue($this->subscriber->isDisabled());
}
public function testGetExtraDataInitiallyReturnsEmptyString(): void
{
- self::assertSame('', $this->subject->getExtraData());
+ self::assertSame('', $this->subscriber->getExtraData());
}
public function testSetExtraDataSetsExtraData(): void
{
$value = 'This is one of our favourite subscribers.';
- $this->subject->setExtraData($value);
+ $this->subscriber->setExtraData($value);
- self::assertSame($value, $this->subject->getExtraData());
+ self::assertSame($value, $this->subscriber->getExtraData());
}
public function testGetSubscriptionsByDefaultReturnsEmptyCollection(): void
{
- $result = $this->subject->getSubscriptions();
+ $result = $this->subscriber->getSubscriptions();
self::assertInstanceOf(Collection::class, $result);
self::assertTrue($result->isEmpty());
@@ -194,16 +196,18 @@ public function testGetSubscriptionsByDefaultReturnsEmptyCollection(): void
public function testSetSubscriptionsSetsSubscriptions(): void
{
- $subscriptions = new ArrayCollection();
+ $subscription = new Subscription();
- $this->subject->setSubscriptions($subscriptions);
+ $this->subscriber->addSubscription($subscription);
- self::assertSame($subscriptions, $this->subject->getSubscriptions());
+ $expectedSubscriptions = new ArrayCollection([$subscription]);
+
+ self::assertEquals($expectedSubscriptions, $this->subscriber->getSubscriptions());
}
public function testGetSubscribedListsByDefaultReturnsEmptyCollection(): void
{
- $result = $this->subject->getSubscribedLists();
+ $result = $this->subscriber->getSubscribedLists();
self::assertInstanceOf(Collection::class, $result);
self::assertTrue($result->isEmpty());
@@ -211,10 +215,14 @@ public function testGetSubscribedListsByDefaultReturnsEmptyCollection(): void
public function testSetSubscribedListsSetsSubscribedLists(): void
{
- $subscriptions = new ArrayCollection();
+ $subscriberList = new SubscriberList();
+ $subscription = new Subscription();
+ $subscription->setSubscriberList($subscriberList);
+
+ $this->subscriber->addSubscription($subscription);
- $this->subject->setSubscribedLists($subscriptions);
+ $expectedSubscribedLists = new ArrayCollection([$subscriberList]);
- self::assertSame($subscriptions, $this->subject->getSubscribedLists());
+ self::assertEquals($expectedSubscribedLists, $this->subscriber->getSubscribedLists());
}
}