|
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 |
|
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
$expectedName = "Jane Doe"; |
|
97
|
|
|
$actualName = $row->name; // test the __get method |
|
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
$this->assertEquals( $expectedName, $actualName ); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|