PhpObjectDecorationBodyCreationTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 13
dl 0
loc 128
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testShouldCreateBodyOfDecoratedObject() 0 17 1
1
<?php
2
3
namespace Exsio\PhpObjectDecorator\Tests;
4
5
use Exsio\PhpObjectDecorator\PhpObjectDecorator;
6
use Exsio\PhpObjectDecorator\PhpObjectDecoratorBehavior;
7
use Exsio\PhpObjectDecorator\PhpObjectDecoratorMethodOverride;
8
use Exsio\PhpObjectDecorator\Tests\Fixtures\Behaviors\ValidBehavior1Interface;
9
use Exsio\PhpObjectDecorator\Tests\Fixtures\Behaviors\ValidBehavior1Trait;
10
use Exsio\PhpObjectDecorator\Tests\Fixtures\ChildObjectToDecorate;
11
use Exsio\PhpObjectDecorator\Tests\Fixtures\TestMethodProcessor;
12
use PHPUnit\Framework\TestCase;
13
14
class PhpObjectDecorationBodyCreationTest extends TestCase
15
{
16
    const EXPECTED = '
17
            namespace Exsio\\PhpObjectDecorator\\Tests;
18
        
19
            class Exsio_PhpObjectDecorator_Tests_Fixtures_ChildObjectToDecorate_PhpDecoratedObject extends Exsio\\PhpObjectDecorator\\Tests\\Fixtures\\ChildObjectToDecorate implements Exsio\\PhpObjectDecorator\\Tests\\Fixtures\\Behaviors\\ValidBehavior1Interface, Exsio\\PhpObjectDecorator\\PhpDecoratedObjectInterface  
20
            {
21
                private string $__originalClass = \'Exsio\\PhpObjectDecorator\\Tests\\Fixtures\\ChildObjectToDecorate\';
22
23
                use Exsio\\PhpObjectDecorator\\Tests\\Fixtures\\Behaviors\\ValidBehavior1Trait;
24
25
                
26
                public function callInParent(): string
27
                {
28
                    
29
                    return \'OVERRIDDEN METHOD \' . parent::callInParent();
30
            
31
                }
32
            
33
        
34
                public function callInChild(): string
35
                {
36
                    
37
                    echo \'PROCESSED METHOD\';
38
                    return parent::callInChild();
39
        
40
                }
41
            
42
        
43
                public function getChildPublicProperty(): string
44
                {
45
                    
46
                    echo \'PROCESSED METHOD\';
47
                    return parent::getChildPublicProperty();
48
        
49
                }
50
            
51
        
52
                public function getChildProtectedProperty(): string
53
                {
54
                    
55
                    echo \'PROCESSED METHOD\';
56
                    return parent::getChildProtectedProperty();
57
        
58
                }
59
            
60
        
61
                public function getChildPrivateProperty(): string
62
                {
63
                    
64
                    echo \'PROCESSED METHOD\';
65
                    return parent::getChildPrivateProperty();
66
        
67
                }
68
            
69
        
70
                public function getPrivateProperty(): string
71
                {
72
                    
73
                    echo \'PROCESSED METHOD\';
74
                    return parent::getPrivateProperty();
75
        
76
                }
77
            
78
        
79
                public function getPublicProperty(): string
80
                {
81
                    
82
                    echo \'PROCESSED METHOD\';
83
                    return parent::getPublicProperty();
84
        
85
                }
86
            
87
        
88
                public function getProtectedProperty(): string
89
                {
90
                    
91
                    echo \'PROCESSED METHOD\';
92
                    return parent::getProtectedProperty();
93
        
94
                }
95
            
96
        
97
                protected function protectedContent(): string
98
                {
99
                    
100
                    echo \'PROCESSED METHOD\';
101
                    return parent::protectedContent();
102
        
103
                }
104
            
105
        
106
                public function callInTrait(): string
107
                {
108
                    
109
                    echo \'PROCESSED METHOD\';
110
                    return parent::callInTrait();
111
        
112
                }
113
            
114
        
115
                
116
                public function getOriginalClass(): string
117
                {
118
                    return $this->__originalClass;
119
                }
120
                
121
            }
122
        ';
123
124
125
    public function testShouldCreateBodyOfDecoratedObject()
126
    {
127
        //when:
128
        $result    = PhpObjectDecorator::decorate(new ChildObjectToDecorate())
129
            ->withNamespace("Exsio\PhpObjectDecorator\Tests")
130
            ->withBehavior(new PhpObjectDecoratorBehavior(ValidBehavior1Interface::class, ValidBehavior1Trait::class))
131
            ->withMethodOverride(new PhpObjectDecoratorMethodOverride("callInParent",
132
                "
133
                    return 'OVERRIDDEN METHOD ' . %CALL_PARENT%;
134
            "))
135
            ->withMethodProcessor(new TestMethodProcessor())
136
            ->get();
137
138
        $body = $result->getBody();
139
140
        //then:
141
        $this->assertEquals(trim(self::EXPECTED), trim($body));
142
    }
143
144
145
}