Test Failed
Push — master ( 299cbe...c555d0 )
by Maxim
01:58
created

ParentClass::testPrivate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/**
3
 * This file is a part of "Axessors" library.
4
 *
5
 * @author <[email protected]>
6
 * @package NoOne4rever\Axessors
7
 * @license GPL
8
 */
9
10
namespace NoOne4rever\Axessors\Examples;
11
12
use NoOne4rever\Axessors\Axessors;
13
use NoOne4rever\Axessors\Exceptions\OopError;
14
15
require 'C:/Users/NoOne/Documents/GitHub/Axessors/vendor/autoload.php';
16
17
/** Class ParentClass. */
18
class ParentClass
19
{
20
    /** Tests a method with public access. */
21
    public function testPublic(): void
22
    {
23
        $sample = new SampleClass();
24
        $sample->setPublicAccess('public:parent');
25
        echo $sample->getPublicAccess();
26
    }
27
28
    /** Tests a method with protected access. */
29
    public function testProtected(): void
30
    {
31
        $sample = new SampleClass();
32
        $sample->setProtectedAccess('protected:parent');
33
        echo $sample->getProtectedAccess();
34
    }
35
36
    /** Tests a method with private access. */
37
    public function testPrivate(): void
38
    {
39
        $sample = new SampleClass();
40
        $sample->setPrivateAccess('private:parent');
41
        echo $sample->getPrivateAccess();
42
    }
43
}
44
45
/**
46
 * Class SampleClass.
47
 *
48
 * @method mixed getPublicAccess() getter for $publicAccess
49
 * @method mixed getProtectedAccess() getter for $protectedAccess
50
 * @method mixed getPrivateAccess() getter for $privateAccess
51
 * @method void setPublicAccess(mixed $val) setter for $publicAccess
52
 * @method void setProtectedAccess(mixed $val) setter for $protectedAccess
53
 * @method void setPrivateAccess(mixed $val) setter for $privateAccess
54
 */
55
class SampleClass extends ParentClass
56
{
57
    use Axessors;
58
59
    /** @var mixed a field with public accessors */
60
    private $publicAccess;    #> +axs mixed
61
    /** @var mixed a field with protected accessors */
62
    private $protectedAccess; #> ~axs mixed
63
    /** @var mixed a field with private accessors */
64
    private $privateAccess;   #> -axs mixed
65
66
    /** Tests a method with public access. */
67
    public function testPublic(): void
68
    {
69
        $this->setPublicAccess('public:test');
70
        echo $this->getPublicAccess();
71
    }
72
73
    /** Tests a method with protected access. */
74
    public function testProtected(): void
75
    {
76
        $this->setProtectedAccess('protected:test');
77
        echo $this->getProtectedAccess();
78
    }
79
80
    /** Tests a method with private access. */
81
    public function testPrivate(): void
82
    {
83
        $this->setPrivateAccess('private:test');
84
        echo $this->getPrivateAccess();
85
    }
86
87
    /** Tests method call from instance. */
88
    public function testInstance(): void
89
    {
90
        $sample = new self();
91
        $sample->setPrivateAccess('private:instance');
92
        echo $sample->getPrivateAccess();
93
    }
94
}
95
96
/** Class ChildClass. */
97
class ChildClass extends SampleClass
98
{
99
    use Axessors;
100
101
    /** Tests a method with public access. */
102
    public function testPublic(): void
103
    {
104
        $this->setPublicAccess('public:child');
105
        echo $this->getPublicAccess();
106
    }
107
108
    /** Tests a method with protected access. */
109
    public function testProtected(): void
110
    {
111
        $this->setProtectedAccess('protected:child');
112
        echo $this->getProtectedAccess();
113
    }
114
115
    /** Tests a method with private access. */
116
    public function testPrivate(): void
117
    {
118
        $this->setPrivateAccess('private:child');
119
        echo $this->getPrivateAccess();
120
    }
121
122
    /** Tests method call from instance. */
123
    public function testInstance(): void
124
    {
125
        $sample = new parent();
126
        $sample->setProtectedAccess('protected:childInstance');
127
        echo $sample->getProtectedAccess();
128
    }
129
}
130
131
require 'C:/Users/NoOne/Documents/GitHub/Axessors/src/Startup.php';
132
133
// Testing parent:
134
135
$parent = new ParentClass();
136
137
$parent->testPublic();
138
echo PHP_EOL;
139
140
$parent->testProtected();
141
echo PHP_EOL;
142
143
try {
144
    $parent->testPrivate();
145
} catch (OopError $error) {
146
    echo $error->getMessage();
147
}
148
echo PHP_EOL;
149
150
// Testing TestCase:
151
152
$sample = new SampleClass();
153
154
$sample->testPublic();
155
echo PHP_EOL;
156
157
$sample->testProtected();
158
echo PHP_EOL;
159
160
$sample->testPrivate();
161
echo PHP_EOL;
162
163
$sample->testInstance();
164
echo PHP_EOL;
165
166
// Testing child:
167
168
$child = new ChildClass();
169
170
$child->testPublic();
171
echo PHP_EOL;
172
173
$child->testProtected();
174
echo PHP_EOL;
175
176
try {
177
    $child->testPrivate();
178
} catch (OopError $error) {
179
    echo $error->getMessage() . PHP_EOL;
180
}
181
182
$child->testInstance();
183
echo PHP_EOL;
184
185
// Global usage tests:
186
187
$sample = new SampleClass();
188
189
$sample->setPublicAccess('public:global');
190
echo $sample->getPublicAccess() . PHP_EOL;
191
192
try {
193
    $sample->setProtectedAccess('protected:global');
194
} catch (OopError $error) {
195
    echo $error->getMessage() . PHP_EOL;
196
}
197
198
try {
199
    $sample->setPrivateAccess('private:global');
200
} catch (OopError $error) {
201
    echo $error->getMessage() . PHP_EOL;
202
}