Completed
Pull Request — master (#348)
by Marco
04:48
created

StaticProxyConstructorTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 0
loc 47
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testBodyStructure() 0 24 1
A testBodyStructureWithoutPublicProperties() 0 19 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\NullObject\MethodGenerator;
22
23
use PHPUnit_Framework_TestCase;
24
use ProxyManager\ProxyGenerator\NullObject\MethodGenerator\StaticProxyConstructor;
25
use ProxyManagerTestAsset\ClassWithMixedProperties;
26
use ProxyManagerTestAsset\ClassWithPrivateProperties;
27
use ReflectionClass;
28
29
/**
30
 * Tests for {@see \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\StaticProxyConstructor}
31
 *
32
 * @author Marco Pivetta <[email protected]>
33
 * @license MIT
34
 *
35
 * @covers \ProxyManager\ProxyGenerator\NullObject\MethodGenerator\StaticProxyConstructor
36
 * @group Coverage
37
 */
38
class StaticProxyConstructorTest extends PHPUnit_Framework_TestCase
39
{
40
    public function testBodyStructure() : void
41
    {
42
        $constructor = new StaticProxyConstructor(
43
            new ReflectionClass(ClassWithMixedProperties::class)
44
        );
45
46
        self::assertSame('staticProxyConstructor', $constructor->getName());
47
        self::assertTrue($constructor->isStatic());
48
        self::assertSame('public', $constructor->getVisibility());
49
        self::assertCount(0, $constructor->getParameters());
50
        self::assertSame(
51
            'static $reflection;
52
53
$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__);
54
$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();
55
56
$instance->publicProperty0 = null;
57
$instance->publicProperty1 = null;
58
$instance->publicProperty2 = null;
59
60
return $instance;',
61
            $constructor->getBody()
62
        );
63
    }
64
65
    public function testBodyStructureWithoutPublicProperties() : void
66
    {
67
        $constructor = new StaticProxyConstructor(
68
            new ReflectionClass(ClassWithPrivateProperties::class)
69
        );
70
71
        self::assertSame('staticProxyConstructor', $constructor->getName());
72
        self::assertCount(0, $constructor->getParameters());
73
        $body = $constructor->getBody();
74
        self::assertSame(
75
            'static $reflection;
76
77
$reflection = $reflection ?: $reflection = new \ReflectionClass(__CLASS__);
78
$instance = (new \ReflectionClass(get_class()))->newInstanceWithoutConstructor();
79
80
return $instance;',
81
            $body
82
        );
83
    }
84
}
85