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 testOffsetExistsViaEmpty () : void |
11
|
|
|
{ |
12
|
|
|
$row = new Row( [ "name" => "Jane Doe" ] ); |
13
|
|
|
|
14
|
|
|
// test the offsetExists method |
15
|
|
|
$this->assertTrue( empty( $row["id"] ) ); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testOffsetExistsViaIsSet () : void |
19
|
|
|
{ |
20
|
|
|
$row = new Row( [ "name" => "Jane Doe" ] ); |
21
|
|
|
|
22
|
|
|
// test the offsetExists method |
23
|
|
|
$this->assertNotTrue( isset( $row["id"] ) ); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testOffsetGetAndSetWithArrayNotation () : void |
27
|
|
|
{ |
28
|
|
|
$givenName = "Jane Doe"; |
29
|
|
|
|
30
|
|
|
$row = new Row( [ "id" => 1 ] ); |
31
|
|
|
$row["name"] = $givenName; // test the offsetSet method |
32
|
|
|
|
33
|
|
|
$expectedName = "Jane Doe"; |
34
|
|
|
$actualName = $row["name"]; // test the offsetGet method |
35
|
|
|
|
36
|
|
|
$this->assertEquals( $expectedName, $actualName ); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testOffsetUnset () : void |
40
|
|
|
{ |
41
|
|
|
$row = new Row( [ "id" => 1, "name" => "Jane Doe" ] ); |
42
|
|
|
|
43
|
|
|
// test the offsetUnset method |
44
|
|
|
unset( $row["id"] ); |
45
|
|
|
|
46
|
|
|
$expectedRow = new Row( [ "name" => "Jane Doe" ] ); |
47
|
|
|
|
48
|
|
|
$this->assertEquals( $expectedRow, $row ); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testGetAndSetAttribute () : void |
52
|
|
|
{ |
53
|
|
|
$givenName = "Jane Doe"; |
54
|
|
|
|
55
|
|
|
$row = new Row( [ "id" => 1 ] ); |
56
|
|
|
$row->set( "name", $givenName ); // test the set method |
57
|
|
|
|
58
|
|
|
$expectedName = "Jane Doe"; |
59
|
|
|
$actualName = $row->get( "name" ); // test the get method |
60
|
|
|
|
61
|
|
|
$this->assertEquals( $expectedName, $actualName ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testRemoveAttribute () : void |
65
|
|
|
{ |
66
|
|
|
$row = new Row( [ "id" => 1, "name" => "Jane Doe" ] ); |
67
|
|
|
|
68
|
|
|
// test the remove method |
69
|
|
|
$row->remove( "id" ); |
70
|
|
|
|
71
|
|
|
$expectedRow = new Row( [ "name" => "Jane Doe" ] ); |
72
|
|
|
|
73
|
|
|
$this->assertEquals( $expectedRow, $row ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testGetAndSetWithObjectNotation () : void |
77
|
|
|
{ |
78
|
|
|
$givenName = "Jane Doe"; |
79
|
|
|
|
80
|
|
|
$row = new Row( [ "id" => 1 ] ); |
81
|
|
|
$row->name = $givenName; // test the __set method |
|
|
|
|
82
|
|
|
|
83
|
|
|
$expectedName = "Jane Doe"; |
84
|
|
|
$actualName = $row->name; // test the __get method |
|
|
|
|
85
|
|
|
|
86
|
|
|
$this->assertEquals( $expectedName, $actualName ); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|