1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jasny; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Test object functions |
9
|
|
|
* @coversNothing |
10
|
|
|
*/ |
11
|
|
|
class ObjectFunctionsTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
protected $object; |
14
|
|
|
|
15
|
|
|
public function setUp() |
16
|
|
|
{ |
17
|
|
|
$this->object = new class() { |
18
|
|
|
public $foo = 'woo'; |
19
|
|
|
public $bar = 'BAR'; |
20
|
|
|
protected $qux = 'qqq'; |
21
|
|
|
private $tol = 'lot'; |
22
|
|
|
|
23
|
|
|
public function getProperties($dynamic = false) |
24
|
|
|
{ |
25
|
|
|
return \Jasny\object_get_properties($this, $dynamic); |
26
|
|
|
} |
27
|
|
|
}; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @covers Jasny\object_get_properties |
32
|
|
|
*/ |
33
|
|
|
public function testObjectGetProperties() |
34
|
|
|
{ |
35
|
|
|
$this->assertSame(['foo' => 'woo', 'bar' => 'BAR'], object_get_properties($this->object)); |
36
|
|
|
$this->assertSame(['foo' => 'woo', 'bar' => 'BAR'], $this->object->getProperties()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @covers Jasny\object_get_properties |
41
|
|
|
*/ |
42
|
|
|
public function testObjectGetPropertiesDynamic() |
43
|
|
|
{ |
44
|
|
|
$this->object->color = 'red'; |
45
|
|
|
|
46
|
|
|
$expected = ['foo' => 'woo', 'bar' => 'BAR', 'color' => 'red']; |
47
|
|
|
$this->assertSame($expected, object_get_properties($this->object, true)); |
48
|
|
|
$this->assertSame($expected, $this->object->getProperties(true)); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @covers Jasny\object_get_properties |
53
|
|
|
*/ |
54
|
|
|
public function testObjectGetPropertiesNotDynamic() |
55
|
|
|
{ |
56
|
|
|
$this->object->color = 'red'; |
57
|
|
|
|
58
|
|
|
$this->assertSame(['foo' => 'woo', 'bar' => 'BAR'], object_get_properties($this->object, false)); |
59
|
|
|
$this->assertSame(['foo' => 'woo', 'bar' => 'BAR'], $this->object->getProperties(false)); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @covers Jasny\object_set_properties |
65
|
|
|
*/ |
66
|
|
|
public function testObjectSetProperties() |
67
|
|
|
{ |
68
|
|
|
object_set_properties($this->object, ['foo' => 'cool', 'bar' => 'land']); |
69
|
|
|
|
70
|
|
|
$this->assertAttributeSame('cool', 'foo', $this->object); |
|
|
|
|
71
|
|
|
$this->assertAttributeSame('land', 'bar', $this->object); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @covers Jasny\object_set_properties |
76
|
|
|
*/ |
77
|
|
|
public function testObjectSetPropertiesDynamic() |
78
|
|
|
{ |
79
|
|
|
object_set_properties($this->object, ['foo' => 'cool', 'bar' => 'land', 'color' => 'red'], true); |
80
|
|
|
|
81
|
|
|
$this->assertObjectHasAttribute('color', $this->object); |
82
|
|
|
$this->assertAttributeSame('red', 'color', $this->object); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @covers Jasny\object_set_properties |
87
|
|
|
*/ |
88
|
|
|
public function testObjectSetPropertiesNotDynamic() |
89
|
|
|
{ |
90
|
|
|
object_set_properties($this->object, ['foo' => 'cool', 'bar' => 'land', 'color' => 'red'], false); |
91
|
|
|
|
92
|
|
|
$this->assertObjectNotHasAttribute('color', $this->object); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.