BulkLoader_ResultTest::testGetErrors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ilateral\SilverStripe\SlightlyBetterBulkLoader\Tests;
4
5
use SilverStripe\Dev\SapphireTest;
6
use ilateral\SilverStripe\SlightlyBetterBulkLoader\BulkLoader_Result;
7
use ilateral\SilverStripe\SlightlyBetterBulkLoader\Tests\Data\Player;
8
9
class BulkLoader_ResultTest extends SapphireTest
10
{
11
    protected static $extra_dataobjects = [
12
        Player::class
13
    ];
14
15
    public function testResultErrors()
16
    {
17
        $results = BulkLoader_Result::create();
18
        $results->addError("Error With Record", 1);
19
        $this->assertEquals($results->ErrorCount(), 1);
20
        $this->assertSame(
21
            "Error With Record",
22
            $results->getErrors()[0],
23
            'The record 1 should be marked as error'
24
        );
25
    }
26
27
    public function testGetCreated()
28
    {
29
        $results = BulkLoader_Result::create();
30
31
        $player = Player::create(['FirstName' => 'Rangi', 'Status' => 'Possible']);
32
        $player->write();
33
        $results->addCreated($player, 'Speedster');
34
35
        $this->assertCount(1, $results->getCreated());
36
    }
37
38 View Code Duplication
    public function testGetUpdated()
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
        $results = BulkLoader_Result::create();
41
42
        Player::create(
43
            [
44
                'FirstName' => 'Vincent',
45
                'Status' => 'Available'
46
            ]
47
        )->write();
48
49
        $player = Player::get()->find('FirstName', 'Vincent');
50
        $player->Status = 'Unavailable';
51
        $player->write();
52
        $results->addUpdated($player, 'Injured');
53
54
        $this->assertCount(1, $results->getUpdated());
55
    }
56
57 View Code Duplication
    public function testGetDeleted()
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...
58
    {
59
        $results = BulkLoader_Result::create();
60
61
        Player::create(
62
            [
63
                'FirstName' => 'Vincent',
64
                'Status' => 'Available'
65
            ]
66
        )->write();
67
68
        $player = Player::get()->find('FirstName', 'Vincent');
69
        $results->addDeleted($player, 'Retired');
70
        $player->delete();
71
72
        $this->assertCount(1, $results->getDeleted());
73
    }
74
75
    public function testGetErrors()
76
    {
77
        $results = BulkLoader_Result::create();
78
        $results->addError("Error With Record", 1);
79
80
        $this->assertCount(1, $results->getErrors());
81
    }
82
83
    public function testGetTotal()
84
    {
85
        $results = BulkLoader_Result::create();
86
87
        Player::create(
88
            [
89
                'FirstName' => 'Vincent',
90
                'Status' => 'Available'
91
            ]
92
        )->write();
93
94
        $player = Player::get()->find('FirstName', 'Vincent');
95
        $player->Status = 'Unavailable';
96
        $player->write();
97
        $results->addUpdated($player, 'Injured');
98
99
        $this->assertEquals($results->getTotal(), 1);
100
101
        $player = Player::create(['FirstName' => 'Rangi', 'Status' => 'Possible']);
102
        $player->write();
103
        $results->addCreated($player, 'Speedster');
104
105
        $this->assertEquals($results->getTotal(), 2);
106
107
        $player = Player::get()->find('FirstName', 'Vincent');
108
        $results->addDeleted($player, 'Retired');
109
        $player->delete();
110
111
        $this->assertEquals($results->getTotal(), 3);
112
113
        $results->addError("Error With Record", 1);
114
115
        $this->assertEquals($results->getTotal(), 4);
116
    }
117
}
118