Completed
Push — master ( 33496d...9e3f76 )
by Daniel
12:54
created

BulkLoaderResultTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 81
rs 10
c 1
b 0
f 0
wmc 4
lcom 1
cbo 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
B testBulkLoaderResultCreated() 0 24 1
A testBulkLoaderResultDeleted() 0 19 1
B testBulkLoaderResultUpdated() 0 25 1
1
<?php
2
/**
3
 * @package framework
4
 * @subpackage tests
5
 */
6
class BulkLoaderResultTest extends SapphireTest
7
{
8
    protected $extraDataObjects = array('BulkLoaderTestPlayer');
9
10
    public function setUp()
11
    {
12
        parent::setUp();
13
        BulkLoaderTestPlayer::create(array('Name' => 'Vincent', 'Status' => 'Available'))->write();
14
    }
15
16
    public function testBulkLoaderResultCreated()
17
    {
18
        $results = BulkLoader_Result::create();
19
        $player = BulkLoaderTestPlayer::create(array('Name' => 'Rangi', 'Status' => 'Possible'));
20
        $player->write();
21
        $results->addCreated($player, 'Speedster');
22
23
        $this->assertEquals($results->CreatedCount(), 1);
24
        $this->assertSame(
25
            'Rangi',
26
            $results->Created()->find('Name', 'Rangi')->Name,
27
            'The player Rangi should be recorded as created in $results'
28
        );
29
        $this->assertSame(
30
            'Possible',
31
            $results->Created()->find('Name', 'Rangi')->Status,
32
            'The player Rangi should have Status of "Possible" in $results'
33
        );
34
        $this->assertSame(
35
            'Speedster',
36
            $results->Created()->find('Name', 'Rangi')->_BulkLoaderMessage,
37
            'Rangi should have _BulkLoaderMessage of Speedster'
38
        );
39
    }
40
41
    public function testBulkLoaderResultDeleted()
42
    {
43
        $results = BulkLoader_Result::create();
44
        $player = BulkLoaderTestPlayer::get()->find('Name', 'Vincent');
45
        $results->addDeleted($player, 'Retired');
46
        $player->delete();
47
48
        $this->assertEquals($results->DeletedCount(), 1);
49
        $this->assertSame(
50
            'Vincent',
51
            $results->Deleted()->find('Name', 'Vincent')->Name,
52
            'The player Vincent should be recorded as deleted'
53
        );
54
        $this->assertSame(
55
            'Retired',
56
            $results->Deleted()->find('Name', 'Vincent')->_BulkLoaderMessage,
57
            'Vincent should have a _BulkLoaderMessage of Retired'
58
        );
59
    }
60
61
    public function testBulkLoaderResultUpdated()
62
    {
63
        $results = BulkLoader_Result::create();
64
        $player = BulkLoaderTestPlayer::get()->find('Name', 'Vincent');
65
        $player->Status = 'Unavailable';
0 ignored issues
show
Documentation introduced by
The property Status does not exist on object<DataObject>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
66
        $player->write();
67
        $results->addUpdated($player, 'Injured');
68
69
        $this->assertEquals($results->UpdatedCount(), 1);
70
        $this->assertSame(
71
            'Vincent',
72
            $results->Updated()->find('Name', 'Vincent')->Name,
73
            'The player Vincent should be recorded as updated'
74
        );
75
        $this->assertSame(
76
            'Unavailable',
77
            $results->Updated()->find('Name', 'Vincent')->Status,
78
            'The player Vincent should have a Status of Unavailable'
79
        );
80
        $this->assertSame(
81
            'Injured',
82
            $results->Updated()->find('Name', 'Vincent')->_BulkLoaderMessage,
83
            'Vincent is injured'
84
        );
85
    }
86
}
87
88
class BulkLoaderTestPlayer extends DataObject implements TestOnly
89
{
90
    private static $db = array(
91
        'Name' => 'Varchar',
92
        'Status' => 'Varchar',
93
    );
94
}
95