Completed
Push — master ( 46cd44...2cb6dc )
by Zura
05:26 queued 03:17
created

PromocodesTest::it_will_apply_given_code()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Tests\Unit;
4
5
use Tests\TestCase;
6
use Gabievi\Promocodes\Facades\Promocodes;
7
use Illuminate\Foundation\Testing\DatabaseMigrations;
8
9
class PromocodesTest extends TestCase
10
{
11
    use DatabaseMigrations;
12
13
    /** @test */
14
    public function it_can_output_number_of_codes()
15
    {
16
        $codes = Promocodes::output(10);
17
18
        $this->assertCount(10, $codes);
19
    }
20
21
    /** @test */
22
    public function it_will_output_one_code_by_default() {
23
        $code = Promocodes::output();
24
25
        $this->assertCount(1, $code);
26
    }
27
28
    /** @test */
29
    public function it_will_create_number_of_codes_into_database_with_reward_value() {
30
        $code = Promocodes::create(5, 35.65)->first();
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...
31
32
        $this->assertDatabaseHas('promocodes', [
33
            'code' => $code['code'],
34
            'reward' => $code['reward'],
35
        ]);
36
    }
37
38
    /** @test */
39
    public function it_will_be_stored_with_additional_data() {
40
        $data = [
41
            'baz' => 'qux',            
42
            'foo' => 'bar',
43
        ];
44
45
        $code = Promocodes::create(1, 50, $data)->first();
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
47
        $this->assertDatabaseHas('promocodes', [
48
            'reward' => 50,
49
        ]);
50
51
        $this->assertEquals($code['data'], json_encode($data));
52
    }
53
54
    /** @test */
55
    public function it_returns_true_if_code_exists_in_database() {
56
        $code = Promocodes::create(1, 80)->first();
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...
57
        $status = Promocodes::check($code['code']);
58
59
        $this->assertTrue($status);
60
    }
61
62
    /** @test */
63
    public function it_will_apply_given_code() {
64
        $code = Promocodes::create(20, 15)->first();
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...
65
66
        $status = Promocodes::apply($code['code']);
67
68
        $this->assertEquals(15, $status->reward);
69
    }
70
71
    /** @test */
72
    public function it_will_apply_given_code_with_some_additional_data() {
73
        $data = [
74
            'baz' => 'qux',            
75
            'foo' => 'bar',
76
        ];
77
        
78
        $code = Promocodes::create(20, 15, $data)->first();
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...
79
80
        $status = Promocodes::apply($code['code']);
81
82
        $this->assertEquals('qux', $status->data['baz']);
83
    }
84
}
85