Skip to content

Commit a46b1b3

Browse files
committed
Fix tests
1 parent 60a5d08 commit a46b1b3

File tree

11 files changed

+121
-39
lines changed

11 files changed

+121
-39
lines changed

src/Domain/Identity/Model/AdministratorToken.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,8 @@ public function generateKey(): self
114114
return $this;
115115
}
116116

117-
public function getAdministrator(): Administrator|Proxy
117+
public function getAdministrator(): Administrator
118118
{
119119
return $this->administrator;
120120
}
121-
122-
public function setAdministrator(Administrator $administrator): self
123-
{
124-
$this->administrator = $administrator;
125-
return $this;
126-
}
127121
}

src/Domain/Messaging/Model/Message.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Message implements DomainModel, Identity, ModificationDate, OwnableInterfa
3333
private ?int $id = null;
3434

3535
#[ORM\Column(name: 'modified', type: 'datetime', nullable: false)]
36-
private DateTimeImmutable $updatedAt;
36+
private DateTime $updatedAt;
3737

3838
#[ORM\Embedded(class: MessageFormat::class, columnPrefix: false)]
3939
private MessageFormat $format;
@@ -82,7 +82,7 @@ public function __construct(
8282
$this->owner = $owner;
8383
$this->template = $template;
8484
$this->listMessages = new ArrayCollection();
85-
$this->updatedAt = new DateTimeImmutable();
85+
$this->updatedAt = new DateTime();
8686
$this->metadata->setEntered(new DateTime());
8787
}
8888

@@ -91,16 +91,15 @@ public function getId(): ?int
9191
return $this->id;
9292
}
9393

94-
/** @SuppressWarnings(PHPMD.StaticAccess) */
9594
public function getUpdatedAt(): DateTime
9695
{
97-
return DateTime::createFromImmutable($this->updatedAt);
96+
return $this->updatedAt;
9897
}
9998

10099
#[ORM\PreUpdate]
101100
public function touchUpdatedTimestamp(): void
102101
{
103-
$this->updatedAt = new DateTimeImmutable();
102+
$this->updatedAt = new DateTime;
104103
}
105104

106105
public function getFormat(): MessageFormat

src/Domain/Subscription/Model/Subscriber.php

Lines changed: 103 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@
1919
* campaigns for those subscriber lists.
2020
* @author Oliver Klee <[email protected]>
2121
* @author Tatevik Grigoryan <[email protected]>
22+
* @SuppressWarnings(TooManyFields)
2223
*/
2324
#[ORM\Entity(repositoryClass: SubscriberRepository::class)]
2425
#[ORM\Table(name: 'phplist_user_user')]
2526
#[ORM\Index(name: 'idxuniqid', columns: ['uniqid'])]
2627
#[ORM\Index(name: 'enteredindex', columns: ['entered'])]
2728
#[ORM\Index(name: 'confidx', columns: ['confirmed'])]
2829
#[ORM\Index(name: 'blidx', columns: ['blacklisted'])]
30+
#[ORM\Index(name: 'optidx', columns: ['optedin'])]
31+
#[ORM\Index(name: 'uuididx', columns: ['uuid'])]
32+
#[ORM\Index(name: 'foreignkey', columns: ['foreignkey'])]
33+
#[ORM\UniqueConstraint(name: 'email', columns: ['email'])]
2934
#[ORM\HasLifecycleCallbacks]
3035
class Subscriber implements DomainModel, Identity, CreationDate, ModificationDate
3136
{
@@ -37,8 +42,8 @@ class Subscriber implements DomainModel, Identity, CreationDate, ModificationDat
3742
#[ORM\Column(name: 'entered', type: 'datetime', nullable: true)]
3843
protected ?DateTime $createdAt = null;
3944

40-
#[ORM\Column(name: 'modified', type: 'datetime')]
41-
private ?DateTime $updatedAt = null;
45+
#[ORM\Column(name: 'modified', type: 'datetime', nullable: false)]
46+
private DateTime $updatedAt;
4247

4348
#[ORM\Column(unique: true)]
4449
private string $email = '';
@@ -52,7 +57,7 @@ class Subscriber implements DomainModel, Identity, CreationDate, ModificationDat
5257
#[ORM\Column(name: 'bouncecount', type: 'integer')]
5358
private int $bounceCount = 0;
5459

55-
#[ORM\Column(name: 'uniqid', unique: true)]
60+
#[ORM\Column(name: 'uniqid', type: 'string', length: 255, nullable: true)]
5661
private string $uniqueId = '';
5762

5863
#[ORM\Column(name: 'htmlemail', type: 'boolean')]
@@ -61,8 +66,8 @@ class Subscriber implements DomainModel, Identity, CreationDate, ModificationDat
6166
#[ORM\Column(type: 'boolean')]
6267
private bool $disabled = false;
6368

64-
#[ORM\Column(name: 'extradata', type: 'text')]
65-
private ?string $extraData;
69+
#[ORM\Column(name: 'extradata', type: 'text', nullable: true)]
70+
private ?string $extraData = null;
6671

6772
#[ORM\OneToMany(
6873
targetEntity: Subscription::class,
@@ -83,12 +88,34 @@ class Subscriber implements DomainModel, Identity, CreationDate, ModificationDat
8388
)]
8489
private Collection $attributes;
8590

