From 3a193d0417a6962e1f21d9a55fc166bc3550ce15 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Wed, 22 Mar 2023 20:57:36 +0100 Subject: [PATCH 01/20] Reuse some GitHub CI config files from centralized spot --- .github/workflows/{ci.yml => ci.yaml} | 68 +++++---------------------- 1 file changed, 13 insertions(+), 55 deletions(-) rename .github/workflows/{ci.yml => ci.yaml} (65%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yaml similarity index 65% rename from .github/workflows/ci.yml rename to .github/workflows/ci.yaml index 535b687..a4ba0b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yaml @@ -1,64 +1,13 @@ -name: MessengerMonitorBundle CI +name: CI on: pull_request: ~ push: - branches: - - "master" + branches: ['master'] + schedule: + - cron: '0 */12 * * *' jobs: - coding-standards: - name: "Coding Standards" - - runs-on: "ubuntu-latest" - - strategy: - matrix: - php: - - "8.0" - - steps: - - name: "Checkout" - uses: actions/checkout@v3 - - - name: "Set up PHP" - uses: shivammathur/setup-php@v2 - with: - coverage: none - php-version: ${{ matrix.php }} - - - name: "Install dependencies with composer" - uses: ramsey/composer-install@v2 - - - name: "Run friendsofphp/php-cs-fixer" - run: vendor/bin/php-cs-fixer fix --ansi --config=.php-cs-fixer.dist.php --diff --dry-run --verbose - - static-code-analysis: - name: "Static Code Analysis" - - runs-on: "ubuntu-latest" - - strategy: - matrix: - php: - - "8.0" - - steps: - - name: "Checkout" - uses: actions/checkout@v3 - - - name: "Set up PHP" - uses: shivammathur/setup-php@v2 - with: - coverage: none - php-version: ${{ matrix.php }} - - - name: "Install dependencies with composer" - uses: ramsey/composer-install@v2 - - - name: "Run vimeo/psalm" - run: vendor/bin/psalm --diff --show-info=false --stats --threads=4 - tests-mariadb: name: "Tests with MariaDB" @@ -148,3 +97,12 @@ jobs: run: vendor/bin/simple-phpunit env: TEST_DATABASE_DSN: postgres://user:password@127.0.0.1:${{ job.services.postgres.ports[5432] }}/messenger_monitor_bundle_test + + composer-validate: + uses: SymfonyCasts/.github/.github/workflows/composer-validate.yaml@main + + cs: + uses: SymfonyCasts/.github/.github/workflows/php-cs-fixer.yaml@main + + sca: + uses: SymfonyCasts/.github/.github/workflows/psalm.yaml@main From 56a78804b0f32ea2df6a549f9841ddaf964455a4 Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Thu, 25 May 2023 10:02:57 +0100 Subject: [PATCH 02/20] Fix CI, test on php 8.2 --- .github/workflows/ci.yaml | 9 ++++----- composer.json | 4 ++-- src/DependencyInjection/FailureReceiverPass.php | 3 --- src/DependencyInjection/ReceiverLocatorPass.php | 3 --- src/Storage/Doctrine/StoredMessage.php | 2 +- .../EventListener/AddStampOnMessageSentListenerTest.php | 2 +- .../SaveStoredMessageOnMessageSentListenerTest.php | 2 +- tests/TestKernel.php | 6 ------ tests/TestableMessageHandler.php | 5 +++-- 9 files changed, 12 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a4ba0b7..d0bb2e1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,15 +17,15 @@ jobs: fail-fast: false matrix: php: - - "8.0" - "8.1" + - "8.2" dependencies: - "lowest" - "highest" services: mariadb: - image: mariadb:latest + image: mariadb:10.11 ports: - 3306 env: @@ -33,8 +33,7 @@ jobs: MYSQL_PASSWORD: password MYSQL_DATABASE: messenger_monitor_bundle_test MYSQL_ROOT_PASSWORD: password - options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 - + options: --health-cmd "mysqladmin ping --silent" steps: - name: "Checkout" uses: actions/checkout@v3 @@ -64,8 +63,8 @@ jobs: fail-fast: false matrix: php: - - "8.0" - "8.1" + - "8.2" postgres-version: - "14" diff --git a/composer.json b/composer.json index 8ed3873..88609d7 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Symfony bundle for information about your Messenger queues and transports", "type": "symfony-bundle", "require": { - "php": "^8.0", + "php": "^8.1", "ext-json": "*", "symfony/config": "^5.4|^6.0", "symfony/dependency-injection": "^5.4|^6.0", @@ -21,7 +21,7 @@ "doctrine/dbal": "^2.13.3", "doctrine/doctrine-bundle": "^2.0", "doctrine/orm": "^2.10", - "friendsofphp/php-cs-fixer": "^3.11", + "php-cs-fixer/shim": "^3.17", "symfony/browser-kit": "^5.4|^6.0", "symfony/css-selector": "^5.4|^6.0", "symfony/doctrine-messenger": "^6.0", diff --git a/src/DependencyInjection/FailureReceiverPass.php b/src/DependencyInjection/FailureReceiverPass.php index e64079a..68d5436 100644 --- a/src/DependencyInjection/FailureReceiverPass.php +++ b/src/DependencyInjection/FailureReceiverPass.php @@ -12,9 +12,6 @@ */ final class FailureReceiverPass implements CompilerPassInterface { - /** - * {@inheritdoc} - */ public function process(ContainerBuilder $container): void { if (!$container->hasDefinition('symfonycasts.messenger_monitor.failed_receiver.name')) { diff --git a/src/DependencyInjection/ReceiverLocatorPass.php b/src/DependencyInjection/ReceiverLocatorPass.php index d27e0e0..e532f34 100644 --- a/src/DependencyInjection/ReceiverLocatorPass.php +++ b/src/DependencyInjection/ReceiverLocatorPass.php @@ -12,9 +12,6 @@ */ final class ReceiverLocatorPass implements CompilerPassInterface { - /** - * {@inheritdoc} - */ public function process(ContainerBuilder $container): void { if ($container->hasDefinition('symfonycasts.messenger_monitor.receiver_locator') diff --git a/src/Storage/Doctrine/StoredMessage.php b/src/Storage/Doctrine/StoredMessage.php index 8dde6b8..a826e1a 100644 --- a/src/Storage/Doctrine/StoredMessage.php +++ b/src/Storage/Doctrine/StoredMessage.php @@ -17,7 +17,7 @@ final class StoredMessage private ?\DateTimeImmutable $handledAt = null; private ?\DateTimeImmutable $failedAt = null; - public function __construct(private string $messageUid, private string $messageClass, private \DateTimeImmutable $dispatchedAt, private ?int $id = null, ?\DateTimeImmutable $receivedAt = null, ?\DateTimeImmutable $handledAt = null, ?\DateTimeImmutable $failedAt = null, private ?string $receiverName = null) + public function __construct(private string $messageUid, private string $messageClass, private \DateTimeImmutable $dispatchedAt, private ?int $id = null, \DateTimeImmutable $receivedAt = null, \DateTimeImmutable $handledAt = null, \DateTimeImmutable $failedAt = null, private ?string $receiverName = null) { if (null !== $receivedAt) { $this->receivedAt = $receivedAt; diff --git a/tests/EventListener/AddStampOnMessageSentListenerTest.php b/tests/EventListener/AddStampOnMessageSentListenerTest.php index 98cf103..7aedbd4 100644 --- a/tests/EventListener/AddStampOnMessageSentListenerTest.php +++ b/tests/EventListener/AddStampOnMessageSentListenerTest.php @@ -16,7 +16,7 @@ final class AddStampOnMessageSentListenerTest extends TestCase public function testAddStampOnMessageSent(): void { $listener = new AddStampOnMessageSentListener(); - $listener->onMessageSent($event = new SendMessageToTransportsEvent(new Envelope(new TestableMessage()))); + $listener->onMessageSent($event = new SendMessageToTransportsEvent(new Envelope(new TestableMessage()), [])); $this->assertNotNull($event->getEnvelope()->last(MonitorIdStamp::class)); } diff --git a/tests/Storage/Doctrine/EventListener/SaveStoredMessageOnMessageSentListenerTest.php b/tests/Storage/Doctrine/EventListener/SaveStoredMessageOnMessageSentListenerTest.php index b995b7d..52fa18f 100644 --- a/tests/Storage/Doctrine/EventListener/SaveStoredMessageOnMessageSentListenerTest.php +++ b/tests/Storage/Doctrine/EventListener/SaveStoredMessageOnMessageSentListenerTest.php @@ -34,6 +34,6 @@ static function (StoredMessage $storedMessage) use ($stamp): bool { ) ); - $listener->onMessageSent(new SendMessageToTransportsEvent($envelope)); + $listener->onMessageSent(new SendMessageToTransportsEvent($envelope, [])); } } diff --git a/tests/TestKernel.php b/tests/TestKernel.php index b1ad176..5c390a4 100644 --- a/tests/TestKernel.php +++ b/tests/TestKernel.php @@ -51,17 +51,11 @@ public function getCacheDir(): string return $this->getProjectDir().'/cache/'.md5(json_encode($this->bundleOptions)); } - /** - * {@inheritdoc} - */ protected function configureRoutes(RoutingConfigurator $routes) { $routes->import(__DIR__.'/../src/Resources/config/routing.xml'); } - /** - * {@inheritdoc} - */ protected function configureContainer(ContainerBuilder $container) { $container->setAlias( diff --git a/tests/TestableMessageHandler.php b/tests/TestableMessageHandler.php index a8d04b4..1ae22f9 100644 --- a/tests/TestableMessageHandler.php +++ b/tests/TestableMessageHandler.php @@ -4,9 +4,10 @@ namespace SymfonyCasts\MessengerMonitorBundle\Tests; -use Symfony\Component\Messenger\Handler\MessageHandlerInterface; +use Symfony\Component\Messenger\Attribute\AsMessageHandler; -final class TestableMessageHandler implements MessageHandlerInterface +#[AsMessageHandler] +final class TestableMessageHandler { public function __invoke(TestableMessage $message) { From ab8ad64f5c9fdd4d9c3efc058c0173e77545b200 Mon Sep 17 00:00:00 2001 From: Ryan Weaver Date: Thu, 22 Jun 2023 15:23:48 -0400 Subject: [PATCH 03/20] Adding note that this bundle is unstable & experimental --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index fcfc25c..3710761 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ Messenger Monitor --- +**THIS BUNDLE IS EXPERIMENTAL & UNSTABLE** and may not work and probably isn't ready for production. +It's also super rough. A Symfony Bundle to show you information about your Messenger queues/transports From 39b4ed405faa87ccd50af6f31cdd5b4e9305bbce Mon Sep 17 00:00:00 2001 From: Victor Bocharsky Date: Fri, 23 Jun 2023 11:46:38 +0300 Subject: [PATCH 04/20] Convert note into GitHub note and minor formatting tweaks in README --- README.md | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 3710761..a3eeb81 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,36 @@ Messenger Monitor ---- +================= -**THIS BUNDLE IS EXPERIMENTAL & UNSTABLE** and may not work and probably isn't ready for production. -It's also super rough. +> **Note** +> **THIS BUNDLE IS EXPERIMENTAL & UNSTABLE** and may not work and probably isn't ready for production. +> It's also super rough and currently is in a development phase. -A Symfony Bundle to show you information about your Messenger queues/transports +A Symfony Bundle to show you information about your Messenger queues/transports. -This is in a development phase +### Implemented Features -Implemented Features * Show queue length in console (configure interval) -Planned Features +### Planned Features + * Add admin route to see the queues in the browser * Auto Refresh * Refactor queue information to allow additional data * Collect data (how? TBD) * Show more queue information (avg time, ago, ...) -Phase 2 -* Realtime updates in browser (use TURTED_reactphp) +### Phase 2 + +* Realtime updates in the browser (use TURTED_reactphp) Installation -============ +------------ Make sure Composer is installed globally, as explained in the [installation chapter](https://getcomposer.org/doc/00-intro.md) of the Composer documentation. -Applications that use Symfony Flex ----------------------------------- +### Applications that use Symfony Flex Open a command console, enter your project directory and execute: @@ -37,10 +38,9 @@ Open a command console, enter your project directory and execute: $ composer require symfonycasts/messenger-monitor-bundle ``` -Applications that don't use Symfony Flex ----------------------------------------- +### Applications that don't use Symfony Flex -### Step 1: Download the Bundle +#### Step 1: Download the Bundle Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle: @@ -49,7 +49,7 @@ following command to download the latest stable version of this bundle: $ composer require symfonycasts/messenger-monitor-bundle ``` -### Step 2: Enable the Bundle +#### Step 2: Enable the Bundle Then, enable the bundle by adding it to the list of registered bundles in the `config/bundles.php` file of your project: @@ -64,15 +64,10 @@ return [ ``` Usage -===== - -```bin/console messenger:monitor``` to refresh every 3 seconds (default) - -```bin/console messenger:monitor -i 0``` to get the information only once -```bin/console messenger:monitor -i 1``` to refresh every second - -Check ```bin/console help messenger:monitor``` for more information - - +----- +- `bin/console messenger:monitor` to refresh every 3 seconds (default) +- `bin/console messenger:monitor -i 0` to get the information only once +- `bin/console messenger:monitor -i 1` to refresh every second +Check `bin/console help messenger:monitor` for more information. From 8019794e1c8a12b4cc820f07d5299cab3c7542c1 Mon Sep 17 00:00:00 2001 From: Victor Bocharsky Date: Tue, 28 Nov 2023 20:49:41 +0100 Subject: [PATCH 05/20] Add PHP 8.3 support --- .github/workflows/ci.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d0bb2e1..3909381 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -19,6 +19,7 @@ jobs: php: - "8.1" - "8.2" + - "8.3" dependencies: - "lowest" - "highest" @@ -65,6 +66,7 @@ jobs: php: - "8.1" - "8.2" + - "8.3" postgres-version: - "14" From a2656b6b81c372f93ef51813e47658aa6116f1a1 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:33:42 -0400 Subject: [PATCH 06/20] minor #58 [ci] php-cs-fixer it up --- src/Storage/Doctrine/StoredMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Storage/Doctrine/StoredMessage.php b/src/Storage/Doctrine/StoredMessage.php index a826e1a..8dde6b8 100644 --- a/src/Storage/Doctrine/StoredMessage.php +++ b/src/Storage/Doctrine/StoredMessage.php @@ -17,7 +17,7 @@ final class StoredMessage private ?\DateTimeImmutable $handledAt = null; private ?\DateTimeImmutable $failedAt = null; - public function __construct(private string $messageUid, private string $messageClass, private \DateTimeImmutable $dispatchedAt, private ?int $id = null, \DateTimeImmutable $receivedAt = null, \DateTimeImmutable $handledAt = null, \DateTimeImmutable $failedAt = null, private ?string $receiverName = null) + public function __construct(private string $messageUid, private string $messageClass, private \DateTimeImmutable $dispatchedAt, private ?int $id = null, ?\DateTimeImmutable $receivedAt = null, ?\DateTimeImmutable $handledAt = null, ?\DateTimeImmutable $failedAt = null, private ?string $receiverName = null) { if (null !== $receivedAt) { $this->receivedAt = $receivedAt; From ffaf5233cbc08345acf3162da06898c893aaaa15 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Tue, 9 Apr 2024 13:37:35 -0400 Subject: [PATCH 07/20] minor #57 [ci] use phpstan instead of psalm --- .github/workflows/ci.yaml | 5 +++- composer.json | 4 ++-- phpstan-baseline.neon | 26 ++++++++++++++++++++ phpstan.dist.neon | 12 ++++++++++ psalm.xml | 29 ----------------------- src/DependencyInjection/Configuration.php | 3 +-- 6 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.dist.neon delete mode 100644 psalm.xml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d0bb2e1..a9ecfa4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -104,4 +104,7 @@ jobs: uses: SymfonyCasts/.github/.github/workflows/php-cs-fixer.yaml@main sca: - uses: SymfonyCasts/.github/.github/workflows/psalm.yaml@main + uses: SymfonyCasts/.github/.github/workflows/phpstan.yaml@main + with: + php: 8.1 + install-phpunit-bridge: true diff --git a/composer.json b/composer.json index 88609d7..c432d40 100644 --- a/composer.json +++ b/composer.json @@ -22,12 +22,12 @@ "doctrine/doctrine-bundle": "^2.0", "doctrine/orm": "^2.10", "php-cs-fixer/shim": "^3.17", + "phpstan/phpstan": "^1.11.x-dev", "symfony/browser-kit": "^5.4|^6.0", "symfony/css-selector": "^5.4|^6.0", "symfony/doctrine-messenger": "^6.0", "symfony/phpunit-bridge": "^5.4|^6.0", - "symfony/security-bundle": "^5.4|^6.0", - "vimeo/psalm": "^4.0" + "symfony/security-bundle": "^5.4|^6.0" }, "conflict": { "symfony/doctrine-bridge": "<5.4" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..99d8fe7 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,26 @@ +parameters: + ignoreErrors: + - + message: "#^Method SymfonyCasts\\\\MessengerMonitorBundle\\\\Exception\\\\ReceiverDoesNotExistException\\:\\:__construct\\(\\) has parameter \\$availableReceivers with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Exception/ReceiverDoesNotExistException.php + + - + message: "#^Method SymfonyCasts\\\\MessengerMonitorBundle\\\\Locator\\\\ReceiverLocator\\:\\:__construct\\(\\) has parameter \\$receiverLocator with generic interface Symfony\\\\Contracts\\\\Service\\\\ServiceProviderInterface but does not specify its types\\: T$#" + count: 1 + path: src/Locator/ReceiverLocator.php + + - + message: "#^Method SymfonyCasts\\\\MessengerMonitorBundle\\\\Locator\\\\ReceiverLocator\\:\\:__construct\\(\\) has parameter \\$receiverNames with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Locator/ReceiverLocator.php + + - + message: "#^Method SymfonyCasts\\\\MessengerMonitorBundle\\\\Storage\\\\Doctrine\\\\Connection\\:\\:executeQuery\\(\\) has parameter \\$parameters with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Storage/Doctrine/Connection.php + + - + message: "#^Method SymfonyCasts\\\\MessengerMonitorBundle\\\\Storage\\\\Doctrine\\\\Connection\\:\\:executeQuery\\(\\) has parameter \\$types with no value type specified in iterable type array\\.$#" + count: 1 + path: src/Storage/Doctrine/Connection.php diff --git a/phpstan.dist.neon b/phpstan.dist.neon new file mode 100644 index 0000000..2f4e641 --- /dev/null +++ b/phpstan.dist.neon @@ -0,0 +1,12 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 6 + bootstrapFiles: + - vendor/autoload.php + paths: + - src +# - tests + excludePaths: + - tests/tmp/* diff --git a/psalm.xml b/psalm.xml deleted file mode 100644 index f16268f..0000000 --- a/psalm.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 44220dd..ce8e8df 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -18,8 +18,7 @@ public function getConfigTreeBuilder(): TreeBuilder $treeBuilder = new TreeBuilder('symfonycasts_messenger_monitor'); $rootNode = $treeBuilder->getRootNode(); - /** @psalm-suppress PossiblyUndefinedMethod */ - $rootNode + $rootNode /** @phpstan-ignore-line method.notFound (The last end() call) */ ->children() ->enumNode('driver') ->defaultValue('doctrine') From 8ab1d7e18872fc00881e7b7d2c5fc2c1a8525253 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Wed, 12 Jun 2024 06:49:48 -0400 Subject: [PATCH 08/20] minor #59 [dx] keep tooling in one place - `composer tools:run` runs `php-cs-fixer` & `phpstan` - `composer tools:run:php-cs-fixer` run only `php-cs-fixer` (works for `phpstan` as well). - `composer tools:upgrade` upgrades / installs all of the `tools/*` - `composer tools:upgrade:php-cs-fixer` Upgrades / installs only `php-cs-fixer` (works for `phpstan` as well) --- composer.json | 17 +++++++++++++++-- tools/.gitignore | 2 ++ tools/php-cs-fixer/composer.json | 5 +++++ tools/phpstan/composer.json | 5 +++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tools/.gitignore create mode 100644 tools/php-cs-fixer/composer.json create mode 100644 tools/phpstan/composer.json diff --git a/composer.json b/composer.json index c432d40..e8f8187 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,6 @@ "doctrine/doctrine-bundle": "^2.0", "doctrine/orm": "^2.10", "php-cs-fixer/shim": "^3.17", - "phpstan/phpstan": "^1.11.x-dev", "symfony/browser-kit": "^5.4|^6.0", "symfony/css-selector": "^5.4|^6.0", "symfony/doctrine-messenger": "^6.0", @@ -56,5 +55,19 @@ "name": "Nicolas PHILIPPE", "email": "nikophil@gmail.com" } - ] + ], + "scripts": { + "tools:upgrade": [ + "@tools:upgrade:php-cs-fixer", + "@tools:upgrade:phpstan" + ], + "tools:upgrade:php-cs-fixer": "composer upgrade -W -d tools/php-cs-fixer", + "tools:upgrade:phpstan": "composer upgrade -W -d tools/phpstan", + "tools:run": [ + "@tools:run:php-cs-fixer", + "@tools:run:phpstan" + ], + "tools:run:php-cs-fixer": "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix", + "tools:run:phpstan": "tools/phpstan/vendor/bin/phpstan --memory-limit=1G" + } } diff --git a/tools/.gitignore b/tools/.gitignore new file mode 100644 index 0000000..af5e68f --- /dev/null +++ b/tools/.gitignore @@ -0,0 +1,2 @@ +**/vendor +**/composer.lock diff --git a/tools/php-cs-fixer/composer.json b/tools/php-cs-fixer/composer.json new file mode 100644 index 0000000..2d76bbe --- /dev/null +++ b/tools/php-cs-fixer/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "friendsofphp/php-cs-fixer": "^3" + } +} diff --git a/tools/phpstan/composer.json b/tools/phpstan/composer.json new file mode 100644 index 0000000..f53376b --- /dev/null +++ b/tools/phpstan/composer.json @@ -0,0 +1,5 @@ +{ + "require": { + "phpstan/phpstan": "^1" + } +} From 3d35da3443cc4ddd0e3534fbc97fb994cdf46878 Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Wed, 10 Jul 2024 13:35:57 -0400 Subject: [PATCH 09/20] fix: switch from Doctrine event subscriber to listener Event subscribers are deprecated in orm 2.x and removed in 3.x. --- src/Resources/config/doctrine.xml | 2 +- .../EventListener/CreateSchemaListener.php | 15 +-------------- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/Resources/config/doctrine.xml b/src/Resources/config/doctrine.xml index 07caf95..182c5ef 100644 --- a/src/Resources/config/doctrine.xml +++ b/src/Resources/config/doctrine.xml @@ -43,7 +43,7 @@ - + diff --git a/src/Storage/Doctrine/EventListener/CreateSchemaListener.php b/src/Storage/Doctrine/EventListener/CreateSchemaListener.php index 92df6e4..c318e66 100644 --- a/src/Storage/Doctrine/EventListener/CreateSchemaListener.php +++ b/src/Storage/Doctrine/EventListener/CreateSchemaListener.php @@ -4,16 +4,14 @@ namespace SymfonyCasts\MessengerMonitorBundle\Storage\Doctrine\EventListener; -use Doctrine\Common\EventSubscriber; use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs; -use Doctrine\ORM\Tools\ToolEvents; use Psr\Container\ContainerInterface; use SymfonyCasts\MessengerMonitorBundle\Storage\Doctrine\Connection; /** * @internal */ -final class CreateSchemaListener implements EventSubscriber +final class CreateSchemaListener { public function __construct(private ContainerInterface $container) { @@ -26,15 +24,4 @@ public function postGenerateSchema(GenerateSchemaEventArgs $event): void $event->getEntityManager()->getConnection() ); } - - public function getSubscribedEvents(): array - { - if (!class_exists(ToolEvents::class)) { - return []; - } - - return [ - ToolEvents::postGenerateSchema, - ]; - } } From a976318324ebc1e6b739017b5f7886f9e33138af Mon Sep 17 00:00:00 2001 From: Victor Bocharsky Date: Wed, 22 Nov 2023 20:44:28 +0100 Subject: [PATCH 10/20] Allow Symfony 7 --- composer.json | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index e8f8187..81ace70 100644 --- a/composer.json +++ b/composer.json @@ -5,16 +5,16 @@ "require": { "php": "^8.1", "ext-json": "*", - "symfony/config": "^5.4|^6.0", - "symfony/dependency-injection": "^5.4|^6.0", - "symfony/event-dispatcher": "^5.4|^6.0", - "symfony/framework-bundle": "^5.4|^6.0", - "symfony/http-foundation": "^5.4|^6.0", - "symfony/http-kernel": "^5.4|^6.0", - "symfony/messenger": "^5.4|^6.0", + "symfony/config": "^5.4|^6.0|^7.0", + "symfony/dependency-injection": "^5.4|^6.0|^7.0", + "symfony/event-dispatcher": "^5.4|^6.0|^7.0", + "symfony/framework-bundle": "^5.4|^6.0|^7.0", + "symfony/http-foundation": "^5.4|^6.0|^7.0", + "symfony/http-kernel": "^5.4|^6.0|^7.0", + "symfony/messenger": "^5.4|^6.0|^7.0", "symfony/polyfill-uuid": "^1.23", - "symfony/routing": "^5.4|^6.0", - "symfony/twig-bundle": "^5.4|^6.0", + "symfony/routing": "^5.4|^6.0|^7.0", + "symfony/twig-bundle": "^5.4|^6.0|^7.0", "twig/twig": "^2.14.7|^3.0" }, "require-dev": { @@ -22,11 +22,11 @@ "doctrine/doctrine-bundle": "^2.0", "doctrine/orm": "^2.10", "php-cs-fixer/shim": "^3.17", - "symfony/browser-kit": "^5.4|^6.0", - "symfony/css-selector": "^5.4|^6.0", - "symfony/doctrine-messenger": "^6.0", - "symfony/phpunit-bridge": "^5.4|^6.0", - "symfony/security-bundle": "^5.4|^6.0" + "symfony/browser-kit": "^5.4|^6.0|^7.0", + "symfony/css-selector": "^5.4|^6.0|^7.0", + "symfony/doctrine-messenger": "^6.0|^7.0", + "symfony/phpunit-bridge": "^5.4|^6.0|^7.0", + "symfony/security-bundle": "^5.4|^6.0|^7.0" }, "conflict": { "symfony/doctrine-bridge": "<5.4" From 2f224b7a1c157fd60d9227cd92103e7632e6a639 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow Date: Tue, 30 Jul 2024 05:04:24 -0400 Subject: [PATCH 11/20] [ci] php-cs-fixer it up --- src/Controller/RejectFailedMessageController.php | 4 ++-- src/Controller/RetryFailedMessageController.php | 4 ++-- src/Exception/ReceiverDoesNotExistException.php | 4 ++-- src/FailedMessage/FailedMessageRejecter.php | 2 +- src/FailedMessage/FailedMessageRetryer.php | 2 +- .../MetricsAlreadyAddedForMessageClassException.php | 2 +- src/Storage/Doctrine/Connection.php | 4 ++-- src/Storage/Doctrine/ConnectionFactory.php | 4 ++-- src/Storage/Doctrine/Driver/MySQLDriver.php | 2 +- src/Storage/Doctrine/Driver/PostgreSQLDriver.php | 2 +- src/Storage/Doctrine/StoredMessageProvider.php | 2 +- src/Twig/TimeDisplayExtension.php | 8 ++++---- tests/FunctionalTests/AbstractFunctionalTests.php | 4 ++-- .../FunctionalTests/RejectFailedMessageControllerTest.php | 4 ++-- .../FunctionalTests/RetryFailedMessageControllerTest.php | 4 ++-- .../IntegrationTests/AbstractDoctrineIntegrationTests.php | 4 ++-- tests/Storage/Doctrine/StoredMessageProviderTest.php | 2 +- 17 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Controller/RejectFailedMessageController.php b/src/Controller/RejectFailedMessageController.php index cf79860..78372be 100644 --- a/src/Controller/RejectFailedMessageController.php +++ b/src/Controller/RejectFailedMessageController.php @@ -29,9 +29,9 @@ public function __invoke(int $id): RedirectResponse try { $this->failedMessageRejecter->rejectFailedMessage($id); - $sessionBag->add('messenger_monitor.success', sprintf('Message with id "%s" correctly rejected.', $id)); + $sessionBag->add('messenger_monitor.success', \sprintf('Message with id "%s" correctly rejected.', $id)); } catch (\Exception $exception) { - $sessionBag->add('messenger_monitor.error', sprintf('Error while rejecting message with id "%s": %s', $id, $exception->getMessage())); + $sessionBag->add('messenger_monitor.error', \sprintf('Error while rejecting message with id "%s": %s', $id, $exception->getMessage())); } return new RedirectResponse($this->urlGenerator->generate('symfonycasts.messenger_monitor.dashboard')); diff --git a/src/Controller/RetryFailedMessageController.php b/src/Controller/RetryFailedMessageController.php index 0bc9c32..e0d9951 100644 --- a/src/Controller/RetryFailedMessageController.php +++ b/src/Controller/RetryFailedMessageController.php @@ -29,9 +29,9 @@ public function __invoke(int $id): RedirectResponse try { $this->failedMessageRetryer->retryFailedMessage($id); - $sessionBag->add('messenger_monitor.success', sprintf('Message with id "%s" correctly retried.', $id)); + $sessionBag->add('messenger_monitor.success', \sprintf('Message with id "%s" correctly retried.', $id)); } catch (\Exception $exception) { - $sessionBag->add('messenger_monitor.error', sprintf('Error while retrying message with id "%s": %s', $id, $exception->getMessage())); + $sessionBag->add('messenger_monitor.error', \sprintf('Error while retrying message with id "%s": %s', $id, $exception->getMessage())); } return new RedirectResponse($this->urlGenerator->generate('symfonycasts.messenger_monitor.dashboard')); diff --git a/src/Exception/ReceiverDoesNotExistException.php b/src/Exception/ReceiverDoesNotExistException.php index 7c54d56..bd363e6 100644 --- a/src/Exception/ReceiverDoesNotExistException.php +++ b/src/Exception/ReceiverDoesNotExistException.php @@ -13,9 +13,9 @@ final class ReceiverDoesNotExistException extends RuntimeException { public function __construct(string $receiverName, array $availableReceivers = []) { - $message = sprintf('The receiver "%s" does not exist.', $receiverName); + $message = \sprintf('The receiver "%s" does not exist.', $receiverName); if (\count($availableReceivers)) { - $message .= sprintf(' Valid receivers are: %s.', implode(', ', $availableReceivers)); + $message .= \sprintf(' Valid receivers are: %s.', implode(', ', $availableReceivers)); } parent::__construct($message); diff --git a/src/FailedMessage/FailedMessageRejecter.php b/src/FailedMessage/FailedMessageRejecter.php index 88919c7..4cab592 100644 --- a/src/FailedMessage/FailedMessageRejecter.php +++ b/src/FailedMessage/FailedMessageRejecter.php @@ -22,7 +22,7 @@ public function rejectFailedMessage(int $id): void $envelope = $failureReceiver->find($id); if (null === $envelope) { - throw new \RuntimeException(sprintf('The message with id "%s" was not found.', $id)); + throw new \RuntimeException(\sprintf('The message with id "%s" was not found.', $id)); } $failureReceiver->reject($envelope); diff --git a/src/FailedMessage/FailedMessageRetryer.php b/src/FailedMessage/FailedMessageRetryer.php index a038920..91b44aa 100644 --- a/src/FailedMessage/FailedMessageRetryer.php +++ b/src/FailedMessage/FailedMessageRetryer.php @@ -38,7 +38,7 @@ public function retryFailedMessage(int $id): void $envelope = $failureReceiver->find($id); if (null === $envelope) { - throw new \RuntimeException(sprintf('The message "%s" was not found.', $id)); + throw new \RuntimeException(\sprintf('The message "%s" was not found.', $id)); } /** @var MonitorIdStamp|null $monitorIdStamp */ diff --git a/src/Statistics/MetricsAlreadyAddedForMessageClassException.php b/src/Statistics/MetricsAlreadyAddedForMessageClassException.php index fe526b8..8a025d1 100644 --- a/src/Statistics/MetricsAlreadyAddedForMessageClassException.php +++ b/src/Statistics/MetricsAlreadyAddedForMessageClassException.php @@ -8,6 +8,6 @@ final class MetricsAlreadyAddedForMessageClassException extends \RuntimeExceptio { public function __construct(string $messageClass) { - parent::__construct(sprintf('Metrics already added for message class "%s"', $messageClass)); + parent::__construct(\sprintf('Metrics already added for message class "%s"', $messageClass)); } } diff --git a/src/Storage/Doctrine/Connection.php b/src/Storage/Doctrine/Connection.php index 65656bf..66e8261 100644 --- a/src/Storage/Doctrine/Connection.php +++ b/src/Storage/Doctrine/Connection.php @@ -110,8 +110,8 @@ public function getStatistics(\DateTimeImmutable $fromDate, \DateTimeImmutable $ $statement = $this->executeQuery( $this->driverConnection->createQueryBuilder() ->select('count(id) as count_messages_on_period, class') - ->addSelect(sprintf('AVG(%s) AS average_waiting_time', $this->SQLDriver->getDateDiffInSecondsExpression('received_at', 'dispatched_at'))) - ->addSelect(sprintf('AVG(%s) AS average_handling_time', $this->SQLDriver->getDateDiffInSecondsExpression('handled_at', 'received_at'))) + ->addSelect(\sprintf('AVG(%s) AS average_waiting_time', $this->SQLDriver->getDateDiffInSecondsExpression('received_at', 'dispatched_at'))) + ->addSelect(\sprintf('AVG(%s) AS average_handling_time', $this->SQLDriver->getDateDiffInSecondsExpression('handled_at', 'received_at'))) ->from($this->tableName) ->where('handled_at >= :from_date') ->andWhere('handled_at <= :to_date') diff --git a/src/Storage/Doctrine/ConnectionFactory.php b/src/Storage/Doctrine/ConnectionFactory.php index 90729cb..0d3a05f 100644 --- a/src/Storage/Doctrine/ConnectionFactory.php +++ b/src/Storage/Doctrine/ConnectionFactory.php @@ -29,12 +29,12 @@ public function __invoke(): Connection $driver = match ($databasePlatform) { 'mysql' => new MySQLDriver(), 'postgresql' => new PostgreSQLDriver(), - default => throw new InvalidConfigurationException(sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) + default => throw new InvalidConfigurationException(\sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) }; return new Connection($driverConnection, $driver, $this->tableName); } catch (\InvalidArgumentException) { - throw new InvalidConfigurationException(sprintf('Doctrine connection with name "%s" does not exist', $this->connectionName)); + throw new InvalidConfigurationException(\sprintf('Doctrine connection with name "%s" does not exist', $this->connectionName)); } } } diff --git a/src/Storage/Doctrine/Driver/MySQLDriver.php b/src/Storage/Doctrine/Driver/MySQLDriver.php index 214125b..fee44ad 100644 --- a/src/Storage/Doctrine/Driver/MySQLDriver.php +++ b/src/Storage/Doctrine/Driver/MySQLDriver.php @@ -11,6 +11,6 @@ final class MySQLDriver implements SQLDriverInterface { public function getDateDiffInSecondsExpression(string $fieldFrom, string $fieldTo): string { - return sprintf('TIME_TO_SEC(TIMEDIFF(%s, %s))', $fieldFrom, $fieldTo); + return \sprintf('TIME_TO_SEC(TIMEDIFF(%s, %s))', $fieldFrom, $fieldTo); } } diff --git a/src/Storage/Doctrine/Driver/PostgreSQLDriver.php b/src/Storage/Doctrine/Driver/PostgreSQLDriver.php index ee3e9f1..c37f4ac 100644 --- a/src/Storage/Doctrine/Driver/PostgreSQLDriver.php +++ b/src/Storage/Doctrine/Driver/PostgreSQLDriver.php @@ -11,6 +11,6 @@ final class PostgreSQLDriver implements SQLDriverInterface { public function getDateDiffInSecondsExpression(string $fieldFrom, string $fieldTo): string { - return sprintf('extract(epoch from (%s - %s))', $fieldFrom, $fieldTo); + return \sprintf('extract(epoch from (%s - %s))', $fieldFrom, $fieldTo); } } diff --git a/src/Storage/Doctrine/StoredMessageProvider.php b/src/Storage/Doctrine/StoredMessageProvider.php index 5bb16a8..83f3b60 100644 --- a/src/Storage/Doctrine/StoredMessageProvider.php +++ b/src/Storage/Doctrine/StoredMessageProvider.php @@ -33,7 +33,7 @@ public function getStoredMessage(Envelope $envelope): ?StoredMessage $storedMessage = $this->doctrineConnection->findMessage($monitorIdStamp->getId()); if (null === $storedMessage) { - $this->logError(sprintf('Message with id "%s" not found', $monitorIdStamp->getId())); + $this->logError(\sprintf('Message with id "%s" not found', $monitorIdStamp->getId())); return null; } diff --git a/src/Twig/TimeDisplayExtension.php b/src/Twig/TimeDisplayExtension.php index cf828d3..78a9e86 100644 --- a/src/Twig/TimeDisplayExtension.php +++ b/src/Twig/TimeDisplayExtension.php @@ -21,21 +21,21 @@ public function formatTime(float $seconds): string if ($seconds < 10) { $seconds = round($seconds, 2); - return sprintf('%s %s', $seconds, $this->pluralize('second', $seconds)); + return \sprintf('%s %s', $seconds, $this->pluralize('second', $seconds)); } if ($seconds < 60) { - return sprintf('%d seconds', round($seconds)); + return \sprintf('%d seconds', round($seconds)); } $minutes = (int) floor($seconds / 60); $intSeconds = (int) $seconds % 60; if (0 === $intSeconds) { - return sprintf('%d %s', $minutes, $this->pluralize('minute', $minutes)); + return \sprintf('%d %s', $minutes, $this->pluralize('minute', $minutes)); } - return sprintf('%d %s %d %s', $minutes, $this->pluralize('minute', $minutes), $intSeconds, $this->pluralize('second', $intSeconds)); + return \sprintf('%d %s %d %s', $minutes, $this->pluralize('minute', $minutes), $intSeconds, $this->pluralize('second', $intSeconds)); } private function pluralize(string $word, float $number): string diff --git a/tests/FunctionalTests/AbstractFunctionalTests.php b/tests/FunctionalTests/AbstractFunctionalTests.php index 130e17b..cdb454c 100644 --- a/tests/FunctionalTests/AbstractFunctionalTests.php +++ b/tests/FunctionalTests/AbstractFunctionalTests.php @@ -44,7 +44,7 @@ protected function setUp(): void try { $connection->connect(); } catch (\Exception $exception) { - self::markTestSkipped(sprintf('Can\'t connect to connection: %s', $exception->getMessage())); + self::markTestSkipped(\sprintf('Can\'t connect to connection: %s', $exception->getMessage())); } $connection->executeQuery('DROP TABLE IF EXISTS messenger_messages'); @@ -54,7 +54,7 @@ protected function setUp(): void $truncateTable = match ($databasePlatform) { 'mysql' => 'TRUNCATE TABLE messenger_monitor', 'postgresql' => 'TRUNCATE TABLE messenger_monitor RESTART IDENTITY', - default => throw new InvalidConfigurationException(sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) + default => throw new InvalidConfigurationException(\sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) }; try { diff --git a/tests/FunctionalTests/RejectFailedMessageControllerTest.php b/tests/FunctionalTests/RejectFailedMessageControllerTest.php index 6bfb408..1299d90 100644 --- a/tests/FunctionalTests/RejectFailedMessageControllerTest.php +++ b/tests/FunctionalTests/RejectFailedMessageControllerTest.php @@ -12,11 +12,11 @@ public function testRejectFailedMessageSuccess(): void $this->handleMessage($envelope, 'queue'); $this->client->followRedirects(); - $crawler = $this->client->request('GET', sprintf('/failed-message/reject/%s', $id = $this->getLastFailedMessageId())); + $crawler = $this->client->request('GET', \sprintf('/failed-message/reject/%s', $id = $this->getLastFailedMessageId())); self::assertResponseIsSuccessful(); $this->assertQueuesCounts(['queue' => 0, 'failed' => 0], $crawler); - $this->assertAlertIsPresent($crawler, '.alert-success', sprintf('Message with id "%s" correctly rejected.', $id)); + $this->assertAlertIsPresent($crawler, '.alert-success', \sprintf('Message with id "%s" correctly rejected.', $id)); } public function testRejectFailedMessageFails(): void diff --git a/tests/FunctionalTests/RetryFailedMessageControllerTest.php b/tests/FunctionalTests/RetryFailedMessageControllerTest.php index 56151e1..dc6c0d5 100644 --- a/tests/FunctionalTests/RetryFailedMessageControllerTest.php +++ b/tests/FunctionalTests/RetryFailedMessageControllerTest.php @@ -12,11 +12,11 @@ public function testRetryFailedMessage(): void $this->handleMessage($envelope, 'queue'); $this->client->followRedirects(); - $crawler = $this->client->request('GET', sprintf('/failed-message/retry/%s', $id = $this->getLastFailedMessageId())); + $crawler = $this->client->request('GET', \sprintf('/failed-message/retry/%s', $id = $this->getLastFailedMessageId())); self::assertResponseIsSuccessful(); $this->assertQueuesCounts(['queue' => 0, 'failed' => 0], $crawler); - $this->assertAlertIsPresent($crawler, '.alert-success', sprintf('Message with id "%s" correctly retried.', $id)); + $this->assertAlertIsPresent($crawler, '.alert-success', \sprintf('Message with id "%s" correctly retried.', $id)); } public function testRetryFailedMessageFails(): void diff --git a/tests/IntegrationTests/AbstractDoctrineIntegrationTests.php b/tests/IntegrationTests/AbstractDoctrineIntegrationTests.php index 786d400..1431709 100644 --- a/tests/IntegrationTests/AbstractDoctrineIntegrationTests.php +++ b/tests/IntegrationTests/AbstractDoctrineIntegrationTests.php @@ -33,7 +33,7 @@ protected function setUp(): void try { $connection->connect(); } catch (\Exception $exception) { - $this->markTestSkipped(sprintf('Can\'t connect to connection: %s', $exception->getMessage())); + $this->markTestSkipped(\sprintf('Can\'t connect to connection: %s', $exception->getMessage())); } $this->doctrineConnection = self::getContainer()->get('test.symfonycasts.messenger_monitor.storage.doctrine_connection'); @@ -43,7 +43,7 @@ protected function setUp(): void $truncateTable = match ($databasePlatform) { 'mysql' => 'TRUNCATE TABLE messenger_monitor', 'postgresql' => 'TRUNCATE TABLE messenger_monitor RESTART IDENTITY', - default => throw new InvalidConfigurationException(sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) + default => throw new InvalidConfigurationException(\sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) }; try { diff --git a/tests/Storage/Doctrine/StoredMessageProviderTest.php b/tests/Storage/Doctrine/StoredMessageProviderTest.php index 946d363..8b75f53 100644 --- a/tests/Storage/Doctrine/StoredMessageProviderTest.php +++ b/tests/Storage/Doctrine/StoredMessageProviderTest.php @@ -38,7 +38,7 @@ public function testGetStoredMessageLogsAnErrorWhenStoredMessageNotFound(): void $envelope = new Envelope(new TestableMessage(), [$stamp = new MonitorIdStamp()]); $doctrineConnection->expects($this->once())->method('findMessage')->with($stamp->getId())->willReturn(null); - $logger->expects($this->once())->method('error')->with(sprintf('Message with id "%s" not found', $stamp->getId())); + $logger->expects($this->once())->method('error')->with(\sprintf('Message with id "%s" not found', $stamp->getId())); $this->assertNull($storedMessageProvider->getStoredMessage($envelope)); } From a07e41164464e8da8377dc6b8c44cb5bebfdb885 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Tue, 30 Jul 2024 11:50:10 +0200 Subject: [PATCH 12/20] Fix CS --- src/Controller/RejectFailedMessageController.php | 4 ++-- src/Controller/RetryFailedMessageController.php | 4 ++-- src/Exception/ReceiverDoesNotExistException.php | 4 ++-- src/FailedMessage/FailedMessageRejecter.php | 2 +- src/FailedMessage/FailedMessageRetryer.php | 2 +- .../MetricsAlreadyAddedForMessageClassException.php | 2 +- src/Storage/Doctrine/Connection.php | 4 ++-- src/Storage/Doctrine/ConnectionFactory.php | 4 ++-- src/Storage/Doctrine/Driver/MySQLDriver.php | 2 +- src/Storage/Doctrine/Driver/PostgreSQLDriver.php | 2 +- src/Storage/Doctrine/StoredMessageProvider.php | 2 +- src/Twig/TimeDisplayExtension.php | 8 ++++---- tests/FunctionalTests/AbstractFunctionalTests.php | 4 ++-- .../FunctionalTests/RejectFailedMessageControllerTest.php | 4 ++-- .../FunctionalTests/RetryFailedMessageControllerTest.php | 4 ++-- .../IntegrationTests/AbstractDoctrineIntegrationTests.php | 4 ++-- tests/Storage/Doctrine/StoredMessageProviderTest.php | 2 +- 17 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Controller/RejectFailedMessageController.php b/src/Controller/RejectFailedMessageController.php index cf79860..78372be 100644 --- a/src/Controller/RejectFailedMessageController.php +++ b/src/Controller/RejectFailedMessageController.php @@ -29,9 +29,9 @@ public function __invoke(int $id): RedirectResponse try { $this->failedMessageRejecter->rejectFailedMessage($id); - $sessionBag->add('messenger_monitor.success', sprintf('Message with id "%s" correctly rejected.', $id)); + $sessionBag->add('messenger_monitor.success', \sprintf('Message with id "%s" correctly rejected.', $id)); } catch (\Exception $exception) { - $sessionBag->add('messenger_monitor.error', sprintf('Error while rejecting message with id "%s": %s', $id, $exception->getMessage())); + $sessionBag->add('messenger_monitor.error', \sprintf('Error while rejecting message with id "%s": %s', $id, $exception->getMessage())); } return new RedirectResponse($this->urlGenerator->generate('symfonycasts.messenger_monitor.dashboard')); diff --git a/src/Controller/RetryFailedMessageController.php b/src/Controller/RetryFailedMessageController.php index 0bc9c32..e0d9951 100644 --- a/src/Controller/RetryFailedMessageController.php +++ b/src/Controller/RetryFailedMessageController.php @@ -29,9 +29,9 @@ public function __invoke(int $id): RedirectResponse try { $this->failedMessageRetryer->retryFailedMessage($id); - $sessionBag->add('messenger_monitor.success', sprintf('Message with id "%s" correctly retried.', $id)); + $sessionBag->add('messenger_monitor.success', \sprintf('Message with id "%s" correctly retried.', $id)); } catch (\Exception $exception) { - $sessionBag->add('messenger_monitor.error', sprintf('Error while retrying message with id "%s": %s', $id, $exception->getMessage())); + $sessionBag->add('messenger_monitor.error', \sprintf('Error while retrying message with id "%s": %s', $id, $exception->getMessage())); } return new RedirectResponse($this->urlGenerator->generate('symfonycasts.messenger_monitor.dashboard')); diff --git a/src/Exception/ReceiverDoesNotExistException.php b/src/Exception/ReceiverDoesNotExistException.php index 7c54d56..bd363e6 100644 --- a/src/Exception/ReceiverDoesNotExistException.php +++ b/src/Exception/ReceiverDoesNotExistException.php @@ -13,9 +13,9 @@ final class ReceiverDoesNotExistException extends RuntimeException { public function __construct(string $receiverName, array $availableReceivers = []) { - $message = sprintf('The receiver "%s" does not exist.', $receiverName); + $message = \sprintf('The receiver "%s" does not exist.', $receiverName); if (\count($availableReceivers)) { - $message .= sprintf(' Valid receivers are: %s.', implode(', ', $availableReceivers)); + $message .= \sprintf(' Valid receivers are: %s.', implode(', ', $availableReceivers)); } parent::__construct($message); diff --git a/src/FailedMessage/FailedMessageRejecter.php b/src/FailedMessage/FailedMessageRejecter.php index 88919c7..4cab592 100644 --- a/src/FailedMessage/FailedMessageRejecter.php +++ b/src/FailedMessage/FailedMessageRejecter.php @@ -22,7 +22,7 @@ public function rejectFailedMessage(int $id): void $envelope = $failureReceiver->find($id); if (null === $envelope) { - throw new \RuntimeException(sprintf('The message with id "%s" was not found.', $id)); + throw new \RuntimeException(\sprintf('The message with id "%s" was not found.', $id)); } $failureReceiver->reject($envelope); diff --git a/src/FailedMessage/FailedMessageRetryer.php b/src/FailedMessage/FailedMessageRetryer.php index a038920..91b44aa 100644 --- a/src/FailedMessage/FailedMessageRetryer.php +++ b/src/FailedMessage/FailedMessageRetryer.php @@ -38,7 +38,7 @@ public function retryFailedMessage(int $id): void $envelope = $failureReceiver->find($id); if (null === $envelope) { - throw new \RuntimeException(sprintf('The message "%s" was not found.', $id)); + throw new \RuntimeException(\sprintf('The message "%s" was not found.', $id)); } /** @var MonitorIdStamp|null $monitorIdStamp */ diff --git a/src/Statistics/MetricsAlreadyAddedForMessageClassException.php b/src/Statistics/MetricsAlreadyAddedForMessageClassException.php index fe526b8..8a025d1 100644 --- a/src/Statistics/MetricsAlreadyAddedForMessageClassException.php +++ b/src/Statistics/MetricsAlreadyAddedForMessageClassException.php @@ -8,6 +8,6 @@ final class MetricsAlreadyAddedForMessageClassException extends \RuntimeExceptio { public function __construct(string $messageClass) { - parent::__construct(sprintf('Metrics already added for message class "%s"', $messageClass)); + parent::__construct(\sprintf('Metrics already added for message class "%s"', $messageClass)); } } diff --git a/src/Storage/Doctrine/Connection.php b/src/Storage/Doctrine/Connection.php index 65656bf..66e8261 100644 --- a/src/Storage/Doctrine/Connection.php +++ b/src/Storage/Doctrine/Connection.php @@ -110,8 +110,8 @@ public function getStatistics(\DateTimeImmutable $fromDate, \DateTimeImmutable $ $statement = $this->executeQuery( $this->driverConnection->createQueryBuilder() ->select('count(id) as count_messages_on_period, class') - ->addSelect(sprintf('AVG(%s) AS average_waiting_time', $this->SQLDriver->getDateDiffInSecondsExpression('received_at', 'dispatched_at'))) - ->addSelect(sprintf('AVG(%s) AS average_handling_time', $this->SQLDriver->getDateDiffInSecondsExpression('handled_at', 'received_at'))) + ->addSelect(\sprintf('AVG(%s) AS average_waiting_time', $this->SQLDriver->getDateDiffInSecondsExpression('received_at', 'dispatched_at'))) + ->addSelect(\sprintf('AVG(%s) AS average_handling_time', $this->SQLDriver->getDateDiffInSecondsExpression('handled_at', 'received_at'))) ->from($this->tableName) ->where('handled_at >= :from_date') ->andWhere('handled_at <= :to_date') diff --git a/src/Storage/Doctrine/ConnectionFactory.php b/src/Storage/Doctrine/ConnectionFactory.php index 90729cb..0d3a05f 100644 --- a/src/Storage/Doctrine/ConnectionFactory.php +++ b/src/Storage/Doctrine/ConnectionFactory.php @@ -29,12 +29,12 @@ public function __invoke(): Connection $driver = match ($databasePlatform) { 'mysql' => new MySQLDriver(), 'postgresql' => new PostgreSQLDriver(), - default => throw new InvalidConfigurationException(sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) + default => throw new InvalidConfigurationException(\sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) }; return new Connection($driverConnection, $driver, $this->tableName); } catch (\InvalidArgumentException) { - throw new InvalidConfigurationException(sprintf('Doctrine connection with name "%s" does not exist', $this->connectionName)); + throw new InvalidConfigurationException(\sprintf('Doctrine connection with name "%s" does not exist', $this->connectionName)); } } } diff --git a/src/Storage/Doctrine/Driver/MySQLDriver.php b/src/Storage/Doctrine/Driver/MySQLDriver.php index 214125b..fee44ad 100644 --- a/src/Storage/Doctrine/Driver/MySQLDriver.php +++ b/src/Storage/Doctrine/Driver/MySQLDriver.php @@ -11,6 +11,6 @@ final class MySQLDriver implements SQLDriverInterface { public function getDateDiffInSecondsExpression(string $fieldFrom, string $fieldTo): string { - return sprintf('TIME_TO_SEC(TIMEDIFF(%s, %s))', $fieldFrom, $fieldTo); + return \sprintf('TIME_TO_SEC(TIMEDIFF(%s, %s))', $fieldFrom, $fieldTo); } } diff --git a/src/Storage/Doctrine/Driver/PostgreSQLDriver.php b/src/Storage/Doctrine/Driver/PostgreSQLDriver.php index ee3e9f1..c37f4ac 100644 --- a/src/Storage/Doctrine/Driver/PostgreSQLDriver.php +++ b/src/Storage/Doctrine/Driver/PostgreSQLDriver.php @@ -11,6 +11,6 @@ final class PostgreSQLDriver implements SQLDriverInterface { public function getDateDiffInSecondsExpression(string $fieldFrom, string $fieldTo): string { - return sprintf('extract(epoch from (%s - %s))', $fieldFrom, $fieldTo); + return \sprintf('extract(epoch from (%s - %s))', $fieldFrom, $fieldTo); } } diff --git a/src/Storage/Doctrine/StoredMessageProvider.php b/src/Storage/Doctrine/StoredMessageProvider.php index 5bb16a8..83f3b60 100644 --- a/src/Storage/Doctrine/StoredMessageProvider.php +++ b/src/Storage/Doctrine/StoredMessageProvider.php @@ -33,7 +33,7 @@ public function getStoredMessage(Envelope $envelope): ?StoredMessage $storedMessage = $this->doctrineConnection->findMessage($monitorIdStamp->getId()); if (null === $storedMessage) { - $this->logError(sprintf('Message with id "%s" not found', $monitorIdStamp->getId())); + $this->logError(\sprintf('Message with id "%s" not found', $monitorIdStamp->getId())); return null; } diff --git a/src/Twig/TimeDisplayExtension.php b/src/Twig/TimeDisplayExtension.php index cf828d3..78a9e86 100644 --- a/src/Twig/TimeDisplayExtension.php +++ b/src/Twig/TimeDisplayExtension.php @@ -21,21 +21,21 @@ public function formatTime(float $seconds): string if ($seconds < 10) { $seconds = round($seconds, 2); - return sprintf('%s %s', $seconds, $this->pluralize('second', $seconds)); + return \sprintf('%s %s', $seconds, $this->pluralize('second', $seconds)); } if ($seconds < 60) { - return sprintf('%d seconds', round($seconds)); + return \sprintf('%d seconds', round($seconds)); } $minutes = (int) floor($seconds / 60); $intSeconds = (int) $seconds % 60; if (0 === $intSeconds) { - return sprintf('%d %s', $minutes, $this->pluralize('minute', $minutes)); + return \sprintf('%d %s', $minutes, $this->pluralize('minute', $minutes)); } - return sprintf('%d %s %d %s', $minutes, $this->pluralize('minute', $minutes), $intSeconds, $this->pluralize('second', $intSeconds)); + return \sprintf('%d %s %d %s', $minutes, $this->pluralize('minute', $minutes), $intSeconds, $this->pluralize('second', $intSeconds)); } private function pluralize(string $word, float $number): string diff --git a/tests/FunctionalTests/AbstractFunctionalTests.php b/tests/FunctionalTests/AbstractFunctionalTests.php index 130e17b..cdb454c 100644 --- a/tests/FunctionalTests/AbstractFunctionalTests.php +++ b/tests/FunctionalTests/AbstractFunctionalTests.php @@ -44,7 +44,7 @@ protected function setUp(): void try { $connection->connect(); } catch (\Exception $exception) { - self::markTestSkipped(sprintf('Can\'t connect to connection: %s', $exception->getMessage())); + self::markTestSkipped(\sprintf('Can\'t connect to connection: %s', $exception->getMessage())); } $connection->executeQuery('DROP TABLE IF EXISTS messenger_messages'); @@ -54,7 +54,7 @@ protected function setUp(): void $truncateTable = match ($databasePlatform) { 'mysql' => 'TRUNCATE TABLE messenger_monitor', 'postgresql' => 'TRUNCATE TABLE messenger_monitor RESTART IDENTITY', - default => throw new InvalidConfigurationException(sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) + default => throw new InvalidConfigurationException(\sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) }; try { diff --git a/tests/FunctionalTests/RejectFailedMessageControllerTest.php b/tests/FunctionalTests/RejectFailedMessageControllerTest.php index 6bfb408..1299d90 100644 --- a/tests/FunctionalTests/RejectFailedMessageControllerTest.php +++ b/tests/FunctionalTests/RejectFailedMessageControllerTest.php @@ -12,11 +12,11 @@ public function testRejectFailedMessageSuccess(): void $this->handleMessage($envelope, 'queue'); $this->client->followRedirects(); - $crawler = $this->client->request('GET', sprintf('/failed-message/reject/%s', $id = $this->getLastFailedMessageId())); + $crawler = $this->client->request('GET', \sprintf('/failed-message/reject/%s', $id = $this->getLastFailedMessageId())); self::assertResponseIsSuccessful(); $this->assertQueuesCounts(['queue' => 0, 'failed' => 0], $crawler); - $this->assertAlertIsPresent($crawler, '.alert-success', sprintf('Message with id "%s" correctly rejected.', $id)); + $this->assertAlertIsPresent($crawler, '.alert-success', \sprintf('Message with id "%s" correctly rejected.', $id)); } public function testRejectFailedMessageFails(): void diff --git a/tests/FunctionalTests/RetryFailedMessageControllerTest.php b/tests/FunctionalTests/RetryFailedMessageControllerTest.php index 56151e1..dc6c0d5 100644 --- a/tests/FunctionalTests/RetryFailedMessageControllerTest.php +++ b/tests/FunctionalTests/RetryFailedMessageControllerTest.php @@ -12,11 +12,11 @@ public function testRetryFailedMessage(): void $this->handleMessage($envelope, 'queue'); $this->client->followRedirects(); - $crawler = $this->client->request('GET', sprintf('/failed-message/retry/%s', $id = $this->getLastFailedMessageId())); + $crawler = $this->client->request('GET', \sprintf('/failed-message/retry/%s', $id = $this->getLastFailedMessageId())); self::assertResponseIsSuccessful(); $this->assertQueuesCounts(['queue' => 0, 'failed' => 0], $crawler); - $this->assertAlertIsPresent($crawler, '.alert-success', sprintf('Message with id "%s" correctly retried.', $id)); + $this->assertAlertIsPresent($crawler, '.alert-success', \sprintf('Message with id "%s" correctly retried.', $id)); } public function testRetryFailedMessageFails(): void diff --git a/tests/IntegrationTests/AbstractDoctrineIntegrationTests.php b/tests/IntegrationTests/AbstractDoctrineIntegrationTests.php index 786d400..1431709 100644 --- a/tests/IntegrationTests/AbstractDoctrineIntegrationTests.php +++ b/tests/IntegrationTests/AbstractDoctrineIntegrationTests.php @@ -33,7 +33,7 @@ protected function setUp(): void try { $connection->connect(); } catch (\Exception $exception) { - $this->markTestSkipped(sprintf('Can\'t connect to connection: %s', $exception->getMessage())); + $this->markTestSkipped(\sprintf('Can\'t connect to connection: %s', $exception->getMessage())); } $this->doctrineConnection = self::getContainer()->get('test.symfonycasts.messenger_monitor.storage.doctrine_connection'); @@ -43,7 +43,7 @@ protected function setUp(): void $truncateTable = match ($databasePlatform) { 'mysql' => 'TRUNCATE TABLE messenger_monitor', 'postgresql' => 'TRUNCATE TABLE messenger_monitor RESTART IDENTITY', - default => throw new InvalidConfigurationException(sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) + default => throw new InvalidConfigurationException(\sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) }; try { diff --git a/tests/Storage/Doctrine/StoredMessageProviderTest.php b/tests/Storage/Doctrine/StoredMessageProviderTest.php index 946d363..8b75f53 100644 --- a/tests/Storage/Doctrine/StoredMessageProviderTest.php +++ b/tests/Storage/Doctrine/StoredMessageProviderTest.php @@ -38,7 +38,7 @@ public function testGetStoredMessageLogsAnErrorWhenStoredMessageNotFound(): void $envelope = new Envelope(new TestableMessage(), [$stamp = new MonitorIdStamp()]); $doctrineConnection->expects($this->once())->method('findMessage')->with($stamp->getId())->willReturn(null); - $logger->expects($this->once())->method('error')->with(sprintf('Message with id "%s" not found', $stamp->getId())); + $logger->expects($this->once())->method('error')->with(\sprintf('Message with id "%s" not found', $stamp->getId())); $this->assertNull($storedMessageProvider->getStoredMessage($envelope)); } From 63d220d076e40bec83f7a1935b67bfd2557275c1 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Tue, 30 Jul 2024 12:05:44 +0200 Subject: [PATCH 13/20] Drop enable_authenticator_manager=true that by default since 5.4 --- tests/TestKernel.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/TestKernel.php b/tests/TestKernel.php index 5c390a4..d6ebdfd 100644 --- a/tests/TestKernel.php +++ b/tests/TestKernel.php @@ -119,7 +119,6 @@ protected function configureContainer(ContainerBuilder $container) $container->loadFromExtension( 'security', [ - 'enable_authenticator_manager' => true, 'providers' => [ 'in_memory' => [ 'memory' => [ From 29ede80d6b885f77baecac36dde0bcb53e55b12f Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Tue, 30 Jul 2024 12:28:24 +0200 Subject: [PATCH 14/20] Return back enable_authenticator_manager for Sf < 6.0 --- tests/TestKernel.php | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/tests/TestKernel.php b/tests/TestKernel.php index d6ebdfd..1e3b0fc 100644 --- a/tests/TestKernel.php +++ b/tests/TestKernel.php @@ -116,27 +116,32 @@ protected function configureContainer(ContainerBuilder $container) ] ); - $container->loadFromExtension( - 'security', - [ - 'providers' => [ - 'in_memory' => [ - 'memory' => [ - 'users' => [ - 'admin' => ['password' => 'password', 'roles' => ['ROLE_MESSENGER_ADMIN']], - 'user' => ['password' => 'password', 'roles' => ['ROLE_USER']], - ], + $securityConfig = [ + 'providers' => [ + 'in_memory' => [ + 'memory' => [ + 'users' => [ + 'admin' => ['password' => 'password', 'roles' => ['ROLE_MESSENGER_ADMIN']], + 'user' => ['password' => 'password', 'roles' => ['ROLE_USER']], ], ], ], - 'password_hashers' => [InMemoryUser::class => 'plaintext'], - 'firewalls' => [ - 'main' => [ - 'provider' => 'in_memory', - 'http_basic' => true, - ], + ], + 'password_hashers' => [InMemoryUser::class => 'plaintext'], + 'firewalls' => [ + 'main' => [ + 'provider' => 'in_memory', + 'http_basic' => true, ], - ] + ], + ]; + // Legacy, since 6.0 enable_authenticator_manager is true by default + if (Kernel::VERSION_ID < 60000) { + $securityConfig['enable_authenticator_manager'] = true; + } + $container->loadFromExtension( + 'security', + $securityConfig, ); $container->loadFromExtension('symfonycasts_messenger_monitor', $this->bundleOptions); From c4102314719aa2b728aba657856e71a1a82e47a8 Mon Sep 17 00:00:00 2001 From: Jesse Rushlow <40327885+jrushlow@users.noreply.github.com> Date: Sat, 31 Aug 2024 08:27:18 -0400 Subject: [PATCH 15/20] minor #63 [ci] php-cs-fixer it up --- src/Controller/DashboardController.php | 2 +- src/Controller/RejectFailedMessageController.php | 2 +- src/EventListener/SendEventOnRetriedMessageListener.php | 2 +- src/FailedMessage/FailedMessageDetails.php | 2 +- src/FailedMessage/FailedMessageRetryer.php | 2 +- src/Statistics/MetricsPerMessageType.php | 2 +- src/Storage/Doctrine/ConnectionFactory.php | 2 +- tests/FunctionalTests/AbstractFunctionalTests.php | 2 +- tests/IntegrationTests/AbstractDoctrineIntegrationTests.php | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php index d483567..bbc00b8 100644 --- a/src/Controller/DashboardController.php +++ b/src/Controller/DashboardController.php @@ -25,7 +25,7 @@ public function __construct( private Environment $twig, private ReceiverLocator $receiverLocator, private FailedMessageRepository $failedMessageRepository, - private StatisticsProcessorInterface $statisticsProcessor + private StatisticsProcessorInterface $statisticsProcessor, ) { } diff --git a/src/Controller/RejectFailedMessageController.php b/src/Controller/RejectFailedMessageController.php index 78372be..3981773 100644 --- a/src/Controller/RejectFailedMessageController.php +++ b/src/Controller/RejectFailedMessageController.php @@ -18,7 +18,7 @@ final class RejectFailedMessageController public function __construct( private FailedMessageRejecter $failedMessageRejecter, private RequestStack $requestStack, - private UrlGeneratorInterface $urlGenerator + private UrlGeneratorInterface $urlGenerator, ) { } diff --git a/src/EventListener/SendEventOnRetriedMessageListener.php b/src/EventListener/SendEventOnRetriedMessageListener.php index 210dfeb..3f62fb6 100644 --- a/src/EventListener/SendEventOnRetriedMessageListener.php +++ b/src/EventListener/SendEventOnRetriedMessageListener.php @@ -24,7 +24,7 @@ final class SendEventOnRetriedMessageListener implements EventSubscriberInterfac public function __construct( private SendFailedMessageForRetryListener $decorated, private EventDispatcherInterface $eventDispatcher, - private ?LoggerInterface $logger = null + private ?LoggerInterface $logger = null, ) { } diff --git a/src/FailedMessage/FailedMessageDetails.php b/src/FailedMessage/FailedMessageDetails.php index a48be46..24419ce 100644 --- a/src/FailedMessage/FailedMessageDetails.php +++ b/src/FailedMessage/FailedMessageDetails.php @@ -13,7 +13,7 @@ public function __construct( private mixed $id, private string $class, private string $failedAt, - private ?string $error + private ?string $error, ) { } diff --git a/src/FailedMessage/FailedMessageRetryer.php b/src/FailedMessage/FailedMessageRetryer.php index 91b44aa..8ed1c49 100644 --- a/src/FailedMessage/FailedMessageRetryer.php +++ b/src/FailedMessage/FailedMessageRetryer.php @@ -26,7 +26,7 @@ public function __construct( private FailureReceiverName $failureReceiverName, private MessageBusInterface $messageBus, private EventDispatcherInterface $eventDispatcher, - private LoggerInterface $logger + private LoggerInterface $logger, ) { } diff --git a/src/Statistics/MetricsPerMessageType.php b/src/Statistics/MetricsPerMessageType.php index 7d92dfb..df36177 100644 --- a/src/Statistics/MetricsPerMessageType.php +++ b/src/Statistics/MetricsPerMessageType.php @@ -15,7 +15,7 @@ public function __construct( private string $class, private int $messagesCountOnPeriod, private float $averageWaitingTime, - private float $averageHandlingTime + private float $averageHandlingTime, ) { } diff --git a/src/Storage/Doctrine/ConnectionFactory.php b/src/Storage/Doctrine/ConnectionFactory.php index 0d3a05f..3f09923 100644 --- a/src/Storage/Doctrine/ConnectionFactory.php +++ b/src/Storage/Doctrine/ConnectionFactory.php @@ -29,7 +29,7 @@ public function __invoke(): Connection $driver = match ($databasePlatform) { 'mysql' => new MySQLDriver(), 'postgresql' => new PostgreSQLDriver(), - default => throw new InvalidConfigurationException(\sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) + default => throw new InvalidConfigurationException(\sprintf('Doctrine platform "%s" is not supported', $databasePlatform)), }; return new Connection($driverConnection, $driver, $this->tableName); diff --git a/tests/FunctionalTests/AbstractFunctionalTests.php b/tests/FunctionalTests/AbstractFunctionalTests.php index cdb454c..ceddded 100644 --- a/tests/FunctionalTests/AbstractFunctionalTests.php +++ b/tests/FunctionalTests/AbstractFunctionalTests.php @@ -54,7 +54,7 @@ protected function setUp(): void $truncateTable = match ($databasePlatform) { 'mysql' => 'TRUNCATE TABLE messenger_monitor', 'postgresql' => 'TRUNCATE TABLE messenger_monitor RESTART IDENTITY', - default => throw new InvalidConfigurationException(\sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) + default => throw new InvalidConfigurationException(\sprintf('Doctrine platform "%s" is not supported', $databasePlatform)), }; try { diff --git a/tests/IntegrationTests/AbstractDoctrineIntegrationTests.php b/tests/IntegrationTests/AbstractDoctrineIntegrationTests.php index 1431709..e68ec97 100644 --- a/tests/IntegrationTests/AbstractDoctrineIntegrationTests.php +++ b/tests/IntegrationTests/AbstractDoctrineIntegrationTests.php @@ -43,7 +43,7 @@ protected function setUp(): void $truncateTable = match ($databasePlatform) { 'mysql' => 'TRUNCATE TABLE messenger_monitor', 'postgresql' => 'TRUNCATE TABLE messenger_monitor RESTART IDENTITY', - default => throw new InvalidConfigurationException(\sprintf('Doctrine platform "%s" is not supported', $databasePlatform)) + default => throw new InvalidConfigurationException(\sprintf('Doctrine platform "%s" is not supported', $databasePlatform)), }; try { From abf875f7fd95bd012b79c353e6f3c35917b9c2ff Mon Sep 17 00:00:00 2001 From: Victor Bocharsky Date: Mon, 7 Oct 2024 23:43:35 +0200 Subject: [PATCH 16/20] Add CI status badge This should help with noticing failed CI builds --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a3eeb81..8aa2c21 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ Messenger Monitor ================= +[![CI](https://github.com/SymfonyCasts/messenger-monitor-bundle/actions/workflows/ci.yaml/badge.svg)](https://github.com/SymfonyCasts/messenger-monitor-bundle/actions/workflows/ci.yaml) + > **Note** > **THIS BUNDLE IS EXPERIMENTAL & UNSTABLE** and may not work and probably isn't ready for production. > It's also super rough and currently is in a development phase. From 2be0ec4ac901a613056a346e166a8ed9a43bc6f4 Mon Sep 17 00:00:00 2001 From: Rhodri Pugh Date: Wed, 11 Jan 2023 17:04:33 +0000 Subject: [PATCH 17/20] use dashboard route so link is correct when template is used in sub-folders --- src/Resources/views/template/base.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/views/template/base.html.twig b/src/Resources/views/template/base.html.twig index 4034314..74869f5 100644 --- a/src/Resources/views/template/base.html.twig +++ b/src/Resources/views/template/base.html.twig @@ -19,7 +19,7 @@ Messenger Monitor From 686caa90aefeb17a6af3ab8f70a1c00c12f66ad2 Mon Sep 17 00:00:00 2001 From: Rhodri Pugh Date: Wed, 11 Jan 2023 17:20:33 +0000 Subject: [PATCH 18/20] allow customizing page header suffix --- src/Resources/views/template/base.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/views/template/base.html.twig b/src/Resources/views/template/base.html.twig index 74869f5..cea5424 100644 --- a/src/Resources/views/template/base.html.twig +++ b/src/Resources/views/template/base.html.twig @@ -2,7 +2,7 @@ {% block messenger_monitor_head %} - Messenger monitor dashboard + Messenger monitor dashboard{% block title %}{% endblock %} Date: Thu, 12 Jan 2023 09:47:42 +0000 Subject: [PATCH 19/20] allow customizing class of card --- src/Resources/views/template/card.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/views/template/card.html.twig b/src/Resources/views/template/card.html.twig index bd0c760..8e02907 100644 --- a/src/Resources/views/template/card.html.twig +++ b/src/Resources/views/template/card.html.twig @@ -1,4 +1,4 @@ -
+
{% block card_title %}{% endblock %}
From d8489d35d8036ea9b602da01e113de74951b869c Mon Sep 17 00:00:00 2001 From: Rhodri Pugh Date: Wed, 11 Jan 2023 17:04:09 +0000 Subject: [PATCH 20/20] add route for displaying information about failed message --- .../ShowFailedMessageController.php | 42 ++++++++++++ src/FailedMessage/FailedMessage.php | 64 +++++++++++++++++++ src/Resources/config/routing.xml | 4 ++ src/Resources/config/services.xml | 5 ++ .../blocks/_failed_message_details.html.twig | 13 ++++ .../_failed_message_stack_trace.html.twig | 9 +++ .../views/blocks/_failure_transport.html.twig | 5 +- src/Resources/views/failed_message.html.twig | 22 +++++++ tests/FailedMessage/FailedMessageTest.php | 41 ++++++++++++ .../ShowFailedMessageControllerTest.php | 35 ++++++++++ 10 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 src/Controller/ShowFailedMessageController.php create mode 100644 src/FailedMessage/FailedMessage.php create mode 100644 src/Resources/views/blocks/_failed_message_details.html.twig create mode 100644 src/Resources/views/blocks/_failed_message_stack_trace.html.twig create mode 100644 src/Resources/views/failed_message.html.twig create mode 100644 tests/FailedMessage/FailedMessageTest.php create mode 100644 tests/FunctionalTests/ShowFailedMessageControllerTest.php diff --git a/src/Controller/ShowFailedMessageController.php b/src/Controller/ShowFailedMessageController.php new file mode 100644 index 0000000..89e41f9 --- /dev/null +++ b/src/Controller/ShowFailedMessageController.php @@ -0,0 +1,42 @@ +failureReceiverProvider->getFailureReceiver(); + $envelope = $failureReceiver->find($id); + + if (null === $envelope) { + throw new NotFoundHttpException(); + } + + return new Response( + $this->twig->render( + '@SymfonyCastsMessengerMonitor/failed_message.html.twig', + [ + 'failed_message' => new FailedMessage($envelope), + ] + ) + ); + } +} diff --git a/src/FailedMessage/FailedMessage.php b/src/FailedMessage/FailedMessage.php new file mode 100644 index 0000000..51e00ab --- /dev/null +++ b/src/FailedMessage/FailedMessage.php @@ -0,0 +1,64 @@ +getStamp(TransportMessageIdStamp::class); + } + + public function getErrorDetails(): StampInterface + { + return $this->getStamp(ErrorDetailsStamp::class); + } + + public function getMessageClass(): string + { + return $this->getMessage()::class; + } + + public function getMessageDetails(): array + { + $details = []; + + foreach ($this->getMessage() as $key => $value) { + $details[$key] = $value; + } + + return $details; + } + + private function getMessage(): object + { + return $this->envelope->getMessage(); + } + + /** @param class-string $stampClass */ + private function getStamp(string $stampClass): StampInterface + { + $stamp = $this->envelope->last($stampClass); + + if (null === $stamp) { + throw new \Exception('Could not find expected stamp: '.$stampClass); + } + + return $stamp; + } +} diff --git a/src/Resources/config/routing.xml b/src/Resources/config/routing.xml index 76f2dc2..90f0048 100644 --- a/src/Resources/config/routing.xml +++ b/src/Resources/config/routing.xml @@ -8,6 +8,10 @@ symfonycasts.messenger_monitor.controller.dashboard + + symfonycasts.messenger_monitor.controller.show_failed_message + + symfonycasts.messenger_monitor.controller.retry_failed_message diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml index 15316ff..b26baa0 100644 --- a/src/Resources/config/services.xml +++ b/src/Resources/config/services.xml @@ -13,6 +13,11 @@ + + + + + diff --git a/src/Resources/views/blocks/_failed_message_details.html.twig b/src/Resources/views/blocks/_failed_message_details.html.twig new file mode 100644 index 0000000..97cf523 --- /dev/null +++ b/src/Resources/views/blocks/_failed_message_details.html.twig @@ -0,0 +1,13 @@ +{% extends "@SymfonyCastsMessengerMonitor/template/card.html.twig" %} + +{% block card_class %}failed-message-details-card{% endblock %} + +{% block card_title %}{{ failed_message.messageClass }}{% endblock %} + +{% block card_body %} +
    + {% for key,value in failed_message.messageDetails %} +
  • {{ key }}: {{ value }}
  • + {% endfor %} +
