Skip to content

Commit 8978d26

Browse files
committed
Fix tests
1 parent de30ae6 commit 8978d26

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tests/FilterListWorkerTest.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
use App\Entity\Job;
1616
use App\Entity\FilterListEntry;
1717
use App\Entity\FilterListEntryRepository;
18+
use App\Entity\Package;
19+
use App\Entity\PackageRepository;
1820
use App\FilterList\FilterLists;
1921
use App\FilterList\List\FilterListInterface;
2022
use App\FilterList\FilterListEntryUpdateListener;
2123
use App\FilterList\FilterListResolver;
2224
use App\FilterList\RemoteFilterListEntry;
25+
use App\Model\DownloadManager;
2326
use App\Service\Locker;
2427
use App\Service\FilterListWorker;
2528
use Doctrine\DBAL\Connection;
@@ -29,21 +32,30 @@
2932
use PHPUnit\Framework\TestCase;
3033
use Psr\Log\NullLogger;
3134
use Seld\Signal\SignalHandler;
35+
use Symfony\Component\Mailer\MailerInterface;
36+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
3237

3338
class FilterListWorkerTest extends TestCase
3439
{
3540
private FilterListWorker $worker;
3641
private FilterListInterface&MockObject $filterList;
3742
private EntityManager&MockObject $em;
3843
private FilterListEntryRepository&MockObject $filterListEntryRepository;
44+
private PackageRepository $packageRepository;
3945
private Locker&MockObject $locker;
46+
private MailerInterface&MockObject $mailer;
47+
private DownloadManager $downloadManager;
48+
private UrlGeneratorInterface $urlGenerator;
4049

4150
protected function setUp(): void
4251
{
4352
$this->filterList = $this->createMock(FilterListInterface::class);
4453
$this->locker = $this->createMock(Locker::class);
54+
$this->mailer = $this->createMock(MailerInterface::class);
55+
$this->downloadManager = $this->createStub(DownloadManager::class);
56+
$this->urlGenerator = $this->createStub(UrlGeneratorInterface::class);
4557
$doctrine = $this->createStub(ManagerRegistry::class);
46-
$this->worker = new FilterListWorker($this->locker, new NullLogger(), $doctrine, [FilterLists::AIKIDO_MALWARE->value => $this->filterList], new FilterListResolver(), new FilterListEntryUpdateListener($doctrine));
58+
$this->worker = new FilterListWorker($this->locker, new NullLogger(), $doctrine, [FilterLists::AIKIDO_MALWARE->value => $this->filterList], new FilterListResolver(), new FilterListEntryUpdateListener($doctrine), $this->mailer, $this->downloadManager, 'test@example.com', $this->urlGenerator);
4759

4860
$this->em = $this->createMock(EntityManager::class);
4961

@@ -56,11 +68,13 @@ protected function setUp(): void
5668
->willReturn($this->createStub(Connection::class));
5769

5870
$this->filterListEntryRepository = $this->createMock(FilterListEntryRepository::class);
71+
$this->packageRepository = $this->createStub(PackageRepository::class);
5972

6073
$doctrine
6174
->method('getRepository')
6275
->willReturnMap([
6376
[FilterListEntry::class, null, $this->filterListEntryRepository],
77+
[Package::class, null, $this->packageRepository],
6478
]);
6579
}
6680

@@ -94,6 +108,14 @@ public function testProcess(): void
94108
->method('remove')
95109
->with($this->identicalTo($existingEntryToBeDeleted));
96110

111+
$this->urlGenerator
112+
->method('generate')
113+
->willReturn('https://packagist.org/packages/vendor/new-malware');
114+
115+
$this->mailer
116+
->expects($this->once())
117+
->method('send');
118+
97119
$result = $this->worker->process($this->createJob(), SignalHandler::create());
98120

99121
$this->assertSame(Job::STATUS_COMPLETED, $result['status']);
@@ -205,5 +227,9 @@ private function expectNoPersistAndRemove(): void
205227
$this->em
206228
->expects($this->never())
207229
->method('flush');
230+
231+
$this->mailer
232+
->expects($this->never())
233+
->method('send');
208234
}
209235
}

0 commit comments

Comments
 (0)