-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from krakphp/must-match-all-receivers
Must Match All Receivers
- Loading branch information
Showing
7 changed files
with
133 additions
and
2 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
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,37 @@ | ||
<?php | ||
|
||
namespace Krak\SymfonyMessengerAutoScale\Tests\Feature\Bundle; | ||
|
||
use Krak\SymfonyMessengerAutoScale\MessengerAutoScaleBundle; | ||
use Krak\SymfonyMessengerAutoScale\Tests\Feature\Fixtures\TestFixtureBundle; | ||
use Krak\SymfonyMessengerRedis\MessengerRedisBundle; | ||
use Nyholm\BundleTest\CompilerPass\PublicServicePass; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
trait InitsKernel | ||
{ | ||
protected function getBundleClass() { | ||
return MessengerAutoScaleBundle::class; | ||
} | ||
|
||
private function registerPublicServiceCompilerPass() { | ||
$this->addCompilerPass(new PublicServicePass('/(Krak.*|krak\..*|messenger.default_serializer|message_bus)/')); | ||
} | ||
|
||
private function given_the_kernel_is_booted_with_config_resources(array $configResources) { | ||
$kernel = $this->createKernel(); | ||
$kernel->addBundle(TestFixtureBundle::class); | ||
$kernel->addBundle(MessengerRedisBundle::class); | ||
foreach ($configResources as $config) { | ||
$kernel->addConfigFile($config); | ||
} | ||
$this->bootKernel(); | ||
} | ||
|
||
private function given_the_kernel_is_booted_with_messenger_and_auto_scale_config() { | ||
$this->given_the_kernel_is_booted_with_config_resources([ | ||
__DIR__ . '/../Fixtures/messenger-config.yaml', | ||
__DIR__ . '/../Fixtures/auto-scale-config.yaml', | ||
]); | ||
} | ||
} |
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,66 @@ | ||
<?php | ||
|
||
namespace Krak\SymfonyMessengerAutoScale\Tests\Feature\Bundle; | ||
|
||
use Nyholm\BundleTest\BaseBundleTestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
final class MustMatchAllReceiversTest extends BaseBundleTestCase | ||
{ | ||
use InitsKernel; | ||
|
||
/** @var \Throwable|null $e */ | ||
private $exception; | ||
private $configs; | ||
|
||
|
||
protected function setUp() { | ||
parent::setUp(); | ||
$this->registerPublicServiceCompilerPass(); | ||
} | ||
|
||
/** @test */ | ||
public function throws_exception_if_not_all_receivers_are_matched() { | ||
$this->given_the_config_where_not_all_receivers_are_set_is_available(); | ||
$this->when_the_kernel_is_booted(); | ||
$this->then_the_not_matched_logic_exception_is_thrown(); | ||
} | ||
|
||
/** @test */ | ||
public function can_disable_must_match_all_receivers_flag() { | ||
$this->given_the_config_where_not_all_receivers_are_set_flag_is_disabled(); | ||
$this->when_the_kernel_is_booted(); | ||
$this->then_no_exception_is_thrown(); | ||
} | ||
|
||
private function given_the_config_where_not_all_receivers_are_set_is_available() { | ||
$this->configs = [ | ||
__DIR__ . '/../Fixtures/messenger-config.yaml', | ||
__DIR__ . '/../Fixtures/auto-scale-config-with-missing-receivers.yaml', | ||
]; | ||
} | ||
|
||
private function given_the_config_where_not_all_receivers_are_set_flag_is_disabled() { | ||
$this->configs = [ | ||
__DIR__ . '/../Fixtures/messenger-config.yaml', | ||
__DIR__ . '/../Fixtures/auto-scale-config-with-missing-receivers-disabled.yaml' | ||
]; | ||
} | ||
|
||
private function when_the_kernel_is_booted() { | ||
try { | ||
$this->given_the_kernel_is_booted_with_config_resources($this->configs); | ||
} catch (\Throwable $e) { | ||
$this->exception = $e; | ||
} | ||
} | ||
|
||
private function then_the_not_matched_logic_exception_is_thrown() { | ||
$this->assertInstanceOf(\LogicException::class, $this->exception); | ||
$this->assertEquals('Some receivers were not matched by the pool config: catalog', $this->exception->getMessage()); | ||
} | ||
|
||
private function then_no_exception_is_thrown() { | ||
$this->assertNull($this->exception); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/Feature/Fixtures/auto-scale-config-with-missing-receivers-disabled.yaml
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,5 @@ | ||
messenger_auto_scale: | ||
must_match_all_receivers: false | ||
pools: | ||
sales: | ||
receivers: "sales*" |
4 changes: 4 additions & 0 deletions
4
tests/Feature/Fixtures/auto-scale-config-with-missing-receivers.yaml
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,4 @@ | ||
messenger_auto_scale: | ||
pools: | ||
sales: | ||
receivers: "sales*" |