| 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 |
||
| 107 | public function testValidateEntityID() |
||
| 108 | { |
||
| 109 | $realMeService = new RealMeService(); |
||
| 110 | $realMeSetupTask = new RealMeSetupTask(); |
||
| 111 | |||
| 112 | $errors = new ReflectionProperty($realMeSetupTask, 'errors'); |
||
| 113 | $errors->setAccessible(true); |
||
| 114 | |||
| 115 | $service = new ReflectionProperty($realMeSetupTask, 'service'); |
||
| 116 | $service->setAccessible(true); |
||
| 117 | $service->setValue($realMeSetupTask, $realMeService); |
||
| 118 | |||
| 119 | // Make sure there's no errors to begin. |
||
| 120 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
| 121 | |||
| 122 | // Test valid entityIds just in case they're different in this configuration. |
||
| 123 | $config = Config::inst(); |
||
| 124 | $config->update(RealMeService::class, 'sp_entity_ids', self::$validEntityIDs); |
||
| 125 | |||
| 126 | // validate our list of valid entity IDs; |
||
| 127 | $validateEntityId = new ReflectionMethod($realMeSetupTask, 'validateEntityID'); |
||
| 128 | $validateEntityId->setAccessible(true); |
||
| 129 | $validateEntityId->invoke($realMeSetupTask, 'mts'); |
||
| 130 | |||
| 131 | // valid entityID's shouldn't have any issues |
||
| 132 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
| 133 | |||
| 134 | // TEST entityId missing. |
||
| 135 | $entityIdList = self::$validEntityIDs; |
||
| 136 | $entityIdList[RealMeService::ENV_MTS] = 'destroy-humans-with-incorrect-entity-ids'; |
||
| 137 | $config->update(RealMeService::class, 'sp_entity_ids', $entityIdList); |
||
| 138 | $validateEntityId->invoke($realMeSetupTask, 'mts'); |
||
| 139 | $this->assertCount(1, $errors->getValue($realMeSetupTask), 'validate entity id should fail for an invalid url'); |
||
| 140 | |||
| 141 | // reset errors && Make sure there's no errors to begin. |
||
| 142 | $errors->setValue($realMeSetupTask, array()); |
||
| 143 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
| 144 | |||
| 145 | // TEST entityId localhost. |
||
| 146 | $entityIdList = self::$validEntityIDs; |
||
| 147 | $entityIdList[RealMeService::ENV_MTS] = 'https://localhost/'; |
||
| 148 | $config->update(RealMeService::class, 'sp_entity_ids', $entityIdList); |
||
| 149 | $validateEntityId->invoke($realMeSetupTask, 'mts'); |
||
| 150 | $this->assertCount(1, $errors->getValue($realMeSetupTask), 'validate entity id should fail for localhost'); |
||
| 151 | |||
| 152 | $errors->setValue($realMeSetupTask, array()); |
||
| 153 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
| 154 | |||
| 155 | // TEST entityId not http |
||
| 156 | $entityIdList = self::$validEntityIDs; |
||
| 157 | $entityIdList[RealMeService::ENV_MTS] = 'http://dev.realme-integration.govt.nz/p-realm/s-name'; |
||
| 158 | $config->update(RealMeService::class, 'sp_entity_ids', $entityIdList); |
||
| 159 | $validateEntityId->invoke($realMeSetupTask, 'mts'); |
||
| 160 | $this->assertCount(1, $errors->getValue($realMeSetupTask), 'validate entity id should fail for http'); |
||
| 161 | |||
| 162 | $errors->setValue($realMeSetupTask, array()); |
||
| 163 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
| 164 | |||
| 165 | // TEST privacy realm /service name missing |
||
| 166 | $entityIdList = self::$validEntityIDs; |
||
| 167 | $entityIdList[RealMeService::ENV_MTS] = 'https://dev.realme-integration.govt.nz/'; |
||
| 168 | $config->update(RealMeService::class, 'sp_entity_ids', $entityIdList); |
||
| 169 | $validateEntityId->invoke($realMeSetupTask, 'mts'); |
||
| 170 | $this->assertCount( |
||
| 171 | 2, |
||
| 172 | $errors->getValue($realMeSetupTask), |
||
| 173 | 'validate entity id should fail for missing service name and privacy realm' |
||
| 174 | ); |
||
| 175 | |||
| 176 | $errors->setValue($realMeSetupTask, array()); |
||
| 177 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
| 178 | |||
| 179 | // TEST privacy realm |
||
| 180 | // "https://www.domain.govt.nz/<privacy-realm>/<service-name>" |
||
| 181 | $entityIdList = self::$validEntityIDs; |
||
| 182 | $entityIdList[RealMeService::ENV_MTS] = |
||
| 183 | 'https://dev.realme-integration.govt.nz/s-name/privacy-realm-is-too-big'; |
||
| 184 | $config->update(RealMeService::class, 'sp_entity_ids', $entityIdList); |
||
| 185 | $validateEntityId->invoke($realMeSetupTask, 'mts'); |
||
| 186 | $this->assertCount( |
||
| 187 | 1, |
||
| 188 | $errors->getValue($realMeSetupTask), |
||
| 189 | 'validate entity id should fail for privacy-realm-is-too-big' |
||
| 190 | ); |
||
| 191 | |||
| 192 | $errors->setValue($realMeSetupTask, array()); |
||
| 193 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
| 194 | |||
| 195 | // "https://www.domain.govt.nz/<privacy-realm>/<service-name>" |
||
| 196 | $entityIdList = self::$validEntityIDs; |
||
| 197 | $entityIdList[RealMeService::ENV_MTS] = 'https://dev.realme-integration.govt.nz/s-name'; |
||
| 198 | $config->update(RealMeService::class, 'sp_entity_ids', $entityIdList); |
||
| 199 | $validateEntityId->invoke($realMeSetupTask, 'mts'); |
||
| 200 | $this->assertCount( |
||
| 201 | 1, |
||
| 202 | $errors->getValue($realMeSetupTask), |
||
| 203 | 'validate entity id should fail if privacy realm is missing' |
||
| 204 | ); |
||
| 205 | |||
| 206 | $errors->setValue($realMeSetupTask, array()); |
||
| 207 | $this->assertCount(0, $errors->getValue($realMeSetupTask)); |
||
| 208 | } |
||
| 296 |