Completed
Push — master ( cce547...d39bda )
by Jefersson
11s
created

PublicPropertiesMapTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 57
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testEmptyClass() 0 12 1
B testClassWithPublicProperties() 0 27 1
A testClassWithMixedProperties() 0 13 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
19
declare(strict_types=1);
20
21
namespace ProxyManagerTest\ProxyGenerator\PropertyGenerator;
22
23
use PHPUnit_Framework_TestCase;
24
use ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap;
25
use ProxyManagerTestAsset\ClassWithMixedProperties;
26
use ProxyManager\ProxyGenerator\Util\Properties;
27
use ProxyManagerTestAsset\ClassWithPublicProperties;
28
use ProxyManagerTestAsset\EmptyClass;
29
use ReflectionClass;
30
31
/**
32
 * Tests for {@see \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap}
33
 *
34
 * @author Marco Pivetta <[email protected]>
35
 * @license MIT
36
 *
37
 * @covers \ProxyManager\ProxyGenerator\PropertyGenerator\PublicPropertiesMap
38
 * @group Coverage
39
 */
40
class PublicPropertiesMapTest extends PHPUnit_Framework_TestCase
41
{
42
    public function testEmptyClass() : void
43
    {
44
        $publicProperties = new PublicPropertiesMap(
45
            Properties::fromReflectionClass(new ReflectionClass(EmptyClass::class))
46
        );
47
48
        self::assertInternalType('array', $publicProperties->getDefaultValue()->getValue());
49
        self::assertEmpty($publicProperties->getDefaultValue()->getValue());
50
        self::assertTrue($publicProperties->isStatic());
51
        self::assertSame('private', $publicProperties->getVisibility());
52
        self::assertTrue($publicProperties->isEmpty());
53
    }
54
55
    public function testClassWithPublicProperties() : void
56
    {
57
        $publicProperties = new PublicPropertiesMap(
58
            Properties::fromReflectionClass(new ReflectionClass(ClassWithPublicProperties::class))
59
        );
60
61
        self::assertInternalType('array', $publicProperties->getDefaultValue()->getValue());
62
        self::assertCount(10, $publicProperties->getDefaultValue()->getValue());
63
        self::assertTrue($publicProperties->isStatic());
64
        self::assertSame('private', $publicProperties->getVisibility());
65
        self::assertFalse($publicProperties->isEmpty());
66
        self::assertSame(
67
            [
68
                'property0' => true,
69
                'property1' => true,
70
                'property2' => true,
71
                'property3' => true,
72
                'property4' => true,
73
                'property5' => true,
74
                'property6' => true,
75
                'property7' => true,
76
                'property8' => true,
77
                'property9' => true,
78
            ],
79
            $publicProperties->getDefaultValue()->getValue()
80
        );
81
    }
82
83
    public function testClassWithMixedProperties() : void
84
    {
85
        self::assertSame(
86
            [
87
                'publicProperty0' => true,
88
                'publicProperty1' => true,
89
                'publicProperty2' => true,
90
            ],
91
            (new PublicPropertiesMap(
92
                Properties::fromReflectionClass(new ReflectionClass(ClassWithMixedProperties::class))
93
            ))->getDefaultValue()->getValue()
94
        );
95
    }
96
}
97