Passed
Push — master ( 63a673...8e8232 )
by Jean Paul
01:25
created

RowTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 37
c 3
b 0
f 0
dl 0
loc 92
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testOffsetGetAndSetWithArrayNotation() 0 11 1
A testOffsetUnset() 0 10 1
A testGetAndSetWithObjectNotation() 0 11 1
A testOffsetExistsViaIsSet() 0 6 1
A testGetAndSetAttribute() 0 11 1
A testRemoveAttribute() 0 10 1
A testOffsetExistsViaEmpty() 0 6 1
A testGetAndSetAttributes() 0 11 1
1
<?php declare( strict_types = 1 );
2
3
namespace Coco\SourceWatcher\Tests\Core;
4
5
use Coco\SourceWatcher\Core\Row;
6
use PHPUnit\Framework\TestCase;
7
8
class RowTest extends TestCase
9
{
10
    public function testGetAndSetAttributes () : void
11
    {
12
        $givenAttributes = [ "id", "name" ];
13
14
        $row = new Row( [] );
15
        $row->setAttributes( $givenAttributes );
16
17
        $expectedAttributes = [ "id", "name" ];
18
        $actualAttributes = $row->getAttributes();
19
20
        $this->assertEquals( $expectedAttributes, $actualAttributes );
21
    }
22
23
    public function testOffsetExistsViaEmpty () : void
24
    {
25
        $row = new Row( [ "name" => "Jane Doe" ] );
26
27
        // test the offsetExists method
28
        $this->assertTrue( empty( $row["id"] ) );
29
    }
30
31
    public function testOffsetExistsViaIsSet () : void
32
    {
33
        $row = new Row( [ "name" => "Jane Doe" ] );
34
35
        // test the offsetExists method
36
        $this->assertNotTrue( isset( $row["id"] ) );
37
    }
38
39
    public function testOffsetGetAndSetWithArrayNotation () : void
40
    {
41
        $givenName = "Jane Doe";
42
43
        $row = new Row( [ "id" => 1 ] );
44
        $row["name"] = $givenName;  // test the offsetSet method
45
46
        $expectedName = "Jane Doe";
47
        $actualName = $row["name"]; // test the offsetGet method
48
49
        $this->assertEquals( $expectedName, $actualName );
50
    }
51
52
    public function testOffsetUnset () : void
53
    {
54
        $row = new Row( [ "id" => 1, "name" => "Jane Doe" ] );
55
56
        // test the offsetUnset method
57
        unset( $row["id"] );
58
59
        $expectedRow = new Row( [ "name" => "Jane Doe" ] );
60
61
        $this->assertEquals( $expectedRow, $row );
62
    }
63
64
    public function testGetAndSetAttribute () : void
65
    {
66
        $givenName = "Jane Doe";
67
68
        $row = new Row( [ "id" => 1 ] );
69
        $row->set( "name", $givenName );    // test the set method
70
71
        $expectedName = "Jane Doe";
72
        $actualName = $row->get( "name" );  // test the get method
73
74
        $this->assertEquals( $expectedName, $actualName );
75
    }
76
77
    public function testRemoveAttribute () : void
78
    {
79
        $row = new Row( [ "id" => 1, "name" => "Jane Doe" ] );
80
81
        // test the remove method
82
        $row->remove( "id" );
83
84
        $expectedRow = new Row( [ "name" => "Jane Doe" ] );
85
86
        $this->assertEquals( $expectedRow, $row );
87
    }
88
89
    public function testGetAndSetWithObjectNotation () : void
90
    {
91
        $givenName = "Jane Doe";
92
93
        $row = new Row( [ "id" => 1 ] );
94
        $row->name = $givenName;    // test the __set method
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Coco\SourceWatcher\Core\Row. Since you implemented __set, consider adding a @property annotation.
Loading history...
95
96
        $expectedName = "Jane Doe";
97
        $actualName = $row->name;   // test the __get method
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Coco\SourceWatcher\Core\Row. Since you implemented __get, consider adding a @property annotation.
Loading history...
98
99
        $this->assertEquals( $expectedName, $actualName );
100
    }
101
}
102