|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHP: Nelson Martell Library file |
|
4
|
|
|
* |
|
5
|
|
|
* Content: |
|
6
|
|
|
* - Trait definition. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright © 2016 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 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 \InvalidArgumentException; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Data providers for NelsonMartell\Test\TestCase\PropertiesHandlerTest. |
|
27
|
|
|
* |
|
28
|
|
|
* @author Nelson Martell <[email protected]> |
|
29
|
|
|
* @internal |
|
30
|
|
|
* */ |
|
31
|
|
|
trait PropertiesHandlerTestProvider |
|
32
|
|
|
{ |
|
33
|
|
|
use ExporterPlugin; |
|
34
|
|
|
|
|
35
|
|
|
public function getAccesiblePropertiesProvider() |
|
36
|
|
|
{ |
|
37
|
|
|
$a = new ExampleClass\A; |
|
|
|
|
|
|
38
|
|
|
$b = new ExampleClass\B; |
|
|
|
|
|
|
39
|
|
|
$c = new ExampleClass\C; |
|
|
|
|
|
|
40
|
|
|
$d = new ExampleClass\D; |
|
|
|
|
|
|
41
|
|
|
return [ |
|
42
|
|
|
'Get property accesible via a wrapper' => [-1, $a, 'property1'], |
|
43
|
|
|
'Get property accesible using attribute name' => [-2, $a, 'attribute2'], |
|
44
|
|
|
'Get property accesible from parent only' => [-4, $b, 'property4'], |
|
45
|
|
|
'Custom prefix: Own attribute directly' => [(-5 * 2), $c, 'attribute5'], |
|
46
|
|
|
'Custom prefix: Own property directly' => [-6, $c, 'property6'], |
|
47
|
|
|
'Custom prefix: Own property directly2' => [-9, $d, 'property9'], |
|
48
|
|
|
'Custom prefix: Parent property' => [-1, $d, 'property1'], |
|
49
|
|
|
'Custom prefix: Parent property (using default prefix)' => [-3, $c, 'property3'], |
|
50
|
|
|
]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* testSetAccesibleProperties |
|
55
|
|
|
*/ |
|
56
|
|
|
public function setAccesiblePropertiesProvider() |
|
57
|
|
|
{ |
|
58
|
|
|
$a = new ExampleClass\A; |
|
|
|
|
|
|
59
|
|
|
$b = new ExampleClass\B; |
|
|
|
|
|
|
60
|
|
|
$c = new ExampleClass\C; |
|
|
|
|
|
|
61
|
|
|
$d = new ExampleClass\D; |
|
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
return [ |
|
64
|
|
|
'Public read-write property: Set attribute with setter' => [(3 * 100), $a, 'property3', 3], |
|
65
|
|
|
'Set parent attribute accesible from parent (write-only property)' => [null, $b, 'property2', 2], |
|
66
|
|
|
'Custom prefix: Own property' => [(6 * 99), $c, 'property6', 6], |
|
67
|
|
|
]; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function unaccesiblePropertiesProvider() |
|
71
|
|
|
{ |
|
72
|
|
|
$a = new ExampleClass\A; |
|
|
|
|
|
|
73
|
|
|
$b = new ExampleClass\B; |
|
|
|
|
|
|
74
|
|
|
$c = new ExampleClass\C; |
|
|
|
|
|
|
75
|
|
|
$d = new ExampleClass\D; |
|
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
return [ |
|
78
|
|
|
'Get inexistent property in base' => [$a, 'property4'], |
|
79
|
|
|
'Get inexistent property in child' => [$b, 'property5'], |
|
80
|
|
|
'Set inexistent property' => [$a, 'property6', 6], |
|
81
|
|
|
'Set read-only property' => [$b, 'property4', 4], |
|
82
|
|
|
'Set read-only attribute' => [$a, 'attribute4', 4], |
|
83
|
|
|
'Set write-only property' => [$a, 'property2', 2], |
|
84
|
|
|
'Set unaccesible property from parent' => [$b, 'property1', 1], |
|
85
|
|
|
'Existent, but wrong prefixes' => [$b, 'property7'], |
|
86
|
|
|
'Existent, but wrong prefixes' => [$b, 'property7', 7], |
|
87
|
|
|
'Double definition of custom getter prefix: D::C' => [$d, 'property6'], |
|
88
|
|
|
'Double definition of custom setter prefix: D::C' => [$d, 'property6', 6], |
|
89
|
|
|
]; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
|
|
|
|
|
92
|
|
|
|
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.