Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/*
* licence Apache-2.0
*/
declare(strict_types=1);

use Ecotone\Messaging\Config\ModulePackageList;
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use PHPUnit\Framework\TestCase;

class SymfonyEventSourcingIntegrationTest extends TestCase
{
protected function tearDown(): void
{
restore_exception_handler();
}

#[DoesNotPerformAssertions]
public function test_symfony_in_test_mode_with_es_should_boot(): void
{
\putenv(sprintf('APP_SKIPPED_PACKAGES=%s', \json_encode(ModulePackageList::allPackagesExcept([ModulePackageList::EVENT_SOURCING_PACKAGE]), JSON_THROW_ON_ERROR)));
$kernel = new \Monorepo\ExampleApp\Symfony\Kernel('test_es', false);
$kernel->boot();
}
}
18 changes: 18 additions & 0 deletions Monorepo/ExampleApp/Symfony/config/services_test_es.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

use Monorepo\ExampleApp\Common\Domain\Product\ProductRepository;
use Monorepo\ExampleApp\Common\Domain\User\UserRepository;
use Monorepo\ExampleApp\Common\Infrastructure\Authentication\AuthenticationService;
use Monorepo\ExampleApp\Common\Infrastructure\Configuration;
use Monorepo\ExampleApp\Common\UI\OrderController;
use OpenTelemetry\API\Trace\TracerProviderInterface;
use OpenTelemetry\SDK\Trace\SpanExporter\InMemoryExporter;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Test\Ecotone\OpenTelemetry\Integration\TracingTestCase;
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;

return static function (ContainerConfigurator $containerConfigurator): void {
$containerConfigurator->extension('ecotone', [
'test' => true,
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,6 @@ public function prepare(Configuration $messagingConfiguration, array $extensionO
GatewayHeaderBuilder::create('channelName', 'ecotone.test_support_gateway.channel_name'),
]));
}

$messagingConfiguration->registerServiceDefinition(
InMemoryEventStoreStreamSource::class,
new Definition(InMemoryEventStoreStreamSource::class, [
new Reference(InMemoryEventStore::class),
])
);
}

public function canHandle($extensionObject): bool
Expand Down Expand Up @@ -401,6 +394,7 @@ private function registerMessageCollector(Configuration $configuration, Interfac

private function registerInMemoryEventStoreIfNeeded(Configuration $messagingConfiguration, array $extensionObjects, ServiceConfiguration $serviceConfiguration): void
{
$registerInMemoryEventStoreStreamSource = false;
if (! $serviceConfiguration->isModulePackageEnabled(ModulePackageList::EVENT_SOURCING_PACKAGE)) {
// Register InMemoryEventStore as the primary definition
$messagingConfiguration->registerServiceDefinition(
Expand All @@ -412,27 +406,36 @@ private function registerInMemoryEventStoreIfNeeded(Configuration $messagingConf
EventStore::class,
new Reference(InMemoryEventStore::class),
);

return;
}

/**
* This is to honour current PdoEventSourcing implementation, as current one is initializing In Memory in EventSourcingConfiguration.
* We register the InMemoryEventStore by getting it from the EventSourcingConfiguration service,
* which ensures we use the same instance that's used by LazyProophEventStore.
*/
foreach ($extensionObjects as $extensionObject) {
if (class_exists(EventSourcingConfiguration::class) && $extensionObject instanceof EventSourcingConfiguration) {
if ($extensionObject->isInMemory()) {
// Register InMemoryEventStore by calling getInMemoryEventStore() on the EventSourcingConfiguration service
// This ensures we use the same instance that's used by LazyProophEventStore
$messagingConfiguration->registerServiceDefinition(
InMemoryEventStore::class,
new Definition(InMemoryEventStore::class, [], [EventSourcingConfiguration::class, 'getInMemoryEventStore'])
);
$registerInMemoryEventStoreStreamSource = true;
} else {
/**
* This is to honour current PdoEventSourcing implementation, as current one is initializing In Memory in EventSourcingConfiguration.
* We register the InMemoryEventStore by getting it from the EventSourcingConfiguration service,
* which ensures we use the same instance that's used by LazyProophEventStore.
*/
foreach ($extensionObjects as $extensionObject) {
if (class_exists(EventSourcingConfiguration::class) && $extensionObject instanceof EventSourcingConfiguration) {
if ($extensionObject->isInMemory()) {
// Register InMemoryEventStore by calling getInMemoryEventStore() on the EventSourcingConfiguration service
// This ensures we use the same instance that's used by LazyProophEventStore
$messagingConfiguration->registerServiceDefinition(
InMemoryEventStore::class,
new Definition(InMemoryEventStore::class, [], [EventSourcingConfiguration::class, 'getInMemoryEventStore'])
);
$registerInMemoryEventStoreStreamSource = true;
}
break;
}
break;
}
}

if ($registerInMemoryEventStoreStreamSource) {
$messagingConfiguration->registerServiceDefinition(
InMemoryEventStoreStreamSource::class,
new Definition(InMemoryEventStoreStreamSource::class, [
new Reference(InMemoryEventStore::class),
])
);
}
}
}