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

CategoryManagerSpec   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 14.08 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 7
c 1
b 1
f 0
lcom 0
cbo 4
dl 10
loc 71
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A let() 0 4 1
A it_find_a_category_by_name() 0 9 1
A it_try_to_find_a_non_existing_category() 0 10 1
A it_delete_a_category_by_id() 0 11 1
A it_delete_a_category_by_name() 0 9 1
A it_store_a_category() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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