RowTest::testOffsetExistsViaIsSet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
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
/**
9
 * Class RowTest
10
 *
11
 * @package Coco\SourceWatcher\Tests\Core
12
 */
13
class RowTest extends TestCase
14
{
15
    private string $janeDoe;
16
17
    public function setUp () : void
18
    {
19
        $this->janeDoe = "Jane Doe";
20
    }
21
22
    public function testGetAndSetAttributes () : void
23
    {
24
        $givenAttributes = [ "id", "name" ];
25
26
        $row = new Row( [] );
27
        $row->setAttributes( $givenAttributes );
28
29
        $expectedAttributes = [ "id", "name" ];
30
        $actualAttributes = $row->getAttributes();
31
32
        $this->assertEquals( $expectedAttributes, $actualAttributes );
33
    }
34
35
    public function testOffsetExistsViaEmpty () : void
36
    {
37
        $row = new Row( [ "name" => $this->janeDoe ] );
38
39
        // test the offsetExists method
40
        $this->assertTrue( empty( $row["id"] ) );
41
    }
42
43
    public function testOffsetExistsViaIsSet () : void
44
    {
45
        $row = new Row( [ "name" => $this->janeDoe ] );
46
47
        // test the offsetExists method
48
        $this->assertNotTrue( isset( $row["id"] ) );
49
    }
50
51
    public function testOffsetGetAndSetWithArrayNotation () : void
52
    {
53
        $givenName = $this->janeDoe;
54
55
        $row = new Row( [ "id" => 1 ] );
56
        $row["name"] = $givenName;  // test the offsetSet method
57
58
        $expectedName = $this->janeDoe;
59
        $actualName = $row["name"]; // test the offsetGet method
60
61
        $this->assertEquals( $expectedName, $actualName );
62
    }
63
64
    public function testOffsetUnset () : void
65
    {
66
        $row = new Row( [ "id" => 1, "name" => $this->janeDoe ] );
67
68
        // test the offsetUnset method
69
        unset( $row["id"] );
70
71
        $expectedRow = new Row( [ "name" => $this->janeDoe ] );
72
73
        $this->assertEquals( $expectedRow, $row );
74
    }
75
76
    public function testGetAndSetAttribute () : void
77
    {
78
        $givenName = $this->janeDoe;
79
80
        $row = new Row( [ "id" => 1 ] );
81
        $row->set( "name", $givenName );    // test the set method
82
83
        $expectedName = $this->janeDoe;
84
        $actualName = $row->get( "name" );  // test the get method
85
86
        $this->assertEquals( $expectedName, $actualName );
87
    }
88
89
    public function testRemoveAttribute () : void
90
    {
91
        $row = new Row( [ "id" => 1, "name" => $this->janeDoe ] );
92
93
        // test the remove method
94
        $row->remove( "id" );
95
96
        $expectedRow = new Row( [ "name" => $this->janeDoe ] );
97
98
        $this->assertEquals( $expectedRow, $row );
99
    }
100
101
    public function testGetAndSetWithObjectNotation () : void
102
    {
103
        $givenName = $this->janeDoe;
104
105
        $row = new Row( [ "id" => 1 ] );
106
        $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...
107
108
        $expectedName = $this->janeDoe;
109
        $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...
110
111
        $this->assertEquals( $expectedName, $actualName );
112
    }
113
}
114