/** * @param NewCommand $command */ public function handle(NewCommand $command) { $recipe = $command->getEntity(); if (!$recipe instanceof Recipe) { throw new \RuntimeException(sprintf("Entity \"%s\" can't be handled by Recipe\\NewCommandHandler", get_class($recipe))); } $this->storage->save($recipe); $this->engine->indexRecipe($recipe); }
function it_save_and_index_updated_recipes(Storage $storage, SearchEngine $searchEngine) { $recipe = new Recipe(new Name("Screwdriver")); $recipe->publish(); $command = new EditCommand($recipe, new ChangeSet()); $searchEngine->indexRecipe(Argument::any())->shouldBeCalled(); $storage->save(Argument::type(Recipe::class))->shouldBeCalled(); $this->handle($command); }