Skip to content

Commit

Permalink
Merge pull request #218 from netglue/symfony-7
Browse files Browse the repository at this point in the history
Remove support for Symfony v5 components, add support for Symfony v7 components
  • Loading branch information
gsteel authored Jan 2, 2024
2 parents 5b1fff9 + 3ad7b48 commit 530a6a0
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"extensions": [
"amqp",
"pcntl",
"redis",
"igbinary",
"amqp"
Expand Down
18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
"laminas/laminas-stdlib": "^3.6",
"psr/container": "^1.0 || ^2.0",
"psr/log": "^2 || ^3",
"symfony/console": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.3.8 || ^6.0",
"symfony/event-dispatcher": "^5.3.7 || ^6.0",
"symfony/messenger": "^5.3.9 || ^6.0",
"symfony/serializer": "^5.3.8 || ^6.0",
"symfony/console": "^6.0 || ^7.0",
"symfony/dependency-injection": "^6.0 || ^7.0",
"symfony/event-dispatcher": "^6.0 || ^7.0",
"symfony/messenger": "^6.4 || ^7.0",
"symfony/serializer": "^6.0 || ^7.0",
"symfony/service-contracts": "^2 || ^3"
},
"require-dev": {
"ext-amqp": "*",
"ext-pcntl": "*",
"doctrine/coding-standard": "^12.0",
"doctrine/orm": "^2.17.2",
"laminas/laminas-cli": "^1.10",
Expand All @@ -42,9 +44,9 @@
"psalm/plugin-phpunit": "^0.18.4",
"roave/security-advisories": "dev-latest",
"squizlabs/php_codesniffer": "^3.8.0",
"symfony/amqp-messenger": "^5.4.22 || ^6.4",
"symfony/doctrine-messenger": "^5.4 || ^6.4.2",
"symfony/redis-messenger": "^5.4.22 || ^6.4.2",
"symfony/amqp-messenger": "^6.4 || ^7.0",
"symfony/doctrine-messenger": "^6.4.2 || ^7.0",
"symfony/redis-messenger": "^6.4.2 || ^7.0",
"vimeo/psalm": "^5.18.0"
},
"suggest": {
Expand Down
7 changes: 5 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 3 additions & 24 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.15.0@5c774aca4746caf3d239d9c8cadb9f882ca29352">
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19">
<file src="src/Container/Command/ConsumeCommandFactory.php">
<DeprecatedClass>
<code>StopWorkerOnSigtermSignalListener::class</code>
<code>new StopWorkerOnSigtermSignalListener($logger)</code>
</DeprecatedClass>
</file>
Expand All @@ -18,24 +19,6 @@
<code><![CDATA[$configuration['connection']]]></code>
</MixedArgument>
</file>
<file src="src/TransportFactoryFactory.php">
<DeprecatedClass>
<code>new InMemoryTransportFactory()</code>
</DeprecatedClass>
</file>
<file src="tests/Container/TransportFactoryTest.php">
<NoInterfaceProperties>
<code><![CDATA[$this->factory->dsn]]></code>
<code><![CDATA[$this->factory->dsn]]></code>
<code><![CDATA[$this->factory->dsn]]></code>
<code><![CDATA[$this->factory->options]]></code>
<code><![CDATA[$this->factory->options]]></code>
<code><![CDATA[$this->factory->options]]></code>
<code><![CDATA[$this->factory->serializer]]></code>
<code><![CDATA[$this->factory->serializer]]></code>
<code><![CDATA[$this->factory->serializer]]></code>
</NoInterfaceProperties>
</file>
<file src="tests/LaminasCliIntegrationTest.php">
<InternalClass>
<code>new ContainerCommandLoader($container, $commands)</code>
Expand All @@ -47,11 +30,7 @@
<file src="tests/ServiceManagerIntegrationTest.php">
<DeprecatedClass>
<code>StopWorkerOnSigtermSignalListener::class</code>
</DeprecatedClass>
</file>
<file src="tests/TransportFactoryFactoryTest.php">
<DeprecatedClass>
<code>InMemoryTransportFactory::class</code>
<code>StopWorkerOnSigtermSignalListener::class</code>
</DeprecatedClass>
</file>
</files>
11 changes: 9 additions & 2 deletions src/Container/Command/ConsumeCommandFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Messenger\RoutableMessageBus;

use function array_keys;
use function class_exists;

final class ConsumeCommandFactory
{
Expand Down Expand Up @@ -46,8 +47,14 @@ public function __invoke(ContainerInterface $container): ConsumeMessagesCommand
$logger,
));

