Skip to content

Commit 809d270

Browse files
committed
Fix: tests
1 parent 88ae308 commit 809d270

File tree

8 files changed

+16
-26
lines changed

8 files changed

+16
-26
lines changed

src/Bounce/Service/NativeBounceProcessingService.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpList\Core\Bounce\Service;
66

7+
use Doctrine\ORM\EntityManagerInterface;
78
use IMAP\Connection;
89
use PhpList\Core\Bounce\Exception\OpenMboxFileException;
910
use PhpList\Core\Bounce\Service\Processor\BounceDataProcessor;
@@ -21,13 +22,15 @@ class NativeBounceProcessingService implements BounceProcessingServiceInterface
2122
private LoggerInterface $logger;
2223
private bool $purgeProcessed;
2324
private bool $purgeUnprocessed;
25+
private EntityManagerInterface $entityManager;
2426

2527
public function __construct(
2628
BounceManager $bounceManager,
2729
NativeImapMailReader $mailReader,
2830
MessageParser $messageParser,
2931
BounceDataProcessor $bounceDataProcessor,
3032
LoggerInterface $logger,
33+
EntityManagerInterface $entityManager,
3134
bool $purgeProcessed,
3235
bool $purgeUnprocessed
3336
) {
@@ -36,6 +39,7 @@ public function __construct(
3639
$this->messageParser = $messageParser;
3740
$this->bounceDataProcessor = $bounceDataProcessor;
3841
$this->logger = $logger;
42+
$this->entityManager = $entityManager;
3943
$this->purgeProcessed = $purgeProcessed;
4044
$this->purgeUnprocessed = $purgeUnprocessed;
4145
}
@@ -135,7 +139,7 @@ private function processImapBounce($link, int $num, string $header): bool
135139
$userId = $this->messageParser->findUserId($body);
136140

137141
$bounce = $this->bounceManager->create($bounceDate, $header, $body);
138-
142+
$this->entityManager->flush();
139143
return $this->bounceDataProcessor->process($bounce, $msgId, $userId, $bounceDate);
140144
}
141145
}

src/Domain/Messaging/Service/Manager/BounceManager.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public function create(
5353
comment: $comment
5454
);
5555

56-
$this->bounceRepository->save($bounce);
56+
$this->bounceRepository->persist($bounce);
57+
$this->entityManager->flush();
5758

5859
return $bounce;
5960
}
@@ -62,14 +63,15 @@ public function update(Bounce $bounce, ?string $status = null, ?string $comment
6263
{
6364
$bounce->setStatus($status);
6465
$bounce->setComment($comment);
65-
$this->bounceRepository->save($bounce);
66+
$this->entityManager->flush();
6667

6768
return $bounce;
6869
}
6970

7071
public function delete(Bounce $bounce): void
7172
{
7273
$this->bounceRepository->remove($bounce);
74+
$this->entityManager->flush();
7375
}
7476

7577
/** @return Bounce[] */

tests/Unit/Bounce/Command/ProcessBouncesCommandTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpList\Core\Tests\Unit\Bounce\Command;
66

7+
use Doctrine\ORM\EntityManagerInterface;
78
use Exception;
89
use PhpList\Core\Bounce\Command\ProcessBouncesCommand;
910
use PhpList\Core\Bounce\Service\ConsecutiveBounceHandler;
@@ -48,6 +49,7 @@ protected function setUp(): void
4849
unidentifiedReprocessor: $this->unidentifiedReprocessor,
4950
consecutiveBounceHandler: $this->consecutiveBounceHandler,
5051
translator: $this->translator,
52+
entityManager: $this->createMock(EntityManagerInterface::class),
5153
);
5254

5355
$this->commandTester = new CommandTester($command);

tests/Unit/Domain/Messaging/Service/Manager/BounceManagerTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testCreatePersistsAndReturnsBounce(): void
4949
$comment = 'created by test';
5050

5151
$this->repository->expects($this->once())
52-
->method('save')
52+
->method('persist')
5353
->with($this->isInstanceOf(Bounce::class));
5454

