Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,8 @@ services:
Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler:
arguments:
- '%env(DATABASE_URL)%'
when@test:
services:
# Testing
App\Tests\Service\:
resource: '../tests/Service/'
2 changes: 2 additions & 0 deletions src/Service/ActivityPub/ApHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Psr\Cache\InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\DependencyInjection\Attribute\WhenNot;
use Symfony\Component\HttpClient\CurlHttpClient;
use Symfony\Contracts\Cache\CacheInterface;
use Symfony\Contracts\Cache\ItemInterface;
Expand All @@ -41,6 +42,7 @@ enum ApRequestType
case NodeInfo;
}

#[WhenNot(env: 'test')]
class ApHttpClient implements ApHttpClientInterface
{
public const TIMEOUT = 8;
Expand Down
2 changes: 2 additions & 0 deletions src/Service/ImageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
use App\Exception\ImageDownloadTooLargeException;
use League\Flysystem\FilesystemOperator;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\WhenNot;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Mime\MimeTypesInterface;
use Symfony\Component\Validator\Constraints\Image;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

#[WhenNot(env: 'test')]
class ImageManager implements ImageManagerInterface
{
public const IMAGE_MIMETYPES = [
Expand Down
2 changes: 2 additions & 0 deletions tests/Service/TestingApHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
use App\Entity\Magazine;
use App\Entity\User;
use App\Service\ActivityPub\ApHttpClientInterface;
use Symfony\Component\DependencyInjection\Attribute\When;

#[When(env: 'test')]
class TestingApHttpClient implements ApHttpClientInterface
{
/**
Expand Down
24 changes: 7 additions & 17 deletions tests/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
use App\Tests\Service\TestingImageManager;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface;
use League\Flysystem\Filesystem;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Console\Application;
Expand All @@ -69,11 +68,8 @@
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Mime\MimeTypesInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

abstract class WebTestCase extends BaseWebTestCase
Expand Down Expand Up @@ -182,20 +178,14 @@ public function setUp(): void
$this->kibbyPath = \dirname(__FILE__).'/assets/kibby_emoji.png';
$this->client = static::createClient();

$this->testingApHttpClient = new TestingApHttpClient();
self::getContainer()->set(ApHttpClientInterface::class, $this->testingApHttpClient);

$this->imageManager = new TestingImageManager(
$this->getContainer()->getParameter('kbin_storage_url'),
$this->getService(Filesystem::class),
$this->getService(HttpClientInterface::class),
$this->getService(MimeTypesInterface::class),
$this->getService(ValidatorInterface::class),
$this->getService(LoggerInterface::class),
$this->getService(SettingsManager::class),
);
$client = $this->getService(ApHttpClientInterface::class);
self::assertTrue($client instanceof TestingApHttpClient);
$this->testingApHttpClient = $client;

$imageManager = $this->getService(ImageManagerInterface::class);
self::assertTrue($imageManager instanceof TestingImageManager);
$this->imageManager = $imageManager;
$this->imageManager->setKibbyPath($this->kibbyPath);
self::getContainer()->set(ImageManagerInterface::class, $this->imageManager);

$this->entityManager = $this->getService(EntityManagerInterface::class);
$this->magazineManager = $this->getService(MagazineManager::class);
Expand Down
Loading