Files
Distributing-Carriers/tests/demo.php
m.jalmoudy 6b5222ad84 feat(core): Implement DDD, CQRS, and Event Sourcing architecture
- Add project README and Composer configuration with PSR-4 autoloading
- Implement domain layer with AggregateRoot base class for event sourcing
- Create Carrier aggregate with CarrierRegistered domain event
- Add application layer with RegisterCarrierCommand and RegisterCarrierHandler
- Implement infrastructure layer with EventStore interface and CassandraEventStore
- Add CommandBus and Router for request handling and routing
- Create demo test file to showcase carrier registration workflow
- Establish foundation for event-driven architecture with Cassandra persistence
2025-12-02 14:58:22 +03:30

67 lines
2.0 KiB
PHP

<?php
namespace Cassandra {
class Timestamp
{
}
}
namespace {
// Mock Cassandra Session
class MockCassandraSession
{
public $executedStatements = [];
public function prepare($cql)
{
return new MockStatement($cql);
}
public function execute($statement, $options)
{
$this->executedStatements[] = [
'statement' => $statement->cql,
'arguments' => $options['arguments']
];
echo "Executed CQL: " . $statement->cql . "\n";
return [];
}
}
class MockStatement
{
public $cql;
public function __construct($cql)
{
$this->cql = $cql;
}
}
require_once __DIR__ . '/../src/Infrastructure/EventStore.php';
require_once __DIR__ . '/../src/Infrastructure/CassandraEventStore.php';
require_once __DIR__ . '/../src/Infrastructure/CommandBus.php';
require_once __DIR__ . '/../src/Domain/AggregateRoot.php';
require_once __DIR__ . '/../src/Domain/Events/CarrierRegistered.php';
require_once __DIR__ . '/../src/Domain/Carrier.php';
require_once __DIR__ . '/../src/Application/Commands/RegisterCarrierCommand.php';
require_once __DIR__ . '/../src/Application/Handlers/RegisterCarrierHandler.php';
use DistributingCarriers\Infrastructure\CommandBus;
use DistributingCarriers\Infrastructure\CassandraEventStore;
use DistributingCarriers\Application\Commands\RegisterCarrierCommand;
use DistributingCarriers\Application\Handlers\RegisterCarrierHandler;
echo "Starting Demo...\n";
$session = new MockCassandraSession();
$eventStore = new CassandraEventStore($session);
$commandBus = new CommandBus();
$commandBus->register(RegisterCarrierCommand::class, new RegisterCarrierHandler($eventStore));
$command = new RegisterCarrierCommand("Demo Carrier", "demo@example.com");
$commandBus->dispatch($command);
echo "Demo Completed.\n";
}