-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
376 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the zenstruck/messenger-monitor-bundle package. | ||
* | ||
* (c) Kevin Bond <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Messenger\Monitor\Tests\Feature; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Zenstruck\Messenger\Monitor\Tests\Fixture\TestService; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class BundleServicesTest extends KernelTestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function autowires_services(): void | ||
{ | ||
/** @var TestService $service */ | ||
$service = self::getContainer()->get(TestService::class); | ||
|
||
$this->assertCount(1, $service->transports); | ||
$this->assertCount(0, $service->workers); | ||
$this->assertCount(0, $service->schedules); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the zenstruck/messenger-monitor-bundle package. | ||
* | ||
* (c) Kevin Bond <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Messenger\Monitor\Tests\Feature; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\Messenger\Exception\HandlerFailedException; | ||
use Symfony\Component\Messenger\Exception\NoHandlerForMessageException; | ||
use Zenstruck\Foundry\Test\Factories; | ||
use Zenstruck\Foundry\Test\ResetDatabase; | ||
use Zenstruck\Messenger\Monitor\Tests\Fixture\Factory\ProcessedMessageFactory; | ||
use Zenstruck\Messenger\Monitor\Tests\Fixture\Message\MessageA; | ||
use Zenstruck\Messenger\Monitor\Tests\Fixture\Message\MessageAHandler; | ||
use Zenstruck\Messenger\Monitor\Tests\Fixture\Message\MessageB; | ||
use Zenstruck\Messenger\Monitor\Tests\Fixture\Message\MessageC; | ||
use Zenstruck\Messenger\Monitor\Tests\Fixture\Message\MessageCHandler1; | ||
use Zenstruck\Messenger\Monitor\Tests\Fixture\Message\MessageCHandler2; | ||
use Zenstruck\Messenger\Test\InteractsWithMessenger; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class HistoryTest extends KernelTestCase | ||
{ | ||
use Factories, InteractsWithMessenger, ResetDatabase; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function flow_for_single_handler(): void | ||
{ | ||
ProcessedMessageFactory::assert()->empty(); | ||
|
||
$this->bus()->dispatch(new MessageA(return: 'foo')); | ||
|
||
$this->transport()->processOrFail(1); | ||
|
||
ProcessedMessageFactory::assert()->count(1); | ||
|
||
$message = ProcessedMessageFactory::first(); | ||
$this->assertSame(MessageA::class, $message->type()->class()); | ||
$this->assertSame('async', $message->transport()); | ||
$this->assertFalse($message->isFailure()); | ||
$this->assertCount(1, $message->results()); | ||
$this->assertSame(['data' => 'foo'], $message->results()->all()[0]->data()); | ||
$this->assertFalse($message->results()->all()[0]->isFailure()); | ||
$this->assertSame(MessageAHandler::class, $message->results()->all()[0]->handler()?->class()); | ||
$this->assertNull($message->results()->all()[0]->handler()?->description()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function flow_for_single_handler_failure(): void | ||
{ | ||
ProcessedMessageFactory::assert()->empty(); | ||
|
||
$this->bus()->dispatch(new MessageA(return: 'foo', throw: true)); | ||
|
||
$this->transport()->processOrFail(1); | ||
|
||
ProcessedMessageFactory::assert()->count(1); | ||
|
||
$message = ProcessedMessageFactory::first(); | ||
$this->assertSame(MessageA::class, $message->type()->class()); | ||
$this->assertTrue($message->isFailure()); | ||
$this->assertSame(HandlerFailedException::class, $message->failure()?->class()); | ||
$this->assertSame(\sprintf('Handling "%s" failed: error', MessageA::class), $message->failure()->description()); | ||
$this->assertCount(1, $message->results()); | ||
$this->assertTrue($message->results()->all()[0]->isFailure()); | ||
$this->assertSame(\RuntimeException::class, $message->results()->all()[0]->failure()?->class()); | ||
$this->assertSame('error', $message->results()->all()[0]->failure()->description()); | ||
$this->assertSame(MessageAHandler::class, $message->results()->all()[0]->handler()?->class()); | ||
$this->assertSame(['stack_trace'], \array_keys($message->results()->all()[0]->data())); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function flow_for_missing_handler(): void | ||
{ | ||
ProcessedMessageFactory::assert()->empty(); | ||
|
||
$this->bus()->dispatch(new MessageB()); | ||
|
||
$this->transport()->processOrFail(1); | ||
|
||
ProcessedMessageFactory::assert()->count(1); | ||
|
||
$message = ProcessedMessageFactory::first(); | ||
|
||
$this->assertTrue($message->isFailure()); | ||
$this->assertSame(NoHandlerForMessageException::class, $message->failure()?->class()); | ||
$this->assertSame(\sprintf('No handler for message "%s".', MessageB::class), $message->failure()->description()); | ||
$this->assertEmpty($message->results()->all()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function flow_for_multiple_handlers(): void | ||
{ | ||
ProcessedMessageFactory::assert()->empty(); | ||
|
||
$this->bus()->dispatch(new MessageC(return1: 'foo', return2: 'bar')); | ||
|
||
$this->transport()->processOrFail(1); | ||
|
||
ProcessedMessageFactory::assert()->count(1); | ||
|
||
$message = ProcessedMessageFactory::first(); | ||
$this->assertSame(MessageC::class, $message->type()->class()); | ||
$this->assertSame('async', $message->transport()); | ||
$this->assertFalse($message->isFailure()); | ||
$this->assertCount(2, $message->results()); | ||
|
||
$this->assertSame(['data' => 'foo'], $message->results()->all()[0]->data()); | ||
$this->assertFalse($message->results()->all()[0]->isFailure()); | ||
$this->assertSame(MessageCHandler1::class, $message->results()->all()[0]->handler()?->class()); | ||
$this->assertNull($message->results()->all()[0]->handler()?->description()); | ||
|
||
$this->assertSame(['data' => 'bar'], $message->results()->all()[1]->data()); | ||
$this->assertFalse($message->results()->all()[1]->isFailure()); | ||
$this->assertSame(MessageCHandler2::class, $message->results()->all()[1]->handler()?->class()); | ||
$this->assertSame('handle', $message->results()->all()[1]->handler()?->description()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function flow_for_multiple_handlers_one_fails(): void | ||
{ | ||
$this->bus()->dispatch(new MessageC(return1: 'foo', return2: 'bar', throw: true)); | ||
|
||
$this->transport()->processOrFail(1); | ||
|
||
ProcessedMessageFactory::assert()->count(1); | ||
|
||
$message = ProcessedMessageFactory::first(); | ||
$this->assertSame(MessageC::class, $message->type()->class()); | ||
$this->assertSame('async', $message->transport()); | ||
$this->assertTrue($message->isFailure()); | ||
|
||
$this->assertSame(HandlerFailedException::class, $message->failure()?->class()); | ||
$this->assertSame(\sprintf('Handling "%s" failed: error', MessageC::class), $message->failure()->description()); | ||
$this->assertCount(2, $message->results()); | ||
|
||
$this->assertSame(['data' => 'bar'], $message->results()->all()[0]->data()); | ||
$this->assertFalse($message->results()->all()[0]->isFailure()); | ||
$this->assertSame(MessageCHandler2::class, $message->results()->all()[0]->handler()?->class()); | ||
$this->assertSame('handle', $message->results()->all()[0]->handler()?->description()); | ||
|
||
$this->assertTrue($message->results()->all()[1]->isFailure()); | ||
$this->assertSame(MessageCHandler1::class, $message->results()->all()[1]->handler()?->class()); | ||
$this->assertNull($message->results()->all()[1]->handler()?->description()); | ||
$this->assertSame(\RuntimeException::class, $message->results()->all()[1]->failure()?->class()); | ||
$this->assertSame('error', $message->results()->all()[1]->failure()->description()); | ||
$this->assertSame(['stack_trace'], \array_keys($message->results()->all()[1]->data())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,47 +9,19 @@ | |
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Messenger\Monitor\Tests\Integration; | ||
namespace Zenstruck\Messenger\Monitor\Tests\Feature; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\Clock\Test\ClockSensitiveTrait; | ||
use Symfony\Component\Serializer\Serializer; | ||
use Zenstruck\Console\Test\InteractsWithConsole; | ||
use Zenstruck\Foundry\Test\ResetDatabase; | ||
use Zenstruck\Messenger\Monitor\Stamp\MonitorStamp; | ||
use Zenstruck\Messenger\Monitor\Tests\Fixture\TestService; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class ZenstruckMessengerMonitorBundleTest extends KernelTestCase | ||
final class SerializerTest extends KernelTestCase | ||
{ | ||
use ClockSensitiveTrait, InteractsWithConsole, ResetDatabase; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function autowires_services(): void | ||
{ | ||
/** @var TestService $service */ | ||
$service = self::getContainer()->get(TestService::class); | ||
|
||
$this->assertCount(1, $service->transports); | ||
$this->assertCount(0, $service->workers); | ||
$this->assertCount(0, $service->schedules); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function run_messenger_monitor_command(): void | ||
{ | ||
$this->executeConsoleCommand('messenger:monitor') | ||
->assertSuccessful() | ||
->assertOutputContains('[!] No workers running.') | ||
->assertOutputContains('async n/a') | ||
; | ||
} | ||
use ClockSensitiveTrait; | ||
|
||
/** | ||
* @test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the zenstruck/messenger-monitor-bundle package. | ||
* | ||
* (c) Kevin Bond <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Messenger\Monitor\Tests\Fixture\Message; | ||
|
||
use Symfony\Component\Messenger\Attribute\AsMessageHandler; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
#[AsMessageHandler] | ||
final class MessageAHandler | ||
{ | ||
public function __invoke(MessageA $message): mixed | ||
{ | ||
if ($message->throw) { | ||
throw new \RuntimeException('error'); | ||
} | ||
|
||
return $message->return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the zenstruck/messenger-monitor-bundle package. | ||
* | ||
* (c) Kevin Bond <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Messenger\Monitor\Tests\Fixture\Message; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class MessageC | ||
{ | ||
public function __construct( | ||
public readonly mixed $return1 = null, | ||
public readonly mixed $return2 = null, | ||
public readonly bool $throw = false, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the zenstruck/messenger-monitor-bundle package. | ||
* | ||
* (c) Kevin Bond <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Messenger\Monitor\Tests\Fixture\Message; | ||
|
||
use Symfony\Component\Messenger\Attribute\AsMessageHandler; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
#[AsMessageHandler] | ||
final class MessageCHandler1 | ||
{ | ||
public function __invoke(MessageC $message): mixed | ||
{ | ||
if ($message->throw) { | ||
throw new \RuntimeException('error'); | ||
} | ||
|
||
return $message->return1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the zenstruck/messenger-monitor-bundle package. | ||
* | ||
* (c) Kevin Bond <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Zenstruck\Messenger\Monitor\Tests\Fixture\Message; | ||
|
||
use Symfony\Component\Messenger\Attribute\AsMessageHandler; | ||
|
||
/** | ||
* @author Kevin Bond <[email protected]> | ||
*/ | ||
final class MessageCHandler2 | ||
{ | ||
#[AsMessageHandler] | ||
public function handle(MessageC $message): mixed | ||
{ | ||
return $message->return2; | ||
} | ||
} |
Oops, something went wrong.