Fenos\Notifynder\Categories\CategoryManager::findByName PHP Method

findByName() public method

Find a category by name.
public findByName ( $name ) : mixed
$name
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;
    }

Usage Example

 /** @test */
 function it_add_a_category_id_to_the_builder_givin_the_name_of_it(CategoryManager $category, NotificationCategory $categoryModel)
 {
     $name = 'category.name';
     $category_id = 1;
     $category->findByName($name)->shouldBeCalled()->willReturn($categoryModel);
     $categoryModel->getAttribute('id')->willReturn($category_id);
     $this->category($name)->shouldReturnAnInstanceOf(NotifynderBuilder::class);
 }