+{% endblock %} diff --git a/src/Resources/views/blocks/_failed_message_stack_trace.html.twig b/src/Resources/views/blocks/_failed_message_stack_trace.html.twig new file mode 100644 index 0000000..a49b033 --- /dev/null +++ b/src/Resources/views/blocks/_failed_message_stack_trace.html.twig @@ -0,0 +1,9 @@ +{% extends "@SymfonyCastsMessengerMonitor/template/card.html.twig" %} + +{% block card_class %}failed-message-stack-trace-card{% endblock %} + +{% block card_title %}Stack trace{% endblock %} + +{% block card_body %} +
{{ failed_message.errorDetails.flattenException.traceAsString }}
+{% endblock %} diff --git a/src/Resources/views/blocks/_failure_transport.html.twig b/src/Resources/views/blocks/_failure_transport.html.twig index 6cdcb05..0f6ef24 100644 --- a/src/Resources/views/blocks/_failure_transport.html.twig +++ b/src/Resources/views/blocks/_failure_transport.html.twig @@ -20,7 +20,10 @@ {% for failedMessage in failedMessages %} - {{ failedMessage.id }} + + {{ failedMessage.id }} + + {{ failedMessage.class }} {{ failedMessage.failedAt }} {{ failedMessage.error }} diff --git a/src/Resources/views/failed_message.html.twig b/src/Resources/views/failed_message.html.twig new file mode 100644 index 0000000..e31e6cf --- /dev/null +++ b/src/Resources/views/failed_message.html.twig @@ -0,0 +1,22 @@ +{% extends "@SymfonyCastsMessengerMonitor/template/base.html.twig" %} + +{% block title %} - Failed Message - {{ failed_message.transportMessageId.id }}{% endblock %} + +{% block messenger_monitor_main %} + {% set errorDetails = failed_message.errorDetails %} + +

