Skip to content

Commit

Permalink
Allows to enable Ecotone Enterprise Features (#385)
Browse files Browse the repository at this point in the history
* Add ability to set up Symfony, Laravel and Ecotone Lite with Enterprise features
  • Loading branch information
dgafka authored Oct 13, 2024
1 parent b947939 commit f24bdf7
Show file tree
Hide file tree
Showing 45 changed files with 1,105 additions and 37 deletions.
2 changes: 1 addition & 1 deletion bin/update-required-packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$composerFile = $package['directory'] . DIRECTORY_SEPARATOR . 'composer.json';
$composer = json_decode(file_get_contents($composerFile), true);
$composer['extra']['branch-alias']['dev-main'] = $version . '-dev';
$releaseTime = (new \DateTimeImmutable('now', new DateTimeZone('UTC')))->modify("+15 min");
$releaseTime = (new \DateTimeImmutable('now', new DateTimeZone('UTC')));
$composer['extra']['release-time'] = $releaseTime->format('Y-m-d H:i:s');

foreach ($composer['require'] as $requiredPackage => $requiredVersion) {
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@
],
"Test\\Ecotone\\Laravel\\": "packages/Laravel/tests",
"App\\MultiTenant\\": "packages/Laravel/tests/MultiTenant/app",
"App\\Licence\\Laravel\\": "packages/Laravel/tests/Licence/app",
"Symfony\\App\\MultiTenant\\": "packages/Symfony/tests/phpunit/MultiTenant/src",
"Symfony\\App\\SingleTenant\\": "packages/Symfony/tests/phpunit/SingleTenant/src",
"Symfony\\App\\Licence\\": "packages/Symfony/tests/phpunit/Licence/src",
"Test\\Ecotone\\Symfony\\Behat\\Bootstrap\\": "packages/Symfony/tests/Behat/Bootstrap",
"Tests\\Ecotone\\": "tests"
}
Expand Down Expand Up @@ -219,7 +221,8 @@
"config": {
"allow-plugins": {
"wikimedia/composer-merge-plugin": true,
"php-http/discovery": false
"php-http/discovery": false,
"tbachert/spi": false
},
"process-timeout": 600
},
Expand Down
16 changes: 9 additions & 7 deletions packages/Ecotone/src/Lite/EcotoneLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ final class EcotoneLite
* @param array<string,string> $configurationVariables
* @param ContainerInterface|object[] $containerOrAvailableServices
* @param bool $allowGatewaysToBeRegisteredInContainer when enabled will add to the container Command/Query/Event and other gateways. Your container must have 'set' method however
* @param string|null $licenceKey licence key for enterprise version
*/
public static function bootstrap(
array $classesToResolve = [],
Expand All @@ -53,7 +54,7 @@ public static function bootstrap(
bool $useCachedVersion = false,
?string $pathToRootCatalog = null,
bool $allowGatewaysToBeRegisteredInContainer = false,
?string $enterpriseLicenceKey = null,
?string $licenceKey = null,
): ConfiguredMessagingSystem {
return self::prepareConfiguration(
$containerOrAvailableServices,
Expand All @@ -64,7 +65,7 @@ public static function bootstrap(
false,
$allowGatewaysToBeRegisteredInContainer,
$useCachedVersion,
$enterpriseLicenceKey,
$licenceKey,
);
}

Expand Down Expand Up @@ -107,7 +108,7 @@ public static function bootstrapForTesting(
* @param array<string,string> $configurationVariables
* @param ContainerInterface|object[] $containerOrAvailableServices
* @param MessageChannelBuilder[] $enableAsynchronousProcessing
* @param bool $enterpriseLicenceKey bool Make use of Enterprise Modules for testing purposes
* @param string|null $licenceKey licence key for enterprise version
*/
public static function bootstrapFlowTesting(
array $classesToResolve = [],
Expand All @@ -120,9 +121,9 @@ public static function bootstrapFlowTesting(
bool $addInMemoryEventSourcedRepository = true,
?array $enableAsynchronousProcessing = null,
TestConfiguration $testConfiguration = null,
?string $enterpriseLicenceKey = null
?string $licenceKey = null
): FlowTestSupport {
$configuration = self::prepareForFlowTesting($configuration, ModulePackageList::allPackages(), $classesToResolve, $addInMemoryStateStoredRepository, $enableAsynchronousProcessing, $testConfiguration, $enterpriseLicenceKey);
$configuration = self::prepareForFlowTesting($configuration, ModulePackageList::allPackages(), $classesToResolve, $addInMemoryStateStoredRepository, $enableAsynchronousProcessing, $testConfiguration, $licenceKey);

if ($addInMemoryEventSourcedRepository) {
$configuration = $configuration->addExtensionObject(InMemoryRepositoryBuilder::createDefaultEventSourcedRepository());
Expand All @@ -139,6 +140,7 @@ public static function bootstrapFlowTesting(
* @param string[] $classesToResolve
* @param array<string,string> $configurationVariables
* @param ContainerInterface|object[] $containerOrAvailableServices
* @param string|null $licenceKey licence key for enterprise version
*/
public static function bootstrapFlowTestingWithEventStore(
array $classesToResolve = [],
Expand All @@ -151,9 +153,9 @@ public static function bootstrapFlowTestingWithEventStore(
bool $runForProductionEventStore = false,
?array $enableAsynchronousProcessing = null,
TestConfiguration $testConfiguration = null,
?string $enterpriseLicenceKey = null,
?string $licenceKey = null,
): FlowTestSupport {
$configuration = self::prepareForFlowTesting($configuration, ModulePackageList::allPackagesExcept([ModulePackageList::EVENT_SOURCING_PACKAGE, ModulePackageList::DBAL_PACKAGE, ModulePackageList::JMS_CONVERTER_PACKAGE]), $classesToResolve, $addInMemoryStateStoredRepository, $enableAsynchronousProcessing, $testConfiguration, $enterpriseLicenceKey);
$configuration = self::prepareForFlowTesting($configuration, ModulePackageList::allPackagesExcept([ModulePackageList::EVENT_SOURCING_PACKAGE, ModulePackageList::DBAL_PACKAGE, ModulePackageList::JMS_CONVERTER_PACKAGE]), $classesToResolve, $addInMemoryStateStoredRepository, $enableAsynchronousProcessing, $testConfiguration, $licenceKey);

if (! $configuration->hasExtensionObject(BaseEventSourcingConfiguration::class) && ! $runForProductionEventStore) {
Assert::isTrue(class_exists(EventSourcingConfiguration::class), 'To use Flow Testing with Event Store you need to add event sourcing module.');
Expand Down
12 changes: 6 additions & 6 deletions packages/Ecotone/tests/Lite/Licence/LicencingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function test_failing_on_licence_not_encoded(): void

EcotoneLite::bootstrap([
Person::class,
], enterpriseLicenceKey: 'incorrect');
], licenceKey: 'incorrect');
}

/**
Expand All @@ -38,7 +38,7 @@ public function test_failing_on_licence_data_not_having_required_fields(string $

EcotoneLite::bootstrap([
Person::class,
], enterpriseLicenceKey: base64_encode($licenceKey));
], licenceKey: base64_encode($licenceKey));
}

public function test_valid_licence(): void
Expand All @@ -47,7 +47,7 @@ public function test_valid_licence(): void
[
Person::class,
],
enterpriseLicenceKey: $this->generate(
licenceKey: $this->generate(
(new DateTimeImmutable('now', new DateTimeZone('UTC')))->modify('+30 seconds'),
false
)
Expand All @@ -64,7 +64,7 @@ public function test_failing_on_expired_licence(): void
[
Person::class,
],
enterpriseLicenceKey: $this->generate(
licenceKey: $this->generate(
(new DateTimeImmutable('now', new DateTimeZone('UTC')))->modify('-30 seconds'),
false
)
Expand All @@ -80,7 +80,7 @@ public function test_licence_for_enterprise_plus_is_valid_when_expires_after_pac
[
Person::class,
],
enterpriseLicenceKey: $this->generate(
licenceKey: $this->generate(
$releaseTime->modify('+30 seconds'),
true
)
Expand All @@ -100,7 +100,7 @@ public function test_licence_for_enterprise_plus_is_invalid_when_expires_before_
[
Person::class,
],
enterpriseLicenceKey: $this->generate(
licenceKey: $this->generate(
$releaseTime->modify('-30 seconds'),
true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private function bootstrapEcotone(array $classesToResolve, array $services, arra
ServiceConfiguration::createWithDefaults()
->withExtensionObjects($collectorConfigurations),
enableAsynchronousProcessing: $channelBuilders,
enterpriseLicenceKey: $withEnterpriseLicence ? LicenceTesting::VALID_LICENCE : null
licenceKey: $withEnterpriseLicence ? LicenceTesting::VALID_LICENCE : null
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function test_sending_and_receiving_from_single_channel(): void
DynamicMessageChannelBuilder::createRoundRobin('async_channel', ['channel_one']),
SimpleMessageChannelBuilder::createQueueChannel('channel_one'),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);

$ecotoneLite->sendDirectToChannel('handle_channel', ['test']);
Expand Down Expand Up @@ -72,7 +72,7 @@ public function test_sending_and_receiving_from_multiple_channels(): void
SimpleMessageChannelBuilder::createQueueChannel('channel_one'),
SimpleMessageChannelBuilder::createQueueChannel('channel_two'),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);

/** Send to channel_one */
Expand Down Expand Up @@ -110,7 +110,7 @@ public function test_sending_and_receiving_from_internal_channels(): void
SimpleMessageChannelBuilder::createQueueChannel('channel_two'),
]),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);

/** Send to channel_one */
Expand Down Expand Up @@ -148,7 +148,7 @@ public function test_sending_and_receiving_from_internal_channels_with_custom_na
'y' => SimpleMessageChannelBuilder::createQueueChannel('channel_two'),
]),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);

/** Send to x */
Expand Down Expand Up @@ -193,7 +193,7 @@ public function test_using_skipping_receiving_strategy(): void
SimpleMessageChannelBuilder::createQueueChannel('channel_one'),
SimpleMessageChannelBuilder::createQueueChannel('channel_two'),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);

