/** * Find a category by name. * * @param $name * @throws CategoryNotFoundException * @return mixed */ public function findByName($name) { $category = $this->categoryRepo->findByName($name); if (is_null($category)) { $error = 'Category Not Found'; throw new CategoryNotFoundException($error); } return $category; }
/** @test */ function it_try_to_find_a_non_existing_category(CategoryDB $categoryRepository) { $nameCategory = 'test.category'; $categoryRepository->findByName($nameCategory)->shouldBeCalled()->willReturn(null); $this->shouldThrow(CategoryNotFoundException::class)->during('findByName', [$nameCategory]); }