91+
#[ORM\Column(name: 'optedin', type: 'boolean')]
92+
private bool $optedIn = false;
93+
94+
#[ORM\Column(name: 'uuid', type: 'string', length: 36)]
95+
private string $uuid = '';
96+
97+
#[ORM\Column(name: 'subscribepage', type: 'integer', nullable: true)]
98+
private ?int $subscribePage = null;
99+
100+
#[ORM\Column(name: 'rssfrequency', type: 'string', length: 100, nullable: true)]
101+
private ?string $rssFrequency = null;
102+
103+
#[ORM\Column(name: 'password', type: 'string', length: 255, nullable: true)]
104+
private ?string $password = null;
105+
106+
#[ORM\Column(name: 'passwordchanged', type: 'datetime', nullable: true)]
107+
private ?DateTime $passwordChanged = null;
108+
109+
#[ORM\Column(name: 'foreignkey', type: 'string', length: 100, nullable: true)]
110+
private ?string $foreignKey = null;
111+
86112
public function __construct()
87113
{
88114
$this->subscriptions = new ArrayCollection();
89115
$this->attributes = new ArrayCollection();
90116
$this->extraData = '';
91117
$this->createdAt = new DateTime();
118+
$this->updatedAt = new DateTime();
92119
}
93120

94121
public function getId(): ?int
@@ -101,12 +128,11 @@ public function getCreatedAt(): ?DateTime
101128
return $this->createdAt;
102129
}
103130

104-
public function getUpdatedAt(): ?DateTime
131+
public function getUpdatedAt(): DateTime
105132
{
106133
return $this->updatedAt;
107134
}
108135

109-
#[ORM\PrePersist]
110136
#[ORM\PreUpdate]
111137
public function updateUpdatedAt(): void
112138
{
@@ -279,4 +305,74 @@ public function removeAttribute(SubscriberAttributeValue $attribute): self
279305
$this->attributes->removeElement($attribute);
280306
return $this;
281307
}
308+
309+
public function isOptedIn(): bool
310+
{
311+
return $this->optedIn;
312+
}
313+
314+
public function setOptedIn(bool $optedIn): void
315+
{
316+
$this->optedIn = $optedIn;
317+
}
318+
319+
public function getUuid(): string
320+
{
321+
return $this->uuid;
322+
}
323+
324+
public function setUuid(string $uuid): void
325+
{
326+
$this->uuid = $uuid;
327+
}
328+
329+
public function getSubscribePage(): ?int
330+
{
331+
return $this->subscribePage;
332+
}
333+
334+
public function setSubscribePage(?int $subscribePage): void
335+
{
336+
$this->subscribePage = $subscribePage;
337+
}
338+
339+
public function getRssFrequency(): ?string
340+
{
341+
return $this->rssFrequency;
342+
}
343+
344+
public function setRssFrequency(?string $rssFrequency): void
345+
{
346+
$this->rssFrequency = $rssFrequency;
347+
}
348+
349+
public function getPassword(): ?string
350+
{
351+
return $this->password;
352+
}
353+
354+
public function setPassword(?string $password): void
355+
{
356+
$this->password = $password;
357+
}
358+
359+
public function getPasswordChanged(): ?DateTime
360+
{
361+
return $this->passwordChanged;
362+
}
363+
364+
public function setPasswordChanged(?DateTime $passwordChanged): void
365+
{
366+
$this->passwordChanged = $passwordChanged;
367+
}
368+
369+
public function getForeignKey(): ?string
370+
{
371+
return $this->foreignKey;
372+
}
373+
374+
public function setForeignKey(?string $foreignKey): void
375+
{
376+
$this->foreignKey = $foreignKey;
377+
}
282378
}