$ecotoneLite->sendDirectToChannel('handle_channel', ['test']);
Expand Down Expand Up @@ -227,7 +227,7 @@ public function test_sending_and_receiving_from_single_channel_using_custom_stra
->withCustomReceivingStrategy('dynamicChannel.receive'),
SimpleMessageChannelBuilder::createQueueChannel('channel_one'),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);

$ecotoneLite->sendDirectToChannel('handle_channel', ['test']);
Expand Down Expand Up @@ -266,7 +266,7 @@ public function test_sending_and_receiving_from_multiple_channels_using_custom_s
SimpleMessageChannelBuilder::createQueueChannel('channel_two'),
SimpleMessageChannelBuilder::createQueueChannel('channel_three'),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);

/** Sending to channel one */
Expand Down Expand Up @@ -318,7 +318,7 @@ public function test_sending_using_header_strategy_with_mapping(): void
SimpleMessageChannelBuilder::createQueueChannel('channel_three'),
]),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);

$ecotoneLite->sendDirectToChannel('handle_channel', ['test'], ['tenant' => 'tenant_b']);
Expand Down Expand Up @@ -366,7 +366,7 @@ public function test_sending_using_header_strategy_from_factory(): void
SimpleMessageChannelBuilder::createQueueChannel('channel_two'),
SimpleMessageChannelBuilder::createQueueChannel('channel_three'),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);

