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

it_has_alias_named_reedem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 14
loc 14
rs 9.7998
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Gabievi\Promocodes\Tests;
4
5
use Gabievi\Promocodes\Models\Promocode;
6
use Gabievi\Promocodes\Tests\Models\User;
7
use Gabievi\Promocodes\Facades\Promocodes;
8
use Gabievi\Promocodes\Exceptions\AlreadyUsedException;
9
use Gabievi\Promocodes\Exceptions\UnauthenticatedException;
10
11
class ApplyPromocodeToUserTest extends TestCase
12
{
13
    /** @test */
14
    public function it_throws_exception_if_user_is_not_authenticated()
15
    {
16
        $this->expectException(UnauthenticatedException::class);
17
18
        $promocodes = Promocodes::create();
0 ignored issues
show
Bug introduced by
The method create() does not exist on Gabievi\Promocodes\Facades\Promocodes. Did you maybe mean createFreshMockInstance()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
19
        $promocode = $promocodes->first();
20
21
        $this->assertCount(1, $promocodes);
22
23
        Promocodes::apply($promocode['code']);
24
    }
25
26
    /** @test */
27
    public function it_returns_false_if_promocode_doesnt_exist()
28
    {
29
        $user = User::find(1);
30
        $this->actingAs($user);
31
32
        $appliedPromocode = Promocodes::apply('INVALID-CODE');
33
34
        $this->assertFalse($appliedPromocode);
35
    }
36
37
    /** @test */
38 View Code Duplication
    public function it_throws_exception_if_user_tries_to_apply_code_twice()
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
        $this->expectException(AlreadyUsedException::class);
41
42
        $user = User::find(1);
43
        $this->actingAs($user);
44
45
        $promocodes = Promocodes::create();
0 ignored issues
show
Bug introduced by
The method create() does not exist on Gabievi\Promocodes\Facades\Promocodes. Did you maybe mean createFreshMockInstance()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
46
        $promocode = $promocodes->first();
47
48
        $this->assertCount(1, $promocodes);
49
50
        Promocodes::apply($promocode['code']);
51
        Promocodes::apply($promocode['code']);
52
    }
53
54
    /** @test */
55
    public function it_attaches_authenticated_user_as_applied_to_promocode()
56
    {
57
        $user = User::find(1);
58
        $this->actingAs($user);
59
60
        $promocodes = Promocodes::create();
0 ignored issues
show
Bug introduced by
The method create() does not exist on Gabievi\Promocodes\Facades\Promocodes. Did you maybe mean createFreshMockInstance()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
61
        $promocode = $promocodes->first();
62
63
        $this->assertCount(1, $promocodes);
64
65
        Promocodes::apply($promocode['code']);
66
67
        $this->assertCount(1, $user->promocodes);
68
69
        $userPromocode = $user->promocodes()->first();
70
71
        $this->assertNotNull($userPromocode->pivot->used_at);
72
    }
73
74
    /** @test */
75 View Code Duplication
    public function is_returns_promocode_with_user_if_applied_successfuly()
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...
76
    {
77
        $user = User::find(1);
78
        $this->actingAs($user);
79
80
        $promocodes = Promocodes::create();
0 ignored issues
show
Bug introduced by
The method create() does not exist on Gabievi\Promocodes\Facades\Promocodes. Did you maybe mean createFreshMockInstance()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
81
        $promocode = $promocodes->first();
82
83
        $this->assertCount(1, $promocodes);
84
85
        $appliedPromocode = Promocodes::apply($promocode['code']);
86
87
        $this->assertTrue($appliedPromocode instanceof Promocode);
88
89
        $this->assertCount(1, $appliedPromocode->users);
90
    }
91
92
    /** @test */
93 View Code Duplication
    public function it_has_alias_named_reedem()
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...
94
    {
95
        $user = User::find(1);
96
        $this->actingAs($user);
97
98
        $promocodes = Promocodes::create();
0 ignored issues
show
Bug introduced by
The method create() does not exist on Gabievi\Promocodes\Facades\Promocodes. Did you maybe mean createFreshMockInstance()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
99
        $promocode = $promocodes->first();
100
101
        $this->assertCount(1, $promocodes);
102
103
        Promocodes::redeem($promocode['code']);
104
105
        $this->assertCount(1, $user->promocodes);
106
    }
107
}
108