1515use App \Entity \Job ;
1616use App \Entity \FilterListEntry ;
1717use App \Entity \FilterListEntryRepository ;
18+ use App \Entity \Package ;
19+ use App \Entity \PackageRepository ;
1820use App \FilterList \FilterLists ;
1921use App \FilterList \List \FilterListInterface ;
2022use App \FilterList \FilterListEntryUpdateListener ;
2123use App \FilterList \FilterListResolver ;
2224use App \FilterList \RemoteFilterListEntry ;
25+ use App \Model \DownloadManager ;
2326use App \Service \Locker ;
2427use App \Service \FilterListWorker ;
2528use Doctrine \DBAL \Connection ;
2932use PHPUnit \Framework \TestCase ;
3033use Psr \Log \NullLogger ;
3134use Seld \Signal \SignalHandler ;
35+ use Symfony \Component \Mailer \MailerInterface ;
36+ use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
3237
3338class 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