$ecotoneLite->sendDirectToChannel('handle_channel', ['test'], ['tenant' => 'tenant_b']);
Expand Down Expand Up @@ -411,7 +411,7 @@ public function test_sending_using_header_strategy_without_mapping(): void
SimpleMessageChannelBuilder::createQueueChannel('tenant_c'),
]),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);

$ecotoneLite->sendDirectToChannel('handle_channel', ['test'], ['tenant' => 'tenant_b']);
Expand Down Expand Up @@ -451,7 +451,7 @@ public function test_sending_using_header_strategy_throws_exception_when_header_
'tenant',
),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);

$this->expectException(InvalidArgumentException::class);
Expand Down Expand Up @@ -480,7 +480,7 @@ public function test_sending_using_header_strategy_with_default_channel(): void
SimpleMessageChannelBuilder::createQueueChannel('tenant_shared'),
]),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);

$ecotoneLite->sendDirectToChannel('handle_channel', ['test']);
Expand Down Expand Up @@ -513,7 +513,7 @@ public function test_throwing_exception_if_trying_to_consume_from_internal_chann
SimpleMessageChannelBuilder::createQueueChannel('tenant_a'),
]),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);

$this->expectException(InvalidArgumentException::class);
Expand All @@ -539,7 +539,7 @@ public function test_throwing_exception_if_trying_to_register_asynchronous_handl
SimpleMessageChannelBuilder::createQueueChannel('async_channel'),
]),
],
enterpriseLicenceKey: LicenceTesting::VALID_LICENCE,
licenceKey: LicenceTesting::VALID_LICENCE,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ private function bootstrapEcotone(array $classesToResolve, array $services, arra
ServiceConfiguration::createWithDefaults()
->withExtensionObjects($extensionObjects),
enableAsynchronousProcessing: $channelBuilders,
enterpriseLicenceKey: $withEnterpriseLicence ? LicenceTesting::VALID_LICENCE : null
licenceKey: $withEnterpriseLicence ? LicenceTesting::VALID_LICENCE : null
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function test_default_repository_is_used_when_multiple_repositories_are_r
ArticleRepository::class => $articleRepository,
PageRepository::class => $pageRepository,
],
enterpriseLicenceKey: $isEnterprise ? LicenceTesting::VALID_LICENCE : null,
licenceKey: $isEnterprise ? LicenceTesting::VALID_LICENCE : null,
);