src/Domain/Subscription/Model/SubscriberAttributeValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SubscriberAttributeValue implements DomainModel
2525
#[ORM\JoinColumn(name: 'userid', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
2626
private Subscriber $subscriber;
2727

28-
#[ORM\Column(name: 'value', type: 'text', nullable: true, columnDefinition: 'TEXT')]
28+
#[ORM\Column(name: 'value', type: 'text', nullable: true)]
2929
private ?string $value = null;
3030

3131
public function __construct(SubscriberAttributeDefinition $attributeDefinition, Subscriber $subscriber)

src/Domain/Subscription/Model/SubscriberList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SubscriberList implements DomainModel, Identity, CreationDate, Modificatio
4343
private ?string $rssFeed = null;
4444

4545
#[ORM\Column]
46-
private ?string $description;
46+
private string $description = '';
4747

4848
#[ORM\Column(name: 'entered', type: 'datetime', nullable: true)]
4949
protected ?DateTime $createdAt = null;

tests/Integration/Domain/Identity/Fixtures/AdministratorTokenWithAdministratorFixture.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ public function load(ObjectManager $manager): void
4545
$manager->persist($admin);
4646
}
4747

48-
$adminToken = new AdministratorToken();
48+
$adminToken = new AdministratorToken($admin);
4949
$this->setSubjectId($adminToken, (int)$row['id']);
5050
$adminToken->setKey($row['value']);
5151
$this->setSubjectProperty($adminToken, 'expiry', new DateTime($row['expires']));
5252
$this->setSubjectProperty($adminToken, 'createdAt', (bool) $row['entered']);
53-
$adminToken->setAdministrator($admin);
5453
$manager->persist($adminToken);
5554
} while (true);
5655

tests/Integration/Domain/Identity/Fixtures/DetachedAdministratorTokenFixture.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DateTime;
88
use Doctrine\Bundle\FixturesBundle\Fixture;
99
use Doctrine\Persistence\ObjectManager;
10+
use PhpList\Core\Domain\Identity\Model\Administrator;
1011
use PhpList\Core\Domain\Identity\Model\AdministratorToken;
1112
use PhpList\Core\TestingSupport\Traits\ModelTestTrait;
1213
use RuntimeException;
@@ -28,6 +29,9 @@ public function load(ObjectManager $manager): void
2829
}
2930

3031
$headers = fgetcsv($handle);
32+
$admin = (new Administrator())->setLoginName('admin');
33+
$this->setSubjectId($admin, 1);
34+
$manager->persist($admin);
3135

3236
do {
3337
$data = fgetcsv($handle);
@@ -36,7 +40,7 @@ public function load(ObjectManager $manager): void
3640
}
3741
$row = array_combine($headers, $data);
3842

39-
$adminToken = new AdministratorToken();
43+
$adminToken = new AdministratorToken($admin);
4044
$this->setSubjectId($adminToken, (int)$row['id']);
4145
$adminToken->setKey($row['value']);
4246

tests/Integration/Domain/Identity/Repository/AdministratorTokenRepositoryTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ public function testSavePersistsAndFlushesModel()
130130
/** @var Administrator $administrator */
131131
$administrator = $administratorRepository->find(1);
132132

133-
$model = new AdministratorToken();
134-
$model->setAdministrator($administrator);
133+
$model = new AdministratorToken($administrator);
135134
$this->repository->save($model);
136135

137136
self::assertSame($model, $this->repository->find($model->getId()));

tests/Unit/Domain/Identity/Model/AdministratorTokenTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,4 @@ public function testGetAdministratorInitiallyReturnsNull(): void
9494
{
9595
self::assertNotNull($this->subject->getAdministrator());
9696
}
97-
98-
public function testSetAdministratorSetsAdministrator(): void
99-
{
100-
$model = new Administrator();
101-
$this->subject->setAdministrator($model);
102-
103-
self::assertSame($model, $this->subject->getAdministrator());
104-
}
10597
}

tests/Unit/Domain/Subscription/Model/SubscriberTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public function testUpdateCreationDateSetsCreationDateToNow(): void
5656
self::assertSimilarDates(new \DateTime(), $this->subscriber->getCreatedAt());
5757
}
5858

59-
public function testgetUpdatedAtInitiallyReturnsNull(): void
59+
public function testGetUpdatedAtInitiallyReturnsNotNull(): void
6060
{
61-
self::assertNull($this->subscriber->getUpdatedAt());
61+
self::assertNotNull($this->subscriber->getUpdatedAt());
6262
}
6363

6464
public function testUpdateModificationDateSetsModificationDateToNow(): void

0 commit comments

Comments
 (0)