|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHP: Nelson Martell Library file |
|
4
|
|
|
* |
|
5
|
|
|
* Content: |
|
6
|
|
|
* - Trait definition. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright © 2016-2017 Nelson Martell (http://nelson6e65.github.io) |
|
9
|
|
|
* |
|
10
|
|
|
* Licensed under The MIT License (MIT) |
|
11
|
|
|
* For full copyright and license information, please see the LICENSE |
|
12
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
13
|
|
|
* |
|
14
|
|
|
* @copyright 2016-2017 Nelson Martell |
|
15
|
|
|
* @link http://nelson6e65.github.io/php_nml/ |
|
16
|
|
|
* @since v0.6.0 |
|
17
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) |
|
18
|
|
|
* */ |
|
19
|
|
|
|
|
20
|
|
|
namespace NelsonMartell\Test\DataProviders; |
|
21
|
|
|
|
|
22
|
|
|
use NelsonMartell\Test\Helpers\ExporterPlugin; |
|
23
|
|
|
use NelsonMartell\Test\Helpers\ImplementsIStrictPropertiesContainer; |
|
24
|
|
|
use NelsonMartell\Test\Helpers\HasWriteOnlyProperties; |
|
25
|
|
|
use NelsonMartell\Test\Helpers\HasReadOnlyProperties; |
|
26
|
|
|
use NelsonMartell\Test\Helpers\HasReadWriteProperties; |
|
27
|
|
|
use NelsonMartell\Test\Helpers\HasUnaccesibleProperties; |
|
28
|
|
|
use \InvalidArgumentException; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Data providers for NelsonMartell\Test\TestCase\PropertiesHandlerTest. |
|
32
|
|
|
* |
|
33
|
|
|
* @author Nelson Martell <[email protected]> |
|
34
|
|
|
* @internal |
|
35
|
|
|
* */ |
|
36
|
|
|
trait PropertiesHandlerTestProvider |
|
37
|
|
|
{ |
|
38
|
|
|
use ExporterPlugin; |
|
39
|
|
|
use ImplementsIStrictPropertiesContainer; |
|
40
|
|
|
use HasUnaccesibleProperties; |
|
41
|
|
|
use HasWriteOnlyProperties; |
|
42
|
|
|
use HasReadWriteProperties; |
|
43
|
|
|
use HasReadOnlyProperties; |
|
44
|
|
|
|
|
45
|
|
|
public function objectInstanceProvider() |
|
46
|
|
|
{ |
|
47
|
|
|
$a = new ExampleClass\A; |
|
|
|
|
|
|
48
|
|
|
$b = new ExampleClass\B; |
|
|
|
|
|
|
49
|
|
|
$c = new ExampleClass\C; |
|
|
|
|
|
|
50
|
|
|
$d = new ExampleClass\D; |
|
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
return [ |
|
53
|
|
|
[$a], |
|
54
|
|
|
[$b], |
|
55
|
|
|
[$c], |
|
56
|
|
|
[$d], |
|
57
|
|
|
]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
public function writeonlyPropertiesProvider() |
|
62
|
|
|
{ |
|
63
|
|
|
$a = new ExampleClass\A; |
|
|
|
|
|
|
64
|
|
|
$b = new ExampleClass\B; |
|
|
|
|
|
|
65
|
|
|
$c = new ExampleClass\C; |
|
|
|
|
|
|
66
|
|
|
$d = new ExampleClass\D; |
|
|
|
|
|
|
67
|
|
|
|
|
68
|
|
|
return [ |
|
69
|
|
|
'Set parent attribute accesible from parent (write-only property)' => [$b, 'property2', 2], |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function readwritePropertiesProvider() |
|
74
|
|
|
{ |
|
75
|
|
|
$a = new ExampleClass\A; |
|
|
|
|
|
|
76
|
|
|
$c = new ExampleClass\C; |
|
|
|
|
|
|
77
|
|
|
$d = new ExampleClass\D; |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
return [ |
|
80
|
|
|
'Set attribute with setter' => [$a, 'property3', 3, (3 * 100)], |
|
81
|
|
|
'Custom prefix (parent using default): Own property directly' => [$c, 'property6', 6, (6 * 99)], |
|
82
|
|
|
'Custom prefix (parent using custom): Own property directly' => [$d, 'property9', -9, -(9 * 10)], |
|
83
|
|
|
'Custom prefix (parent using default)): Parent property ' => [$c, 'property3', -3, -(3 * 100)], |
|
84
|
|
|
]; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
public function readonlyPropertiesProvider() |
|
89
|
|
|
{ |
|
90
|
|
|
$a = new ExampleClass\A; |
|
|
|
|
|
|
91
|
|
|
$b = new ExampleClass\B; |
|
|
|
|
|
|
92
|
|
|
$c = new ExampleClass\C; |
|
|
|
|
|
|
93
|
|
|
$d = new ExampleClass\D; |
|
|
|
|
|
|
94
|
|
|
return [ |
|
95
|
|
|
'Get property accesible via a wrapper' => [$a, 'property1', -1], |
|
96
|
|
|
'Get property accesible using attribute name' => [$a, 'attribute2', -2], |
|
97
|
|
|
'Get property accesible from parent only' => [$b, 'property4', -4], |
|
98
|
|
|
'Custom prefix: Own attribute directly' => [$c, 'attribute5', (-5 * 2)], |
|
99
|
|
|
'Custom prefix: Parent property' => [$d, 'property1', -1], |
|
100
|
|
|
]; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function unaccesiblePropertiesProvider() |
|
104
|
|
|
{ |
|
105
|
|
|
$a = new ExampleClass\A; |
|
|
|
|
|
|
106
|
|
|
$b = new ExampleClass\B; |
|
|
|
|
|
|
107
|
|
|
$c = new ExampleClass\C; |
|
|
|
|
|
|
108
|
|
|
$d = new ExampleClass\D; |
|
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
return [ |
|
111
|
|
|
'Get inexistent property in base' => [$a, 'property4'], |
|
112
|
|
|
'Get inexistent property in child' => [$b, 'property5'], |
|
113
|
|
|
'Set inexistent property' => [$a, 'property6', 6], |
|
114
|
|
|
'Set read-only property' => [$b, 'property4', 4], |
|
115
|
|
|
'Set read-only attribute' => [$a, 'attribute4', 4], |
|
116
|
|
|
'Set write-only property' => [$a, 'property2', 2], |
|
117
|
|
|
'Set unaccesible property from parent' => [$b, 'property1', 1], |
|
118
|
|
|
'Existent, but wrong prefixes' => [$b, 'property7'], |
|
119
|
|
|
'Existent, but wrong prefixes' => [$b, 'property7', 7], |
|
120
|
|
|
'Double definition of custom getter prefix: D::C' => [$d, 'property6'], |
|
121
|
|
|
'Double definition of custom setter prefix: D::C' => [$d, 'property6', 6], |
|
122
|
|
|
]; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.