Completed
Push — issue-118 ( aecd99...68e7b7 )
by
unknown
02:26
created

it_create_empty_array_loop_builder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 8
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace spec\Fenos\Notifynder\Builder;
4
5
use Carbon\Carbon;
6
use Fenos\Notifynder\Builder\NotifynderBuilder;
7
use Fenos\Notifynder\Categories\CategoryManager;
8
use Fenos\Notifynder\Models\NotificationCategory;
9
use Illuminate\Support\Collection;
10
use PhpSpec\ObjectBehavior;
11
use Prophecy\Argument;
12
13
class NotifynderBuilderSpec extends ObjectBehavior
14
{
15
    public function let(CategoryManager $category)
16
    {
17
        $this->beConstructedWith($category);
18
    }
19
20
    function it_is_initializable()
21
    {
22
        $this->shouldHaveType('Fenos\Notifynder\Builder\NotifynderBuilder');
23
    }
24
25
    /** @test */
26
    function it_set_the_FROM_value_with_a_single_entity()
27
    {
28
        $user_id = 1;
29
30
        $this->from($user_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class);
31
    }
32
33
    /** @test */
34
    function it_set_the_FROM_value_giving_a_polymorphic_entity()
35
    {
36
        $user_id = 1;
37
        $user_class = 'User';
38
39
        $this->from($user_class,$user_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class);
40
    }
41
42
    /** @test */
43
    function it_set_the_FROM_value_giving_a_polymorphic_entity_the_first_value_must_be_the_class_entity()
44
    {
45
        $user_id = 1;
46
        $user_class = 'User';
47
48
        $this->shouldThrow('InvalidArgumentException')->during('from',[$user_id,$user_class]);
49
    }
50
51
    /** @test */
52
    function it_set_the_TO_value_with_a_single_entity()
53
    {
54
        $user_id = 1;
55
56
        $this->to($user_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class);
57
    }
58
59
    /** @test */
60
    function it_set_the_TO_value_giving_a_polymorphic_entity()
61
    {
62
        $user_id = 1;
63
        $user_class = 'User';
64
65
        $this->to($user_class,$user_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class);
66
    }
67
68
    /** @test */
69
    function it_set_the_TO_value_giving_a_polymorphic_entity_the_first_value_must_be_the_class_entity()
70
    {
71
        $user_id = 1;
72
        $user_class = 'User';
73
74
        $this->shouldThrow('InvalidArgumentException')->during('to',[$user_id,$user_class]);
75
    }
76
77
    /** @test */
78
    function it_add_the_url_parameter_to_the_builder()
79
    {
80
        $url = 'www.notifynder.io';
81
82
        $this->url($url)->shouldReturnAnInstanceOf(NotifynderBuilder::class);
83
    }
84
85
    /** @test */
86
    function it_allow_only_string_as_url()
87
    {
88
        $url = 1;
89
90
        $this->shouldThrow('InvalidArgumentException')->during('url',[$url]);
91
    }
92
93
    /** @test */
94
    function it_add_the_expire_parameter_to_the_builder()
95
    {
96
        date_default_timezone_set('UTC');
97
98
        $datetime = new Carbon;
99
100
        $this->expire($datetime)->shouldReturnAnInstanceOf(NotifynderBuilder::class);
101
    }
102
103
    /** @test */
104
    function it_allow_only_carbon_instance_as_expire_time()
105
    {
106
        $datetime = 1;
107
108
        $this->shouldThrow('InvalidArgumentException')->during('expire',[$datetime]);
109
    }
110
111
112
    /** @test */
113
    function it_add_a_category_id_to_the_builder()
114
    {
115
        $category_id = 1;
116
117
        $this->category($category_id)->shouldReturnAnInstanceOf(NotifynderBuilder::class);
118
    }
119
120
    /** @test */
121 View Code Duplication
    function it_add_a_category_id_to_the_builder_givin_the_name_of_it(CategoryManager $category, NotificationCategory $categoryModel)
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...
122
    {
123
        $name = 'category.name';
124
        $category_id = 1;
125
126
        $category->findByName($name)->shouldBeCalled()
127
                 ->willReturn($categoryModel);
128
129
        $categoryModel->getAttribute('id')->willReturn($category_id);
130
131
        $this->category($name)->shouldReturnAnInstanceOf(NotifynderBuilder::class);
132
    }
133
134
    /** @test */
135
    function it_add_the_extra_parameter_to_the_builder()
136
    {
137
        $extra = ['my'  => 'extra'];
138
139
        $this->extra($extra)->shouldReturnAnInstanceOf(NotifynderBuilder::class);
140
    }
141
142
    /** @test */
143
    function it_allow_only_associative_array_as_extra_parameter_they_llbe_converted_in_jon()
144
    {
145
        $extra = ['my'];
146
147
        $this->shouldThrow('InvalidArgumentException')->during('extra',[$extra]);
148
    }
149
150
    /** @test */
151
    function it_create_a_builder_array_using_a_raw_closure()
152
    {
153
        date_default_timezone_set('UTC');
154
155
        $closure = function(NotifynderBuilder $builder)
156
        {
157
            return $builder->to(1)->from(2)->url('notifynder.io')->category(1);
158
        };
159
160
        $this->raw($closure)->shouldHaveKey('to_id');
161
        $this->raw($closure)->shouldHaveKey('from_id');
162
        $this->raw($closure)->shouldHaveKey('url');
163
        $this->raw($closure)->shouldHaveKey('category_id');
164
        $this->raw($closure)->shouldHaveKey('created_at');
165
        $this->raw($closure)->shouldHaveKey('updated_at');
166
    }
167
168
    public function it_create_multi_notification_in_a_loop()
169
    {
170
        $closure = function(NotifynderBuilder $builder,$data,$key)
0 ignored issues
show
Unused Code introduced by
$closure is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
171
        {
172
            return $builder->to(1)->from(2)->url('notifynder.io')->category(1);
173
        };
174
    }
175
176 View Code Duplication
    public function it_create_empty_array_loop_builder()
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...
177
    {
178
        $closure = function(NotifynderBuilder $builder,$data,$key)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
179
        {
180
            return $builder->to(1)->from(2)->url('notifynder.io')->category(1);
181
        };
182
        $this->shouldThrow('InvalidArgumentException')->during('loop', [[], $closure]);
183
    }
184
185 View Code Duplication
    public function it_create_empty_collection_loop_builder()
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...
186
    {
187
        $closure = function(NotifynderBuilder $builder,$data,$key)
0 ignored issues
show
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
188
        {
189
            return $builder->to(1)->from(2)->url('notifynder.io')->category(1);
190
        };
191
        $this->shouldThrow('InvalidArgumentException')->during('loop', [new Collection([]), $closure]);
192
    }
193
}
194