5555
$bounce = $this->manager->create(
@@ -115,9 +115,8 @@ public function testGetByIdReturnsNullWhenNotFound(): void
115115
public function testUpdateChangesFieldsAndSaves(): void
116116
{
117117
$bounce = new Bounce();
118-
$this->repository->expects($this->once())
119-
->method('save')
120-
->with($bounce);
118+
$this->entityManager->expects($this->once())
119+
->method('flush');
121120

122121
$updated = $this->manager->update($bounce, 'processed', 'done');
123122
$this->assertSame($bounce, $updated);
@@ -130,8 +129,6 @@ public function testLinkUserMessageBounceFlushesAndSetsFields(): void
130129
$bounce = $this->createMock(Bounce::class);
131130
$bounce->method('getId')->willReturn(77);
132131

133-
$this->entityManager->expects($this->once())->method('flush');
134-
135132
$dt = new DateTimeImmutable('2024-05-01 12:34:56');
136133
$umb = $this->manager->linkUserMessageBounce($bounce, $dt, 123, 456);
137134

tests/Unit/Domain/Messaging/Service/Manager/SendProcessManagerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ protected function setUp(): void
2929
public function testCreatePersistsEntityAndSetsFields(): void
3030
{
3131
$this->em->expects($this->once())->method('persist')->with($this->isInstanceOf(SendProcess::class));
32-
$this->em->expects($this->once())->method('flush');
3332

3433
$sp = $this->manager->create('pageA', 'proc-1');
3534
$this->assertInstanceOf(SendProcess::class, $sp);

tests/Unit/Domain/Subscription/Service/Manager/SubscribePageManagerTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,6 @@ public function testSetPageDataCreatesNewWhenMissingAndPersistsAndFlushes(): voi
218218
->method('persist')
219219
->with($this->isInstanceOf(SubscribePageData::class));
220220

221-
$this->entityManager
222-
->expects($this->once())
223-
->method('flush');
224-
225221
$result = $this->manager->setPageData($page, 'greeting', 'hello');
226222

227223
$this->assertInstanceOf(SubscribePageData::class, $result);

tests/Unit/Domain/Subscription/Service/Manager/SubscriberBlacklistManagerTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ public function testAddEmailToBlacklistAddsEntryAndReason(): void
106106
[$this->isInstanceOf(UserBlacklistData::class)]
107107
);
108108

109-
$this->entityManager
110-
->expects($this->once())
111-
->method('flush');
112-
113109
$this->manager->addEmailToBlacklist('[email protected]', 'test reason');
114110
}
115111

@@ -126,10 +122,6 @@ public function testAddEmailToBlacklistAddsEntryWithoutReason(): void
126122
->method('persist')
127123
->with($this->isInstanceOf(UserBlacklist::class));
128124

129-
$this->entityManager
130-
->expects($this->once())
131-
->method('flush');
132-
133125
$this->manager->addEmailToBlacklist('[email protected]');
134126
}
135127

@@ -166,10 +158,6 @@ public function testRemoveEmailFromBlacklistRemovesAllRelatedData(): void
166158

167159
$subscriber->expects($this->once())->method('setBlacklisted')->with(false);
168160

169-
$this->entityManager
170-
->expects($this->once())
171-
->method('flush');
172-
173161
$this->manager->removeEmailFromBlacklist('[email protected]');
174162
}
175163

tests/Unit/Processor/BounceDataProcessorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PhpList\Core\Tests\Unit\Processor;
66

77
use DateTimeImmutable;
8+
use Doctrine\ORM\EntityManagerInterface;
89
use PhpList\Core\Bounce\Service\Processor\BounceDataProcessor;
910
use PhpList\Core\Domain\Messaging\Model\Bounce;
1011
use PhpList\Core\Domain\Messaging\Repository\MessageRepository;
@@ -47,6 +48,7 @@ private function makeProcessor(): BounceDataProcessor
4748
logger: $this->logger,
4849
subscriberManager: $this->subscriberManager,
4950
subscriberHistoryManager: $this->historyManager,
51+
entityManager: $this->createMock(EntityManagerInterface::class),
5052
);
5153
}
5254

0 commit comments

Comments
 (0)