Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codedmonkey committed Jan 10, 2025
1 parent 231537c commit e7d5986
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 57 deletions.
11 changes: 11 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": "3"
}
]
]
}
28 changes: 0 additions & 28 deletions tests/Controller/AjaxTest.php

This file was deleted.

41 changes: 20 additions & 21 deletions tests/Crawling/BatSignalCrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,52 @@
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);
}

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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand Down
8 changes: 0 additions & 8 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit e7d5986

Please sign in to comment.