CreatePromocodesToDatabaseTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 117
Duplicated Lines 49.57 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 58
loc 117
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A it_will_create_only_one_code_without_parameters() 10 10 1
A it_can_create_several_promocodes_and_save_in_database() 14 14 1
A it_can_set_reward_value_to_promocodes() 12 12 1
A it_can_set_additional_data_to_promocodes() 0 17 1
A it_can_set_days_to_expire_promocode() 0 13 1
A it_will_create_multiuse_promocode_by_deafult() 11 11 1
A it_can_create_disposable_promocode() 11 11 1
A it_can_output_all_valid_promocodes() 0 11 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 Gabievi\Promocodes\Tests;
4
5
use Promocodes;
6
7
class CreatePromocodesToDatabaseTest extends TestCase
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
8
{
9
    /** @test */
10 View Code Duplication
    public function it_will_create_only_one_code_without_parameters()
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...
11
    {
12
        $promocodes = Promocodes::create();
13
        $promocode = $promocodes->first();
14
15
        $this->assertCount(1, $promocodes);
16
        $this->assertDatabaseHas('promocodes', [
0 ignored issues
show
Bug introduced by
The method assertDatabaseHas() does not seem to exist on object<Gabievi\Promocode...omocodesToDatabaseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
17
            'code' => $promocode['code']
18
        ]);
19
    }
20
21
    /** @test */
22 View Code Duplication
    public function it_can_create_several_promocodes_and_save_in_database()
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...
23
    {
24
        $promocodes = Promocodes::create(10);
25
        $firstPromocode = $promocodes->first();
26
        $lastPromocode = $promocodes->last();
27
28
        $this->assertCount(10, $promocodes);
29
        $this->assertDatabaseHas('promocodes', [
0 ignored issues
show
Bug introduced by
The method assertDatabaseHas() does not seem to exist on object<Gabievi\Promocode...omocodesToDatabaseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
            'code' => $firstPromocode['code']
31
        ]);
32
        $this->assertDatabaseHas('promocodes', [
0 ignored issues
show
Bug introduced by
The method assertDatabaseHas() does not seem to exist on object<Gabievi\Promocode...omocodesToDatabaseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
            'code' => $lastPromocode['code']
34
        ]);
35
    }
36
37
    /** @test */
38 View Code Duplication
    public function it_can_set_reward_value_to_promocodes()
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...
39
    {
40
        $promocodes = Promocodes::create(1, 10);
41
        $promocode = $promocodes->first();
42
43
        $this->assertCount(1, $promocodes);
44
        $this->assertSame(10, $promocode['reward']);
45
        $this->assertDatabaseHas('promocodes', [
0 ignored issues
show
Bug introduced by
The method assertDatabaseHas() does not seem to exist on object<Gabievi\Promocode...omocodesToDatabaseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
46
            'code' => $promocode['code'],
47
            'reward' => $promocode['reward']
48
        ]);
49
    }
50
51
    /** @test */
52
    public function it_can_set_additional_data_to_promocodes()
53
    {
54
        $data = [
55
            'foo' => 'bar',
56
            'baz' => 'qux',
57
        ];
58
59
        $promocodes = Promocodes::create(1, null, $data);
60
        $promocode = $promocodes->first();
61
62
        $this->assertCount(1, $promocodes);
63
        $this->assertDatabaseHas('promocodes', [
0 ignored issues
show
Bug introduced by
The method assertDatabaseHas() does not seem to exist on object<Gabievi\Promocode...omocodesToDatabaseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
            'code' => $promocode['code'],
65
            'data' => json_encode($data),
66
        ]);
67
        $this->assertSame('bar', $promocode['data']['foo']);
68
    }
69
70
    /** @test */
71
    public function it_can_set_days_to_expire_promocode()
72
    {
73
        $promocodes = Promocodes::create(1, null, [], 5);
74
        $promocode = $promocodes->first();
75
76
        $expires_at = date('Y-m-d H:i:s', strtotime('+5 days'));
77
78
        $this->assertCount(1, $promocodes);
79
        $this->assertDatabaseHas('promocodes', [
0 ignored issues
show
Bug introduced by
The method assertDatabaseHas() does not seem to exist on object<Gabievi\Promocode...omocodesToDatabaseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
            'code' => $promocode['code'],
81
            'expires_at' => $expires_at,
82
        ]);
83
    }
84
85
    /** @test */
86 View Code Duplication
    public function it_will_create_multiuse_promocode_by_deafult()
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...
87
    {
88
        $promocodes = Promocodes::create();
89
        $promocode = $promocodes->first();
90
91
        $this->assertCount(1, $promocodes);
92
        $this->assertDatabaseHas('promocodes', [
0 ignored issues
show
Bug introduced by
The method assertDatabaseHas() does not seem to exist on object<Gabievi\Promocode...omocodesToDatabaseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
93
            'code' => $promocode['code'],
94
            'is_disposable' => false,
95
        ]);
96
    }
97
98
    /** @test */
99 View Code Duplication
    public function it_can_create_disposable_promocode()
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...
100
    {
101
        $promocodes = Promocodes::createDisposable();
102
        $promocode = $promocodes->first();
103
104
        $this->assertCount(1, $promocodes);
105
        $this->assertDatabaseHas('promocodes', [
0 ignored issues
show
Bug introduced by
The method assertDatabaseHas() does not seem to exist on object<Gabievi\Promocode...omocodesToDatabaseTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
106
            'code' => $promocode['code'],
107
            'is_disposable' => true,
108
        ]);
109
    }
110
111
    /** @test */
112
    public function it_can_output_all_valid_promocodes()
113
    {
114
        $promocodes = Promocodes::create(5);
115
        $promocode = $promocodes->first();
116
117
        $this->assertCount(5, Promocodes::all());
118
119
        Promocodes::disable($promocode['code']);
120
121
        $this->assertCount(4, Promocodes::all());
122
    }
123
}
124