{{ errorDetails.exceptionCode }} {{ errorDetails.exceptionClass }}

+

{{ errorDetails.exceptionMessage }}

+ +
+
+ {% include "@SymfonyCastsMessengerMonitor/blocks/_failed_message_details.html.twig" with {failed_message} only %} +
+
+ +
+
+ {% include "@SymfonyCastsMessengerMonitor/blocks/_failed_message_stack_trace.html.twig" with {failed_message} only %} +
+
+{% endblock %} diff --git a/tests/FailedMessage/FailedMessageTest.php b/tests/FailedMessage/FailedMessageTest.php new file mode 100644 index 0000000..5b68712 --- /dev/null +++ b/tests/FailedMessage/FailedMessageTest.php @@ -0,0 +1,41 @@ +foo = 'bar'; + + $errorDetails = new ErrorDetailsStamp( + \Exception::class, + 123, + 'The Message', + new FlattenException(new \Exception()), + ); + + $transportMessage = new TransportMessageIdStamp('id'); + + $envelope = (new Envelope($object)) + ->with($errorDetails) + ->with($transportMessage); + + $failedMessage = new FailedMessage($envelope); + + $this->assertSame('stdClass', $failedMessage->getMessageClass()); + $this->assertSame(['foo' => 'bar'], $failedMessage->getMessageDetails()); + $this->assertSame($errorDetails, $failedMessage->getErrorDetails()); + $this->assertSame($transportMessage, $failedMessage->getTransportMessageId()); + } +} diff --git a/tests/FunctionalTests/ShowFailedMessageControllerTest.php b/tests/FunctionalTests/ShowFailedMessageControllerTest.php new file mode 100644 index 0000000..9379a36 --- /dev/null +++ b/tests/FunctionalTests/ShowFailedMessageControllerTest.php @@ -0,0 +1,35 @@ +dispatchMessage(true); + $this->handleMessage($envelope, 'queue'); + + $crawler = $this->client->request('GET', sprintf('/failed-message/%s', $id = $this->getLastFailedMessageId())); + self::assertResponseIsSuccessful(); + + $this->assertSame('0 Exception', $crawler->filter('h1')->text()); + $this->assertSame('oops!', $crawler->filter('p.lead')->text()); + + $this->assertStringContainsString('SymfonyCasts\MessengerMonitorBundle\Tests\TestableMessage', $crawler->filter('.failed-message-details-card .card-header')->text()); + $this->assertStringContainsString('willFail:', $crawler->filter('.failed-message-details-card .card-body')->text()); + + $this->assertStringContainsString('Stack trace', $crawler->filter('.failed-message-stack-trace-card .card-header')->text()); + $this->assertStringContainsString('HandleMessageMiddleware', $crawler->filter('.failed-message-stack-trace-card .card-body')->text()); + } + + public function testShowFailedMessageNotFound(): void + { + $this->client->request('GET', '/failed-message/123456'); + + self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND); + } +}