public function testBuildCreateCommandWithInvalidCommands() { $author_type = new AuthorType(); $builder = new AggregateRootCommandBuilder($author_type, CreateAuthorCommand::CLASS); $build_result = $builder->withValues(['firstname' => 123, 'products' => [['@type' => 'highlight', 'title' => 456, 'description' => 789], ['@type' => 'highlight', 'title' => 890, 'description' => 321], ['@type' => 'highlight', 'description' => 222], ['title' => 'hello'], ['@type' => 'brexit', 'title' => 'goodbye']]])->build(); $this->assertInstanceOf(Result::CLASS, $build_result); $this->assertInstanceOf(Error::CLASS, $build_result); $this->assertEquals(['firstname' => [['path' => 'firstname', 'incidents' => ['non_string_value' => ['value' => 123]]]], 'email' => [['path' => 'email', 'incidents' => ['mandatory' => ['reason' => 'missing']]]], 'lastname' => [['path' => 'lastname', 'incidents' => ['mandatory' => ['reason' => 'missing']]]], 'products.0.title' => [['path' => 'products.highlight.title', 'incidents' => ['non_string_value' => ['value' => 456]]]], 'products.0.description' => [['path' => 'products.highlight.description', 'incidents' => ['non_string_value' => ['value' => 789]]]], 'products.1.title' => [['path' => 'products.highlight.title', 'incidents' => ['non_string_value' => ['value' => 890]]]], 'products.1.description' => [['path' => 'products.highlight.description', 'incidents' => ['non_string_value' => ['value' => 321]]]], 'products.2.title' => [['path' => 'products.highlight.title', 'incidents' => ['mandatory' => ['reason' => 'missing']]]], 'products.2.description' => [['path' => 'products.highlight.description', 'incidents' => ['non_string_value' => ['value' => 222]]]], 'products.3.@type' => [['path' => 'products', 'incidents' => ['invalid_type' => ['reason' => 'missing']]]], 'products.4.@type' => [['path' => 'products', 'incidents' => ['invalid_type' => ['reason' => 'unknown']]]]], $build_result->get()); }
protected function importFixture($type_name, array $fixture) { $aggregate_root_type = $this->aggregate_root_type_map->getItem($type_name); $type_class_name = get_class($aggregate_root_type); $command_namespace = array_slice(explode('\\', $type_class_name), 0, -2); $command_class = isset($fixture['@command']) ? $fixture['@command'] : sprintf('%1$s\\Task\\Create%2$s\\Create%2$sCommand', implode('\\', $command_namespace), $aggregate_root_type->getName()); $builder = new AggregateRootCommandBuilder($aggregate_root_type, $command_class); if (isset($fixture['@command'])) { unset($fixture['@command']); foreach ($fixture as $command_property => $command_data) { $builder->{'with' . StringToolkit::asCamelCase($command_property)}($command_data); } } else { $builder->withValues($fixture); } $result = $builder->build(); if (!$result instanceof Success) { $this->logger->error('Error importing fixtures:' . print_r($result->get(), true)); throw new RuntimeError(sprintf('Error importing fixtures. Incidents have been logged.')); } $this->command_bus->post($result->get()); }