/
ObjectPropertyTest.php
71 lines (45 loc) · 1.83 KB
/
ObjectPropertyTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
use Codeception\Specify\ObjectProperty;
final class ObjectPropertyTest extends SpecifyUnitTest
{
private ?string $prop = null;
private $private = 'private';
public function testConstruction()
{
$this->prop = 'test';
$prop = new ObjectProperty($this, 'prop');
$this->assertEquals('prop', $prop->getName());
$this->assertEquals('test', $prop->getValue());
$prop = new ObjectProperty($this, 'private');
$this->assertEquals('private', $prop->getName());
$this->assertEquals('private', $prop->getValue());
$prop = new ObjectProperty(
$this, new ReflectionProperty($this, 'private')
);
$this->assertEquals('private', $prop->getName());
$this->assertEquals('private', $prop->getValue());
}
public function testRestore()
{
$this->prop = 'test';
$prop = new ObjectProperty($this, 'prop');
$prop->setValue('another value');
$this->assertEquals('another value', $this->prop);
$prop->restoreValue();
$this->assertEquals('test', $this->prop);
$prop = new ObjectProperty($this, 'private');
$prop->setValue('another private value');
$this->assertEquals('another private value', $this->private);
$prop->restoreValue();
$this->assertEquals('private', $this->private);
$prop = new ObjectProperty($this, 'prop', 'testing');
$this->assertEquals('test', $prop->getValue());
$prop->setValue('Hello, World!');
$this->assertEquals($prop->getValue(), $this->prop);
$this->assertEquals('Hello, World!', $prop->getValue());
$prop->restoreValue();
$this->assertEquals($prop->getValue(), $this->prop);
$this->assertEquals('testing', $prop->getValue());
}
}