ObjectFunctionsTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 82
rs 10
c 0
b 0
f 0
wmc 8

15 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ setUp() 0 11 1
testObjectSetProperties() 0 6 ?
A hp$0 ➔ testObjectSetPropertiesNotDynamic() 0 5 1
A hp$0 ➔ testObjectGetPropertiesDynamic() 0 7 1
testObjectGetPropertiesNotDynamic() 0 6 ?
setUp() 0 11 ?
testObjectGetPropertiesDynamic() 0 7 ?
A hp$0 ➔ getProperties() 0 3 1
testObjectSetPropertiesDynamic() 0 6 ?
A hp$0 ➔ testObjectGetPropertiesNotDynamic() 0 6 1
A hp$0 ➔ testObjectSetPropertiesDynamic() 0 6 1
testObjectGetProperties() 0 4 ?
testObjectSetPropertiesNotDynamic() 0 5 ?
A hp$0 ➔ testObjectGetProperties() 0 4 1
A hp$0 ➔ testObjectSetProperties() 0 6 1
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);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertAttributeSame() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3338 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

70
        /** @scrutinizer ignore-deprecated */ $this->assertAttributeSame('cool', 'foo', $this->object);

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.

Loading history...
71
        $this->assertAttributeSame('land', 'bar', $this->object);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertAttributeSame() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3338 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

71
        /** @scrutinizer ignore-deprecated */ $this->assertAttributeSame('land', 'bar', $this->object);

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.

Loading history...
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);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertAttributeSame() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3338 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

82
        /** @scrutinizer ignore-deprecated */ $this->assertAttributeSame('red', 'color', $this->object);

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.

Loading history...
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