Completed
Branch master (db83f9)
by Arnold
03:38
created

testObjectSetPropertiesNotDynamic()

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
nc 1
nop 0
dl 0
loc 5
c 0
b 0
f 0
1
<?php
2
3
namespace Jasny;
4
5
use Jasny\Tests\Support\FooBar;
0 ignored issues
show
Bug introduced by
The type Jasny\Tests\Support\FooBar was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use PHPStan\Testing\TestCase;
7
8
/**
9
 * Test object functions
10
 * @coversNothing
11
 */
12
class ObjectFunctionsTest extends TestCase
13
{
14
    protected $object;
15
16
    public function setUp()
17
    {
18
        $this->object = new class() {
19
            public $foo = 'woo';
20
            public $bar = 'BAR';
21
            protected $qux = 'qqq';
22
            private $tol = 'lot';
1 ignored issue
show
introduced by
The private property $tol is not used, and could be removed.
Loading history...
23
24
            public function getProperties($dynamic = false)
25
            {
26
                return \Jasny\object_get_properties($this, $dynamic);
27
            }
28
        };
29
    }
30
31
    /**
32
     * @covers Jasny\object_get_properties
33
     */
34
    public function testObjectGetProperties()
35
    {
36
        $this->assertSame(['foo' => 'woo', 'bar' => 'BAR'], object_get_properties($this->object));
37
        $this->assertSame(['foo' => 'woo', 'bar' => 'BAR'], $this->object->getProperties());
38
    }
39
40
    /**
41
     * @covers Jasny\object_get_properties
42
     */
43
    public function testObjectGetPropertiesDynamic()
44
    {
45
        $this->object->color = 'red';
46
47
        $expected = ['foo' => 'woo', 'bar' => 'BAR', 'color' => 'red'];
48
        $this->assertSame($expected, object_get_properties($this->object, true));
49
        $this->assertSame($expected, $this->object->getProperties(true));
50
    }
51
52
    /**
53
     * @covers Jasny\object_get_properties
54
     */
55
    public function testObjectGetPropertiesNotDynamic()
56
    {
57
        $this->object->color = 'red';
58
59
        $this->assertSame(['foo' => 'woo', 'bar' => 'BAR'], object_get_properties($this->object, false));
60
        $this->assertSame(['foo' => 'woo', 'bar' => 'BAR'], $this->object->getProperties(false));
61
    }
62
63
64
    /**
65
     * @covers Jasny\object_set_properties
66
     */
67
    public function testObjectSetProperties()
68
    {
69
        object_set_properties($this->object, ['foo' => 'cool', 'bar' => 'land']);
70
71
        $this->assertAttributeSame('cool', 'foo', $this->object);
72
        $this->assertAttributeSame('land', 'bar', $this->object);
73
    }
74
75
    /**
76
     * @covers Jasny\object_set_properties
77
     */
78
    public function testObjectSetPropertiesDynamic()
79
    {
80
        object_set_properties($this->object, ['foo' => 'cool', 'bar' => 'land', 'color' => 'red'], true);
81
82
        $this->assertObjectHasAttribute('color', $this->object);
83
        $this->assertAttributeSame('red', 'color', $this->object);
84
    }
85
86
    /**
87
     * @covers Jasny\object_set_properties
88
     */
89
    public function testObjectSetPropertiesNotDynamic()
90
    {
91
        object_set_properties($this->object, ['foo' => 'cool', 'bar' => 'land', 'color' => 'red'], false);
92
93
        $this->assertObjectNotHasAttribute('color', $this->object);
94
    }
95
}
96
97