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

DisablePromocodeTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A it_thows_exception_if_promocode_is_invalid() 0 6 1
A it_sets_expiration_date_if_code_was_valid() 0 10 1
A it_returns_true_if_disabled() 0 9 1
1
<?php
2
3
namespace Gabievi\Promocodes\Tests;
4
5
use Promocodes;
6
use Gabievi\Promocodes\Models\Promocode;
7
use Gabievi\Promocodes\Exceptions\InvalidPromocodeException;
8
9
class DisablePromocodeTest extends TestCase
10
{
11
    /** @test */
12
    public function it_thows_exception_if_promocode_is_invalid()
13
    {
14
        $this->expectException(InvalidPromocodeException::class);
15
16
        Promocodes::disable('INVALID-CODE');
17
    }
18
19
    /** @test */
20
    public function it_sets_expiration_date_if_code_was_valid()
21
    {
22
        $promocodes = Promocodes::create();
23
        $promocode = $promocodes->first();
24
25
        Promocodes::disable($promocode['code']);
26
        $dbPromocode = Promocode::byCode($promocode['code'])->first();
27
28
        $this->assertNotNull($dbPromocode->expires_at);
29
    }
30
31
    /** @test */
32
    public function it_returns_true_if_disabled()
33
    {
34
        $promocodes = Promocodes::create();
35
        $promocode = $promocodes->first();
36
37
        $disabledPromocode = Promocodes::disable($promocode['code']);
38
39
        $this->assertTrue($disabledPromocode);
40
    }
41
}
42