// Always adds a listener to gracefully shut-down workers when SIGTERM is received
$dispatcher->addSubscriber(new StopWorkerOnSigtermSignalListener($logger));
/**
* In Symfony v7, this listener has been removed. Now, the Consume command automatically listens for
* SIGTERM and SIGINT as part of the SignalableCommandInterface contract.
*/
if (class_exists(StopWorkerOnSigtermSignalListener::class)) {
// Always adds a listener to gracefully shut-down workers when SIGTERM is received
$dispatcher->addSubscriber(new StopWorkerOnSigtermSignalListener($logger));
}

return new ConsumeMessagesCommand(
new RoutableMessageBus($container),
Expand Down
2 changes: 1 addition & 1 deletion src/TransportFactoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport;
use Symfony\Component\Messenger\Bridge\Redis\Transport\RedisTransportFactory;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Messenger\Transport\InMemoryTransportFactory;
use Symfony\Component\Messenger\Transport\InMemory\InMemoryTransportFactory;
use Symfony\Component\Messenger\Transport\Sync\SyncTransportFactory;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;

Expand Down
37 changes: 37 additions & 0 deletions tests/Container/TransportFactoryStub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Netglue\PsrContainer\MessengerTest\Container;

use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;

/** @implements TransportFactoryInterface<TransportInterface> */
final class TransportFactoryStub implements TransportFactoryInterface
{
public SerializerInterface|null $serializer = null;
public string|null $dsn = null;
public array|null $options = null;

public function __construct(private readonly TransportInterface $transport)
{
}

/** @inheritDoc */
public function createTransport(string $dsn, array $options, SerializerInterface $serializer): TransportInterface
{
$this->serializer = $serializer;
$this->dsn = $dsn;
$this->options = $options;

return $this->transport;
}

/** @inheritDoc */
public function supports(string $dsn, array $options): bool
{
return true;
}
}
31 changes: 2 additions & 29 deletions tests/Container/TransportFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
use Psr\Container\ContainerInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;

class TransportFactoryTest extends TestCase
{
private TransportInterface $transport;
/** @var TransportFactoryInterface<TransportInterface> */
private TransportFactoryInterface $factory;
private TransportFactoryStub $factory;
/** @var MockObject&ContainerInterface */
private ContainerInterface $container;

Expand Down Expand Up @@ -50,32 +48,7 @@ public function send(Envelope $envelope): Envelope
}
};

/** @psalm-suppress MissingTemplateParam Anyone know how to add templates to anonymous classes? */
$this->factory = new class ($this->transport) implements TransportFactoryInterface {
public SerializerInterface|null $serializer = null;
public string|null $dsn = null;
public array|null $options = null;

public function __construct(private TransportInterface $transport)
{
}

// phpcs:ignore
public function createTransport(string $dsn, array $options, SerializerInterface $serializer) : TransportInterface
{
$this->serializer = $serializer;
$this->dsn = $dsn;
$this->options = $options;

return $this->transport;
}

// phpcs:ignore
public function supports(string $dsn, array $options) : bool
{
return true;
}
};
$this->factory = new TransportFactoryStub($this->transport);
}

private function thereIsNoConfig(): void
Expand Down
5 changes: 5 additions & 0 deletions tests/ServiceManagerIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Symfony\Component\Messenger\Transport\InMemoryTransport as DeprecatedInMemoryTransport;

use function assert;
use function class_exists;
use function is_array;

/**
Expand Down Expand Up @@ -282,6 +283,10 @@ public function testThatAnExceptionWillBeThrownWhenTheFailureCommandsAreRegister

public function testThatASigtermListenerIsSubscribedToTheConsumeCommand(): void
{
if (! class_exists(StopWorkerOnSigtermSignalListener::class)) {
self::markTestSkipped('The sigterm listener is only attached for v6 symfony messenger');
}

$dispatcher = new EventDispatcher();

$this->mergeConfig([
Expand Down
2 changes: 1 addition & 1 deletion tests/TransportFactoryFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Symfony\Component\Messenger\Bridge\Amqp\Transport\AmqpTransportFactory;
use Symfony\Component\Messenger\Bridge\Redis\Transport\RedisTransportFactory;
use Symfony\Component\Messenger\MessageBus;
use Symfony\Component\Messenger\Transport\InMemoryTransportFactory;
use Symfony\Component\Messenger\Transport\InMemory\InMemoryTransportFactory;
use Symfony\Component\Messenger\Transport\Sync\SyncTransportFactory;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;

Expand Down

0 comments on commit 530a6a0

Please sign in to comment.