public function handle(Query $query) { $id = TaskId::fromString($query->id()); foreach ($this->tasks as $task) { if ($task->id()->equals($id)) { return TaskViewModel::fromTask($task); } } throw new Exception('Task not found'); }
public function test_that_it_allows_loading_partial_streams() { $task = Task::create('First task description'); $stream = $task->getRecordedEvents(); $this->store->appendStream($stream); $task->clearRecordedEvents(); $task->changeDescription('Updating the description'); $stream = $task->getRecordedEvents(); $this->store->appendStream($stream); $task->clearRecordedEvents(); $task->changeDescription('Testing the event store'); $stream = $task->getRecordedEvents(); $this->store->appendStream($stream); $task->clearRecordedEvents(); $idString = $task->id()->toString(); $eventStream = $this->store->loadStream(TaskId::fromString($idString), Type::create(Task::class), 1, 1); $eventMessages = []; foreach ($eventStream as $eventMessage) { $eventMessages[] = $eventMessage; } $descChanged = 'Novuso.Test.Common.Doubles.Domain.Model.DescriptionChangedEvent'; $this->assertTrue(count($eventMessages) === 1 && $descChanged === (string) $eventMessages[0]->payloadType()); }
public function test_that_hash_value_returns_expected_string() { $id = TaskId::fromString('014f18df-9e1a-44de-9eee-d9f997491947'); $task = Task::reconstitute($id, 'Go to the store', 0); $this->assertSame('014f18df9e1a44de9eeed9f997491947', $task->hashValue()); }
use Novuso\Test\Common\Doubles\Domain\Model\TaskId; $container = new ServiceContainer(); $container->service('logger', function () { return new Novuso\Test\Common\Doubles\Application\Logging\InMemoryLogger(); }); $container->service('query.pipeline', function ($container) { return new Novuso\Common\Application\Messaging\Query\QueryPipeline($container->get('query.handler_resolver'), $container->getParameter('query.filters', [])); }); $container->service('query.service', function ($container) { return new Novuso\Common\Application\Messaging\Query\QueryHandlerService($container->get('query.handler_resolver')); }); $container->service('query.handler_resolver', function ($container) { return new Novuso\Common\Application\Messaging\Query\Resolver\QueryServiceResolver($container->get('query.service_map')); }); $container->service('query.service_map', function ($container) { $serviceMap = new Novuso\Common\Application\Messaging\Query\Resolver\QueryServiceMap($container); $handlers = []; $query = 'Novuso\\Test\\Common\\Doubles\\Application\\Messaging\\Query\\GetTaskQuery'; $serviceId = 'query.handler.get_task'; $handlers[$query] = $serviceId; $serviceMap->registerHandlers($handlers); return $serviceMap; }); $container->service('query.filter.logger', function ($container) { return new Novuso\Common\Application\Messaging\Query\Filter\QueryLogger($container->get('logger')); }); $container->service('query.handler.get_task', function ($container) { $tasks = [Task::reconstitute(TaskId::fromString('014faa02-b67b-4beb-9d68-10abbb4455cb'), 'Test task one', 0), Task::reconstitute(TaskId::fromString('014faa02-b67c-4aa4-b063-ceaf27f4a9b3'), 'Test task two', 0), Task::reconstitute(TaskId::fromString('014faa02-b67e-47e1-b1da-5bbdc7e342b3'), 'Test task three', 0)]; return new Novuso\Test\Common\Doubles\Application\Messaging\Query\GetTaskHandler($tasks); }); return $container;