From e7d5986a509e7e5d69da98b8c6de5e9c51dc75f7 Mon Sep 17 00:00:00 2001 From: Tim Goudriaan Date: Fri, 10 Jan 2025 16:14:39 +0100 Subject: [PATCH] Fix tests --- .babelrc | 11 +++++++ tests/Controller/AjaxTest.php | 28 ----------------- tests/Crawling/BatSignalCrawlerTest.php | 41 ++++++++++++------------- webpack.config.js | 8 ----- 4 files changed, 31 insertions(+), 57 deletions(-) create mode 100644 .babelrc delete mode 100644 tests/Controller/AjaxTest.php diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..e7ada960 --- /dev/null +++ b/.babelrc @@ -0,0 +1,11 @@ +{ + "presets": [ + [ + "@babel/preset-env", + { + "useBuiltIns": "usage", + "corejs": "3" + } + ] + ] +} diff --git a/tests/Controller/AjaxTest.php b/tests/Controller/AjaxTest.php deleted file mode 100644 index a55bac63..00000000 --- a/tests/Controller/AjaxTest.php +++ /dev/null @@ -1,28 +0,0 @@ -request('GET', '/', [], [], [ - 'HTTP_X_REQUESTED_WITH' => 'NoAgendaRequest', - ]); - - $this->assertEquals(200, $client->getResponse()->getStatusCode()); - $this->assertResponseHeaderSame('Content-Type', 'application/json'); - - $responseData = json_decode($client->getResponse()->getContent(), true); - - $this->assertIsArray($responseData); - $this->assertArrayHasKey('path', $responseData); - $this->assertArrayHasKey('title', $responseData); - $this->assertArrayHasKey('contents', $responseData); - $this->assertArrayHasKey('authenticated', $responseData); - } -} diff --git a/tests/Crawling/BatSignalCrawlerTest.php b/tests/Crawling/BatSignalCrawlerTest.php index c4079c85..3f78b127 100644 --- a/tests/Crawling/BatSignalCrawlerTest.php +++ b/tests/Crawling/BatSignalCrawlerTest.php @@ -3,29 +3,35 @@ namespace App\Tests\Crawling; use App\Crawling\BatSignalCrawler; +use App\Crawling\NotificationPublisher; use App\Repository\BatSignalRepository; use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use Symfony\Component\HttpClient\MockHttpClient; use Symfony\Component\HttpClient\Response\MockResponse; +use Symfony\Component\Notifier\NotifierInterface; class BatSignalCrawlerTest extends TestCase { private $crawler; + private $notificationPublisher; private $entityManager; private $httpClient; + private $notifier; private $logger; private $repository; public function setUp(): void { $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->getMock(); + $this->notificationPublisher = $this->getMockBuilder(NotificationPublisher::class)->disableOriginalConstructor()->getMock(); $this->repository = $this->getMockBuilder(BatSignalRepository::class)->disableOriginalConstructor()->getMock(); $this->httpClient = new MockHttpClient(); + $this->notifier = $this->getMockBuilder(NotifierInterface::class)->getMock(); $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); - $this->crawler = new BatSignalCrawler($this->entityManager, $this->repository, $this->httpClient, 'foo', 1); + $this->crawler = new BatSignalCrawler($this->entityManager, $this->notificationPublisher, $this->repository, $this->httpClient, $this->notifier, 'foo', 1); $this->crawler->setLogger($this->logger); } @@ -33,18 +39,16 @@ public function testNewSignal(): void { $this->httpClient->setResponseFactory([ $this->createResponse([[ - 'content' => 'We\'re live now at noagendastream.com/ with No Agenda episode 33 #@pocketnoagenda', + 'id' => '404', + 'content' => 'We’re live now at noagendastream.com/ with No Agenda episode 33 #@pocketnoagenda', 'created_at' => '2022-02-02 12:00:00', ]]), ]); $this->repository->expects($this->once())->method('exists') - ->willReturn(false) - ; + ->willReturn(false); - $this->logger->expects($this->once())->method('info') - ->with('Found new bat signal with code "33" published at 2022-02-02 12:00:00.') - ; + $this->logger->expects($this->exactly(2))->method('info'); $this->entityManager->expects($this->once())->method('persist'); @@ -53,12 +57,11 @@ public function testNewSignal(): void public function testMissingAccessToken(): void { - $crawler = new BatSignalCrawler($this->entityManager, $this->repository, $this->httpClient, null, 1); + $crawler = new BatSignalCrawler($this->entityManager, $this->notificationPublisher, $this->repository, $this->httpClient, $this->notifier, null, 1); $crawler->setLogger($this->logger); $this->logger->expects($this->once())->method('critical') - ->with('Mastodon access token not found. Skipping crawling of bat signal.') - ; + ->with('Mastodon access token not found. Skipping crawling of bat signal.'); $this->entityManager->expects($this->never())->method('persist'); @@ -72,12 +75,10 @@ public function testInvalidResponse(): void ]); $this->logger->expects($this->once())->method('warning') - ->with('Failed to crawl bat signal feed. HTTP response code: 400') - ; + ->with('Failed to crawl bat signal on Mastodon: Response code 400'); $this->logger->expects($this->once())->method('debug') - ->with('No bat signal found.') - ; + ->with('No bat signal found.'); $this->entityManager->expects($this->never())->method('persist'); @@ -91,8 +92,7 @@ public function testNoSignal(): void ]); $this->logger->expects($this->once())->method('debug') - ->with('No bat signal found.') - ; + ->with('No bat signal found.'); $this->entityManager->expects($this->never())->method('persist'); @@ -103,18 +103,17 @@ public function testSignalExists(): void { $this->httpClient->setResponseFactory([ $this->createResponse([[ - 'content' => 'We\'re live now at noagendastream.com/ with No Agenda episode 33 #@pocketnoagenda', + 'id' => '404', + 'content' => 'We’re live now at noagendastream.com/ with No Agenda episode 33 #@pocketnoagenda', 'created_at' => '2022-02-02 12:00:00', ]]), ]); $this->repository->expects($this->once())->method('exists') - ->willReturn(true) - ; + ->willReturn(true); $this->logger->expects($this->once())->method('debug') - ->with('Found bat signal already exists.') - ; + ->with('Found bat signal already exists.'); $this->entityManager->expects($this->never())->method('persist'); diff --git a/webpack.config.js b/webpack.config.js index aded1f4c..e7287a8f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -17,10 +17,6 @@ Encore .enableSourceMaps(!Encore.isProduction()) .enableVersioning(Encore.isProduction()) - .configureBabelPresetEnv((config) => { - config.useBuiltIns = 'usage'; - config.corejs = '3.23'; - }) .enableSassLoader(); const appConfig = Encore.getWebpackConfig(); @@ -39,10 +35,6 @@ Encore .enableSourceMaps(!Encore.isProduction()) .enableVersioning(Encore.isProduction()) - .configureBabelPresetEnv((config) => { - config.useBuiltIns = 'usage'; - config.corejs = '3.23'; - }) .enableSassLoader(); const consoleConfig = Encore.getWebpackConfig();