Conditions | 1 |
Paths | 1 |
Total Lines | 101 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
103 | public function testValidateEntityID() |
||
104 | { |
||
105 | $realMeService = new RealMeService(); |
||
106 | $realMeSetupTask = new RealMeSetupTask(); |
||
107 | |||
108 | $errors = new ReflectionProperty($realMeSetupTask, 'errors'); |
||
109 | $errors->setAccessible(true); |
||
110 | |||
111 | $service = new ReflectionProperty($realMeSetupTask, 'service'); |
||
112 | $service->setAccessible(true); |
||
113 | $service->setValue($realMeSetupTask, $realMeService); |
||
114 | |||
115 | // Make sure there's no errors to begin. |
||
116 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
117 | |||
118 | // Test valid entityIds just in case they're different in this configuration. |
||
119 | $config = Config::inst(); |
||
120 | $config->update(RealMeService::class, 'sp_entity_ids', self::$validEntityIDs); |
||
121 | |||
122 | // validate our list of valid entity IDs; |
||
123 | $validateEntityId = new ReflectionMethod($realMeSetupTask, 'validateEntityID'); |
||
124 | $validateEntityId->setAccessible(true); |
||
125 | $validateEntityId->invoke($realMeSetupTask); |
||
126 | |||
127 | // valid entityID's shouldn't have any issues |
||
128 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
129 | |||
130 | // TEST entityId missing. |
||
131 | $entityIdList = self::$validEntityIDs; |
||
132 | $entityIdList[RealMeService::ENV_MTS] = 'destroy-humans-with-incorrect-entity-ids'; |
||
133 | $config->update(RealMeService::class, 'sp_entity_ids', $entityIdList); |
||
134 | $validateEntityId->invoke($realMeSetupTask); |
||
135 | $this->assertCount(1, $errors->getValue($realMeSetupTask), 'validate entity id should fail for an invalid url'); |
||
136 | |||
137 | // reset errors && Make sure there's no errors to begin. |
||
138 | $errors->setValue($realMeSetupTask, array()); |
||
139 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
140 | |||
141 | // TEST entityId localhost. |
||
142 | $entityIdList = self::$validEntityIDs; |
||
143 | $entityIdList[RealMeService::ENV_MTS] = 'https://localhost/'; |
||
144 | $config->update(RealMeService::class, 'sp_entity_ids', $entityIdList); |
||
145 | $validateEntityId->invoke($realMeSetupTask); |
||
146 | $this->assertCount(1, $errors->getValue($realMeSetupTask), 'validate entity id should fail for localhost'); |
||
147 | |||
148 | $errors->setValue($realMeSetupTask, array()); |
||
149 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
150 | |||
151 | // TEST entityId not http |
||
152 | $entityIdList = self::$validEntityIDs; |
||
153 | $entityIdList[RealMeService::ENV_MTS] = 'http://dev.realme-integration.govt.nz/p-realm/s-name'; |
||
154 | $config->update(RealMeService::class, 'sp_entity_ids', $entityIdList); |
||
155 | $validateEntityId->invoke($realMeSetupTask); |
||
156 | $this->assertCount(1, $errors->getValue($realMeSetupTask), 'validate entity id should fail for http'); |
||
157 | |||
158 | $errors->setValue($realMeSetupTask, array()); |
||
159 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
160 | |||
161 | // TEST privacy realm /service name missing |
||
162 | $entityIdList = self::$validEntityIDs; |
||
163 | $entityIdList[RealMeService::ENV_MTS] = 'https://dev.realme-integration.govt.nz/'; |
||
164 | $config->update(RealMeService::class, 'sp_entity_ids', $entityIdList); |
||
165 | $validateEntityId->invoke($realMeSetupTask); |
||
166 | $this->assertCount( |
||
167 | 2, |
||
168 | $errors->getValue($realMeSetupTask), |
||
169 | 'validate entity id should fail for missing service name and privacy realm' |
||
170 | ); |
||
171 | |||
172 | $errors->setValue($realMeSetupTask, array()); |
||
173 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
174 | |||
175 | // TEST privacy realm |
||
176 | // "https://www.domain.govt.nz/<privacy-realm>/<service-name>" |
||
177 | $entityIdList = self::$validEntityIDs; |
||
178 | $entityIdList[RealMeService::ENV_MTS] = |
||
179 | 'https://dev.realme-integration.govt.nz/s-name/privacy-realm-is-too-big'; |
||
180 | $config->update(RealMeService::class, 'sp_entity_ids', $entityIdList); |
||
181 | $validateEntityId->invoke($realMeSetupTask); |
||
182 | $this->assertCount( |
||
183 | 1, |
||
184 | $errors->getValue($realMeSetupTask), |
||
185 | 'validate entity id should fail for privacy-realm-is-too-big' |
||
186 | ); |
||
187 | |||
188 | $errors->setValue($realMeSetupTask, array()); |
||
189 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
190 | |||
191 | // "https://www.domain.govt.nz/<privacy-realm>/<service-name>" |
||
192 | $entityIdList = self::$validEntityIDs; |
||
193 | $entityIdList[RealMeService::ENV_MTS] = 'https://dev.realme-integration.govt.nz/s-name'; |
||
194 | $config->update(RealMeService::class, 'sp_entity_ids', $entityIdList); |
||
195 | $validateEntityId->invoke($realMeSetupTask); |
||
196 | $this->assertCount( |
||
197 | 1, |
||
198 | $errors->getValue($realMeSetupTask), |
||
199 | 'validate entity id should fail if privacy realm is missing' |
||
200 | ); |
||
201 | |||
202 | $errors->setValue($realMeSetupTask, array()); |
||
203 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
204 | } |
||
286 |