1 | <?php |
||
2 | |||
3 | /** |
||
4 | * PHP: Nelson Martell Library file |
||
5 | * |
||
6 | * Copyright © 2016-2021 Nelson Martell (http://nelson6e65.github.io) |
||
7 | * |
||
8 | * Licensed under The MIT License (MIT) |
||
9 | * For full copyright and license information, please see the LICENSE |
||
10 | * Redistributions of files must retain the above copyright notice. |
||
11 | * |
||
12 | * @copyright 2016-2021 Nelson Martell |
||
13 | * @link http://nelson6e65.github.io/php_nml/ |
||
14 | * @since v0.6.0 |
||
15 | * @license http://www.opensource.org/licenses/mit-license.php The MIT License (MIT) |
||
16 | * */ |
||
17 | |||
18 | namespace NelsonMartell\Test\DataProviders; |
||
19 | |||
20 | use NelsonMartell\Test\DataProviders\ExampleClass\A; |
||
21 | use NelsonMartell\Test\DataProviders\ExampleClass\B; |
||
22 | use NelsonMartell\Test\DataProviders\ExampleClass\C; |
||
23 | use NelsonMartell\Test\DataProviders\ExampleClass\D; |
||
24 | use NelsonMartell\Test\DataProviders\ExampleClass\WithMagicPropertiesBaseClass; |
||
25 | use NelsonMartell\Test\DataProviders\ExampleClass\WithMagicPropertiesChildClass; |
||
26 | use NelsonMartell\Test\DataProviders\ExampleClass\WithoutMagicPropertiesClass; |
||
27 | use NelsonMartell\Test\Helpers\ExporterPlugin; |
||
28 | use NelsonMartell\Test\Helpers\HasReadOnlyProperties; |
||
29 | use NelsonMartell\Test\Helpers\HasReadWriteProperties; |
||
30 | use NelsonMartell\Test\Helpers\HasWriteOnlyProperties; |
||
31 | use NelsonMartell\Test\Helpers\HasUnaccesibleProperties; |
||
32 | use NelsonMartell\Test\Helpers\ImplementsIStrictPropertiesContainer; |
||
33 | use NelsonMartell\PropertiesHandler; |
||
34 | |||
35 | /** |
||
36 | * Data providers for NelsonMartell\Test\TestCase\PropertiesHandlerTest. |
||
37 | * |
||
38 | * @author Nelson Martell <[email protected]> |
||
39 | * @internal |
||
40 | * */ |
||
41 | trait PropertiesHandlerTestProvider |
||
42 | { |
||
43 | use ExporterPlugin; |
||
44 | use ImplementsIStrictPropertiesContainer; |
||
45 | use HasUnaccesibleProperties; |
||
46 | use HasWriteOnlyProperties; |
||
47 | use HasReadWriteProperties; |
||
48 | use HasReadOnlyProperties; |
||
49 | |||
50 | public function getTargetClassName(): string |
||
51 | { |
||
52 | return PropertiesHandler::class; |
||
53 | } |
||
54 | |||
55 | public function objectInstanceProvider(): array |
||
56 | { |
||
57 | $a = new A(); |
||
58 | $b = new B(); |
||
59 | $c = new C(); |
||
60 | $d = new D(); |
||
61 | |||
62 | return [ |
||
63 | [$a], |
||
64 | [$b], |
||
65 | [$c], |
||
66 | [$d], |
||
67 | ]; |
||
68 | } |
||
69 | |||
70 | |||
71 | public function writeonlyPropertiesProvider(): array |
||
72 | { |
||
73 | $a = new A(); |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
74 | $b = new B(); |
||
75 | $c = new C(); |
||
0 ignored issues
–
show
|
|||
76 | $d = new D(); |
||
0 ignored issues
–
show
|
|||
77 | |||
78 | return [ |
||
79 | 'Set parent attribute accesible from parent (write-only property)' => [$b, 'property2', 2], |
||
80 | ]; |
||
81 | } |
||
82 | |||
83 | public function readwritePropertiesProvider(): array |
||
84 | { |
||
85 | $a = new A(); |
||
86 | $c = new C(); |
||
87 | $d = new D(); |
||
88 | |||
89 | $mb = new WithMagicPropertiesBaseClass(); |
||
90 | $mc = new WithMagicPropertiesChildClass(); |
||
91 | $wm = new WithoutMagicPropertiesClass(); |
||
92 | |||
93 | return [ |
||
94 | 'Set attribute with setter' => [$a, 'property3', 3, (3 * 100)], |
||
95 | 'Custom prefix (parent using default): Own property directly' => [$c, 'property6', 6, (6 * 99)], |
||
96 | 'Custom prefix (parent using custom): Own property directly' => [$d, 'property9', -9, -(9 * 10)], |
||
97 | 'Custom prefix (parent using default)): Parent property ' => [$c, 'property3', -3, -(3 * 100)], |
||
98 | |||
99 | // Magic examples |
||
100 | 'Not implementing IMagicPropertiesContainer' => [$wm, 'noMagicProperty', 'yes', 'yes'], |
||
101 | 'Using IMagicPropertiesContainer' => [$mb, 'baseProperty', 'base', 'base'], |
||
102 | 'Parent using IMagicPropertiesContainer: Parent property' => [$mc, 'baseProperty', 'base', 'base'], |
||
103 | 'Parent using IMagicPropertiesContainer: Child property' => [$mc, 'childProperty', 'child', 'child'], |
||
104 | ]; |
||
105 | } |
||
106 | |||
107 | |||
108 | public function readonlyPropertiesProvider(): array |
||
109 | { |
||
110 | $a = new A(); |
||
111 | $b = new B(); |
||
112 | $c = new C(); |
||
113 | $d = new D(); |
||
114 | |||
115 | $mc = new WithMagicPropertiesChildClass(); |
||
116 | |||
117 | return [ |
||
118 | 'Get property accesible via a wrapper' => [$a, 'property1', -1], |
||
119 | 'Get property accesible using attribute name' => [$a, 'attribute2', -2], |
||
120 | 'Get property accesible from parent only' => [$b, 'property4', -4], |
||
121 | 'Custom prefix: Own attribute directly' => [$c, 'attribute5', (-5 * 2)], |
||
122 | 'Custom prefix: Parent property' => [$d, 'property1', -1], |
||
123 | |||
124 | // Magic |
||
125 | 'Parent using IMagicPropertiesContainer' => [$mc, 'readOnlyChildProperty', 1], |
||
126 | ]; |
||
127 | } |
||
128 | |||
129 | public function unaccesiblePropertiesProvider(): array |
||
130 | { |
||
131 | $a = new A(); |
||
132 | $b = new B(); |
||
133 | $c = new C(); |
||
0 ignored issues
–
show
|
|||
134 | $d = new D(); |
||
135 | $w = new WithoutMagicPropertiesClass(); |
||
136 | |||
137 | return [ |
||
138 | 'Get inexistent property in base' => [$a, 'property4'], |
||
139 | 'Get existent property with case changed' => [$a, 'Property1'], |
||
140 | 'Get inexistent property in child' => [$b, 'property5'], |
||
141 | 'Set inexistent property' => [$a, 'property6', 6], |
||
142 | 'Set read-only property' => [$b, 'property4', 4], |
||
143 | 'Set read-only attribute' => [$a, 'attribute4', 4], |
||
144 | 'Set write-only property' => [$a, 'property2', 2], |
||
145 | 'Set unaccesible property from parent' => [$b, 'property1', 1], |
||
146 | 'Existent, but wrong prefixes' => [$b, 'property7'], |
||
147 | 'Existent, but wrong prefixes 7' => [$b, 'property7', 7], |
||
148 | 'Double definition of custom getter prefix: D::C' => [$d, 'property6'], |
||
149 | 'Double definition of custom setter prefix: D::C' => [$d, 'property6', 6], |
||
150 | |||
151 | 'Unaccesibe since not implementing IMacigPropertiesContainer' => [$w, 'magicProperty', 'no'], |
||
152 | ]; |
||
153 | } |
||
154 | } |
||
155 |