Completed
Push — master ( 9abbc7...a687e5 )
by Fabrizio
03:03
created

CategoryManagerSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace spec\Fenos\Notifynder\Categories;
4
5
use Fenos\Notifynder\Contracts\CategoryDB;
6
use Fenos\Notifynder\Exceptions\CategoryNotFoundException;
7
use Fenos\Notifynder\Models\NotificationCategory;
8
use PhpSpec\ObjectBehavior;
9
10
class CategoryManagerSpec extends ObjectBehavior
11
{
12
    public function it_is_initializable()
13
    {
14
        $this->shouldHaveType('Fenos\Notifynder\Categories\CategoryManager');
15
    }
16
17
    public function let(CategoryDB $categoryRepository)
18
    {
19
        $this->beConstructedWith($categoryRepository);
20
    }
21
22
    /** @test */
23
    public function it_find_a_category_by_name(CategoryDB $categoryRepository)
24
    {
25
        $nameCategory = 'test.category';
26
27
        $categoryRepository->findByName($nameCategory)->shouldBeCalled()
28
                           ->willReturn(new NotificationCategory());
29
30
        $this->findByName($nameCategory)->shouldReturnAnInstanceOf(NotificationCategory::class);
31
    }
32
33
    /** @test */
34
    public function it_try_to_find_a_non_existing_category(CategoryDB $categoryRepository)
35
    {
36
        $nameCategory = 'test.category';
37
38
        $categoryRepository->findByName($nameCategory)->shouldBeCalled()
39
            ->willReturn(null);
40
41
        $this->shouldThrow(CategoryNotFoundException::class)
42
             ->during('findByName', [$nameCategory]);
43
    }
44
45
    /** @test */
46 View Code Duplication
    public function it_store_a_category(CategoryDB $categoryRepository)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        $categoryName = 'hello';
49
        $categoryText = 'wow';
50
51
        $categoryRepository->add($categoryName, $categoryText)->shouldBeCalled()
52
                           ->willReturn(new NotificationCategory());
53
54
        $this->add($categoryName, $categoryText)->shouldReturnAnInstanceOf(NotificationCategory::class);
55
    }
56
57
    /** @test */
58
    public function it_delete_a_category_by_id(CategoryDB $categoryRepository)
59
    {
60
        $categoryId = 1;
61
62
        $categoryRepository->delete($categoryId);
63
64
        $categoryRepository->delete($categoryId)->shouldBeCalled()
65
                           ->willReturn(1);
66
67
        $this->delete($categoryId)->shouldReturn(1);
68
    }
69
70
    /** @test */
71
    public function it_delete_a_category_by_name(CategoryDB $categoryRepository)
72
    {
73
        $categoryName = 'testCategory';
74
75
        $categoryRepository->deleteByName($categoryName)->shouldBeCalled()
76
                           ->willReturn(1);
77
78
        $this->deleteByName($categoryName)->shouldReturn(1);
79
    }
80
}
81