Completed
Push — master ( e7b516...6a1685 )
by Zura
10:42
created

ClearRedundantPromocodesTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A it_returns_null_if_there_is_no_redundant_promocodes() 0 7 1
A it_removes_expired_or_used_promocodes_and_relations() 0 17 1
1
<?php
2
3
namespace Gabievi\Promocodes\Test;
4
5
use Promocodes;
6
use Gabievi\Promocodes\Models\Promocode;
7
use Gabievi\Promocodes\Test\Models\User;
8
9
class ClearRedundantPromocodesTest extends TestCase
10
{
11
    /** @test */
12
    public function it_returns_null_if_there_is_no_redundant_promocodes()
13
    {
14
        $promocodes = Promocodes::create(3);
15
16
        $this->assertCount(3, $promocodes);
17
        $this->assertNull(Promocodes::clearRedundant());
18
    }
19
20
    /** @test */
21
    public function it_removes_expired_or_used_promocodes_and_relations()
22
    {
23
        $user = User::find(1);
24
        $this->actingAs($user);
25
26
        $disposablePromocodes = Promocodes::createDisposable(2);
27
        $multiusePromocodes = Promocodes::create(2);
28
29
        $this->assertCount(4, Promocode::all());
30
31
        Promocodes::redeem($disposablePromocodes->first()['code']);
32
        Promocodes::disable($multiusePromocodes->first()['code']);
33
34
        Promocodes::clearRedundant();
35
36
        $this->assertCount(2, Promocode::all());
37
    }
38
}
39