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); }
/** * @param RemoveCommand $command */ public function handle(RemoveCommand $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->remove($recipe); $this->engine->removeRecipeFromIndex($recipe); }
/** * @param string $slug * @return null|Recipe */ public function findBySlug($slug) { $recipe = $this->storage->fetchBySlug($slug); if (!is_null($recipe)) { if ($this->isolate->getContext()->hasOpenTransaction()) { $transaction = $this->isolate->getContext()->getTransaction(); $transaction->persist($recipe); } } return $recipe; }
/** * @param mixed $entity * @return boolean */ public function isIdentified($entity) { return $this->storage->hasRecipeWithName($entity->getName()); }