// We have provided multiple standard repositories, therefore there is single Event Sourced repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function test_registering_and_using_headers_in_event_sourcing_handler():
{
$ecotoneLite = EcotoneLite::bootstrapFlowTesting([
Person::class,
], enterpriseLicenceKey: LicenceTesting::VALID_LICENCE);
], licenceKey: LicenceTesting::VALID_LICENCE);


$ecotoneLite->sendCommand(new RegisterPerson('123', 'premium'));
Expand Down
3 changes: 2 additions & 1 deletion packages/Laravel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"autoload-dev": {
"psr-4": {
"Test\\Ecotone\\Laravel\\": "tests",
"App\\MultiTenant\\": "tests/MultiTenant/app"
"App\\MultiTenant\\": "tests/MultiTenant/app",
"App\\Licence\\Laravel\\": "tests/Licence/app"
}
},
"require": {
Expand Down
10 changes: 10 additions & 0 deletions packages/Laravel/config/ecotone.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,14 @@
|
*/
'test' => false,

/*
|--------------------------------------------------------------------------
| licenceKey
|--------------------------------------------------------------------------
|
| Licence key to use Ecotone Enterprise features
|
*/
'licenceKey' => null,
];
4 changes: 4 additions & 0 deletions packages/Laravel/src/EcotoneProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public function register()
->withSkippedModulePackageNames($skippedModules)
->withCacheDirectoryPath($cacheDirectory);

if (Config::get('ecotone.licenceKey') !== null) {
$applicationConfiguration = $applicationConfiguration->withLicenceKey(Config::get('ecotone.licenceKey'));
}

$serializationMediaType = Config::get('ecotone.defaultSerializationMediaType');
if ($serializationMediaType) {
$applicationConfiguration = $applicationConfiguration
Expand Down
42 changes: 42 additions & 0 deletions packages/Laravel/tests/Licence/LicenceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Test\Ecotone\Laravel\Licence;

use App\MultiTenant\Application\Command\RegisterCustomer;
use Ecotone\Modelling\CommandBus;
use Ecotone\Modelling\QueryBus;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Http\Kernel;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use PHPUnit\Framework\TestCase;
use RuntimeException;

/**
* licence Enterprise
* @internal
*/
final class LicenceTest extends TestCase
{
private Application $app;
private QueryBus $queryBus;
private CommandBus $commandBus;

public function setUp(): void
{
$app = require __DIR__ . '/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
$this->app = $app;
$this->queryBus = $app->get(QueryBus::class);
$this->commandBus = $app->get(CommandBus::class);
}

public function test_triggering_laravel_with_licence_key(): void
{
$this->commandBus->sendWithRouting('sendNotification');

$this->expectNotToPerformAssertions();
}
}
Loading

0 comments on commit f24bdf7

Please sign in to comment.