Skip to content

Commit

Permalink
Add support for Symfony 7
Browse files Browse the repository at this point in the history
  • Loading branch information
rpkamp committed Mar 2, 2024
1 parent 9070d7c commit bb86f16
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["8.0", "8.1", "8.2", "8.3"]
php: ["8.1", "8.2", "8.3"]

steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
},
"minimum-stability": "stable",
"require": {
"php": "^8.0",
"php": "^8.1",
"behat/behat": "^3.8.0",
"rpkamp/mailhog-client": "^2.0",
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.0",
"symfony/dependency-injection": "^6.4 || ^7.0",
"psr-discovery/http-client-implementations": "^1.0",
"psr-discovery/http-factory-implementations": "^1.0",
"symfony/http-client": "^5.4 || ^6.4"
"symfony/http-client": "^6.4 || ^7.0"
},
"require-dev": {
"guzzlehttp/psr7": "^1.6",
Expand Down
33 changes: 1 addition & 32 deletions src/ServiceContainer/MailhogExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

use function method_exists;

/**
* This class configures a lot of services, so needs access
* to a lot of classes. Therefore high coupling is allowed here.
Expand Down Expand Up @@ -69,7 +67,6 @@ private function registerHttpClient(ContainerBuilder $container): void
{
$httpClient = new Definition(ClientInterface::class);
$httpClient->setFactory([Discover::class, 'httpClient']);
$this->markServicePrivate($httpClient);

$container->setDefinition('mailhog.http_client', $httpClient);
}
Expand All @@ -78,7 +75,6 @@ private function registerHttpMessageFactory(ContainerBuilder $container): void
{
$httpRequestFactory = new Definition(RequestFactoryInterface::class);
$httpRequestFactory->setFactory([Discover::class, 'httpRequestFactory']);
$this->markServicePrivate($httpRequestFactory);

$container->setDefinition('mailhog.http_request_factory', $httpRequestFactory);
}
Expand All @@ -87,7 +83,6 @@ private function registerHttpStreamFactory(ContainerBuilder $container): void
{
$httpStreamFactory = new Definition(StreamFactoryInterface::class);
$httpStreamFactory->setFactory([Discover::class, 'httpStreamFactory']);
$this->markServicePrivate($httpStreamFactory);

$container->setDefinition('mailhog.http_stream_factory', $httpStreamFactory);
}
Expand All @@ -100,7 +95,7 @@ private function registerMailhogClient(ContainerBuilder $container): void
new Reference('mailhog.http_stream_factory'),
'%mailhog.base_url%',
]);
$this->markServicePublic($mailhogClient);
$mailhogClient->setPublic(true);

$container->setDefinition('mailhog.client', $mailhogClient);
}
Expand All @@ -112,14 +107,12 @@ private function registerContextInitializer(ContainerBuilder $container): void
]);

$contextInitializer->addTag(ContextExtension::INITIALIZER_TAG, ['priority' => 0]);
$this->markServicePrivate($contextInitializer);
$container->setDefinition('mailhog.context_initializer', $contextInitializer);
}

private function registerOpenedEmailStorage(ContainerBuilder $container): void
{
$openedEmailStorage = new Definition(OpenedEmailStorage::class);
$this->markServicePrivate($openedEmailStorage);

$container->setDefinition('mailhog.opened_email_storage', $openedEmailStorage);
}
Expand All @@ -130,7 +123,6 @@ private function registerOpenedEmailStorageContextInitializer(ContainerBuilder $
new Reference('mailhog.opened_email_storage'),
]);
$openMailInitializer->addTag(ContextExtension::INITIALIZER_TAG, ['priority' => 0]);
$this->markServicePrivate($openMailInitializer);

$container->setDefinition('mailhog.opened_email_storage.context_initializer', $openMailInitializer);
}
Expand All @@ -142,33 +134,10 @@ private function registerPurgeListener(ContainerBuilder $container): void
'%mailhog.purge_tag%',
]);
$listener->addTag(EventDispatcherExtension::SUBSCRIBER_TAG, ['priority' => 0]);
$this->markServicePrivate($listener);

$container->setDefinition('mailhog.purge_listener', $listener);
}

private function markServicePrivate(Definition $definition): void
{
if (!method_exists($definition, 'setPrivate')) {
// symfony/dependency-injection >= 3.4 where
// all services are private by default
return;
}

$definition->setPrivate(true);
}

public function markServicePublic(Definition $definition): void
{
if (!method_exists($definition, 'setPublic')) {
// symfony/dependency-injection < 3.4 where
// all services are public by default
return;
}

$definition->setPublic(true);
}

public function process(ContainerBuilder $container): void
{
}
Expand Down
3 changes: 0 additions & 3 deletions tests/ServiceContainer/MailhogExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

use Behat\Behat\Context\ServiceContainer\ContextExtension;
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension;
use Http\Client\HttpClient;
use Http\Message\MessageFactory;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
Expand All @@ -19,7 +17,6 @@
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpClient\Psr18Client;
use Symfony\Contracts\HttpClient\HttpClientInterface;

final class MailhogExtensionTest extends TestCase
{
Expand Down

0 comments on commit bb86f16

Please sign in to comment.