Skip to content

Commit

Permalink
add config option to enable test module in Symfony and Laravel
Browse files Browse the repository at this point in the history
  • Loading branch information
jlabedo committed Sep 4, 2023
1 parent 702f026 commit c104380
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 4 deletions.
10 changes: 10 additions & 0 deletions packages/Laravel/config/ecotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,14 @@
|
*/
'skippedModulePackageNames' => [],

/*
|--------------------------------------------------------------------------
| test
|--------------------------------------------------------------------------
|
| Whether ecotone test module should be loaded
|
*/
'test' => false,
];
7 changes: 6 additions & 1 deletion packages/Laravel/src/EcotoneProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,18 @@ public function register()

$errorChannel = Config::get('ecotone.defaultErrorChannel');

$skippedModules = Config::get('ecotone.skippedModulePackageNames');
if (! Config::get('ecotone.test')) {
$skippedModules[] = ModulePackageList::TEST_PACKAGE;
}

/** @TODO Ecotone 2.0 use ServiceContext to configure Laravel */
$applicationConfiguration = ServiceConfiguration::createWithDefaults()
->withEnvironment($environment)
->withLoadCatalog(Config::get('ecotone.loadAppNamespaces') ? 'app' : '')
->withFailFast(false)
->withNamespaces(Config::get('ecotone.namespaces'))
->withSkippedModulePackageNames(array_merge(Config::get('ecotone.skippedModulePackageNames'), [ModulePackageList::TEST_PACKAGE]));
->withSkippedModulePackageNames($skippedModules);

if ($isCachingConfiguration) {
$applicationConfiguration = $applicationConfiguration
Expand Down
15 changes: 14 additions & 1 deletion packages/Laravel/tests/Application/Execution/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

namespace Test\Ecotone\Laravel\Application\Execution;

use Ecotone\Lite\Test\MessagingTestSupport;
use Ecotone\Messaging\Config\ConfiguredMessagingSystem;
use Ecotone\Modelling\CommandBus;
use Ecotone\Modelling\QueryBus;
use Illuminate\Foundation\Http\Kernel;
use Illuminate\Foundation\Testing\TestCase;
use Illuminate\Support\Facades\Config;
use Test\Ecotone\Laravel\Fixture\User\User;
use Test\Ecotone\Laravel\Fixture\User\UserRepository;

Expand Down Expand Up @@ -67,6 +70,16 @@ public function test_sending_command_using_expression_language()
$amount,
$queryBus->sendWithRouting('getAmount')
);
;
}

public function test_it_boots_messaging_system_with_test_support(): void
{
$app = $this->createApplication();

$messagingSystem = $app->get(ConfiguredMessagingSystem::class);

self::assertInstanceOf(
MessagingTestSupport::class,
$messagingSystem->getGatewayByName(MessagingTestSupport::class));
}
}
1 change: 1 addition & 0 deletions packages/Laravel/tests/Application/config/ecotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
'Test\Ecotone\Laravel\Fixture',
],
'skippedModulePackageNames' => ModulePackageList::allPackages(),
'test' => true,
];
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class EcotoneCompilerPass implements CompilerPassInterface
public const SERVICE_NAME = 'ecotone.service_name';
public const WORKING_NAMESPACES_CONFIG = 'ecotone.namespaces';
public const FAIL_FAST_CONFIG = 'ecotone.fail_fast';
public const TEST = 'ecotone.test';
public const LOAD_SRC = 'ecotone.load_src';
public const DEFAULT_SERIALIZATION_MEDIA_TYPE = 'ecotone.serializationMediaType';
public const ERROR_CHANNEL = 'ecotone.errorChannel';
Expand All @@ -52,13 +53,18 @@ public static function getRootProjectPath(ContainerInterface $container)
public static function getMessagingConfiguration(ContainerInterface $container, bool $useCachedVersion = false): Configuration
{
$ecotoneCacheDirectory = $container->getParameter('kernel.cache_dir') . self::CACHE_DIRECTORY_SUFFIX;
$skippedModules = $container->getParameter(self::SKIPPED_MODULE_PACKAGES);
if (! $container->getParameter(self::TEST)) {
$skippedModules[] = ModulePackageList::TEST_PACKAGE;
}

/** @TODO Ecotone 2.0 use ServiceContext to configure Symfony */
$serviceConfiguration = ServiceConfiguration::createWithDefaults()
->withEnvironment($container->getParameter('kernel.environment'))
->withFailFast($container->getParameter('kernel.environment') === 'prod' ? false : $container->getParameter(self::FAIL_FAST_CONFIG))
->withLoadCatalog($container->getParameter(self::LOAD_SRC) ? 'src' : '')
->withNamespaces($container->getParameter(self::WORKING_NAMESPACES_CONFIG))
->withSkippedModulePackageNames(array_merge($container->getParameter(self::SKIPPED_MODULE_PACKAGES), [ModulePackageList::TEST_PACKAGE]))
->withSkippedModulePackageNames($skippedModules)
->withCacheDirectoryPath($ecotoneCacheDirectory);

if ($container->getParameter(self::SERVICE_NAME)) {
Expand Down
4 changes: 4 additions & 0 deletions packages/Symfony/DepedencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public function getConfigTreeBuilder()
->defaultTrue()
->end()

->booleanNode('test')
->defaultFalse()
->end()

->booleanNode('loadSrcNamespaces')
->defaultTrue()
->end()
Expand Down
1 change: 1 addition & 0 deletions packages/Symfony/DepedencyInjection/EcotoneExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter(EcotoneCompilerPass::WORKING_NAMESPACES_CONFIG, $config['namespaces']);
$container->setParameter(EcotoneCompilerPass::SERVICE_NAME, $config['serviceName']);
$container->setParameter(EcotoneCompilerPass::FAIL_FAST_CONFIG, $config['failFast']);
$container->setParameter(EcotoneCompilerPass::TEST, $config['test']);
$container->setParameter(EcotoneCompilerPass::LOAD_SRC, $config['loadSrcNamespaces']);
$container->setParameter(EcotoneCompilerPass::DEFAULT_SERIALIZATION_MEDIA_TYPE, $config['defaultSerializationMediaType']);
$container->setParameter(EcotoneCompilerPass::SKIPPED_MODULE_PACKAGES, $config['skippedModulePackageNames']);
Expand Down
5 changes: 4 additions & 1 deletion packages/Symfony/config/packages/test/framework.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
framework:
test: ~
test: ~

ecotone:
test: true
30 changes: 30 additions & 0 deletions packages/Symfony/tests/phpunit/SymfonyApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Test;

use Ecotone\Lite\Test\MessagingTestSupport;
use Ecotone\Messaging\Config\ConfiguredMessagingSystem;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class SymfonyApplicationTest extends KernelTestCase
{
public function test_it_boots_kernel_with_test_support(): void
{
self::bootKernel([
'environment' => 'test'
]);
self::assertInstanceOf(
MessagingTestSupport::class,
self::getMessagingTestSupport());
}

protected static function getMessagingSystem(): ConfiguredMessagingSystem
{
return static::getContainer()->get(ConfiguredMessagingSystem::class);
}

protected static function getMessagingTestSupport(): MessagingTestSupport
{
return static::getMessagingSystem()->getGatewayByName(MessagingTestSupport::class);
}
}

0 comments on commit c104380

Please sign in to comment.