Completed
Push — master ( 9c2e57...960d6d )
by Zura
03:25
created

it_can_set_additional_data_to_promocodes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 17
rs 9.7
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Gabievi\Promocodes\Tests;
4
5
use Promocodes;
6
7
class CreatePromocodesToDatabaseTest extends TestCase
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', [
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', [
30
            'code' => $firstPromocode['code']
31
        ]);
32
        $this->assertDatabaseHas('promocodes', [
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->assertEquals(10, $promocode['reward']);
45
        $this->assertDatabaseHas('promocodes', [
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', [
64
            'code' => $promocode['code'],
65
            'data' => json_encode($data),
66
        ]);
67
        $this->assertEquals('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', [
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', [
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', [
106
            'code' => $promocode['code'],
107
            'is_disposable' => true,
108
        ]);
109
    }
110
}
111