| Total Complexity | 69 | 
| Total Lines | 890 | 
| Duplicated Lines | 0 % | 
| Changes | 2 | ||
| Bugs | 0 | Features | 0 | 
Complex classes like UriTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UriTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php | ||
| 8 | class UriTest extends TestCase | ||
| 9 | { | ||
| 10 | /** | ||
| 11 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 12 | */ | ||
| 13 | public function testConstructCorrectInterfaceWithoutUri(): void | ||
| 14 |     { | ||
| 15 | $uri = new Uri(); | ||
| 16 | |||
| 17 |         self::assertInstanceOf('\\OAuth\\Common\\Http\\Uri\\UriInterface', $uri); | ||
| 18 | } | ||
| 19 | |||
| 20 | /** | ||
| 21 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 22 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 23 | */ | ||
| 24 | public function testConstructThrowsExceptionOnInvalidUri(): void | ||
| 25 |     { | ||
| 26 |         $this->expectException('\\InvalidArgumentException'); | ||
| 27 | |||
| 28 | // http://lxr.php.net/xref/PHP_5_4/ext/standard/tests/url/urls.inc#92 | ||
| 29 |         $uri = new Uri('http://@:/'); | ||
|  | |||
| 30 | } | ||
| 31 | |||
| 32 | /** | ||
| 33 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 34 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 35 | */ | ||
| 36 | public function testConstructThrowsExceptionOnUriWithoutScheme(): void | ||
| 37 |     { | ||
| 38 |         $this->expectException('\\InvalidArgumentException'); | ||
| 39 | |||
| 40 |         $uri = new Uri('www.pieterhordijk.com'); | ||
| 41 | } | ||
| 42 | |||
| 43 | /** | ||
| 44 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 45 | * @covers \OAuth\Common\Http\Uri\Uri::getScheme | ||
| 46 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 47 | */ | ||
| 48 | public function testGetScheme(): void | ||
| 49 |     { | ||
| 50 |         $uri = new Uri('http://example.com'); | ||
| 51 | |||
| 52 |         self::assertSame('http', $uri->getScheme()); | ||
| 53 | } | ||
| 54 | |||
| 55 | /** | ||
| 56 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 57 | * @covers \OAuth\Common\Http\Uri\Uri::getUserInfo | ||
| 58 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 59 | * @covers \OAuth\Common\Http\Uri\Uri::protectUserInfo | ||
| 60 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 61 | */ | ||
| 62 | public function testGetUserInfo(): void | ||
| 63 |     { | ||
| 64 |         $uri = new Uri('http://[email protected]'); | ||
| 65 | |||
| 66 |         self::assertSame('peehaa', $uri->getUserInfo()); | ||
| 67 | } | ||
| 68 | |||
| 69 | /** | ||
| 70 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 71 | * @covers \OAuth\Common\Http\Uri\Uri::getUserInfo | ||
| 72 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 73 | * @covers \OAuth\Common\Http\Uri\Uri::protectUserInfo | ||
| 74 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 75 | */ | ||
| 76 | public function testGetUserInfoWithPass(): void | ||
| 77 |     { | ||
| 78 |         $uri = new Uri('http://peehaa:[email protected]'); | ||
| 79 | |||
| 80 |         self::assertSame('peehaa:********', $uri->getUserInfo()); | ||
| 81 | } | ||
| 82 | |||
| 83 | /** | ||
| 84 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 85 | * @covers \OAuth\Common\Http\Uri\Uri::getRawUserInfo | ||
| 86 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 87 | * @covers \OAuth\Common\Http\Uri\Uri::protectUserInfo | ||
| 88 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 89 | */ | ||
| 90 | public function testGetRawUserInfo(): void | ||
| 91 |     { | ||
| 92 |         $uri = new Uri('http://[email protected]'); | ||
| 93 | |||
| 94 |         self::assertSame('peehaa', $uri->getRawUserInfo()); | ||
| 95 | } | ||
| 96 | |||
| 97 | /** | ||
| 98 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 99 | * @covers \OAuth\Common\Http\Uri\Uri::getRawUserInfo | ||
| 100 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 101 | * @covers \OAuth\Common\Http\Uri\Uri::protectUserInfo | ||
| 102 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 103 | */ | ||
| 104 | public function testGetRawUserInfoWithPass(): void | ||
| 105 |     { | ||
| 106 |         $uri = new Uri('http://peehaa:[email protected]'); | ||
| 107 | |||
| 108 |         self::assertSame('peehaa:pass', $uri->getRawUserInfo()); | ||
| 109 | } | ||
| 110 | |||
| 111 | /** | ||
| 112 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 113 | * @covers \OAuth\Common\Http\Uri\Uri::getHost | ||
| 114 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 115 | */ | ||
| 116 | public function testGetHost(): void | ||
| 117 |     { | ||
| 118 |         $uri = new Uri('http://example.com'); | ||
| 119 | |||
| 120 |         self::assertSame('example.com', $uri->getHost()); | ||
| 121 | } | ||
| 122 | |||
| 123 | /** | ||
| 124 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 125 | * @covers \OAuth\Common\Http\Uri\Uri::getPort | ||
| 126 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 127 | */ | ||
| 128 | public function testGetPortImplicitHttp(): void | ||
| 129 |     { | ||
| 130 |         $uri = new Uri('http://example.com'); | ||
| 131 | |||
| 132 | self::assertSame(80, $uri->getPort()); | ||
| 133 | } | ||
| 134 | |||
| 135 | /** | ||
| 136 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 137 | * @covers \OAuth\Common\Http\Uri\Uri::getPort | ||
| 138 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 139 | */ | ||
| 140 | public function testGetPortImplicitHttps(): void | ||
| 141 |     { | ||
| 142 |         $uri = new Uri('https://example.com'); | ||
| 143 | |||
| 144 | self::assertSame(443, $uri->getPort()); | ||
| 145 | } | ||
| 146 | |||
| 147 | /** | ||
| 148 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 149 | * @covers \OAuth\Common\Http\Uri\Uri::getPort | ||
| 150 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 151 | */ | ||
| 152 | public function testGetPortExplicit(): void | ||
| 153 |     { | ||
| 154 |         $uri = new Uri('http://example.com:21'); | ||
| 155 | |||
| 156 | self::assertSame(21, $uri->getPort()); | ||
| 157 | } | ||
| 158 | |||
| 159 | /** | ||
| 160 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 161 | * @covers \OAuth\Common\Http\Uri\Uri::getPath | ||
| 162 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 163 | */ | ||
| 164 | public function testGetPathNotSupplied(): void | ||
| 165 |     { | ||
| 166 |         $uri = new Uri('http://example.com'); | ||
| 167 | |||
| 168 |         self::assertSame('/', $uri->getPath()); | ||
| 169 | } | ||
| 170 | |||
| 171 | /** | ||
| 172 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 173 | * @covers \OAuth\Common\Http\Uri\Uri::getPath | ||
| 174 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 175 | */ | ||
| 176 | public function testGetPathSlash(): void | ||
| 177 |     { | ||
| 178 |         $uri = new Uri('http://example.com/'); | ||
| 179 | |||
| 180 |         self::assertSame('/', $uri->getPath()); | ||
| 181 | } | ||
| 182 | |||
| 183 | /** | ||
| 184 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 185 | * @covers \OAuth\Common\Http\Uri\Uri::getPath | ||
| 186 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 187 | */ | ||
| 188 | public function testGetPath(): void | ||
| 189 |     { | ||
| 190 |         $uri = new Uri('http://example.com/foo'); | ||
| 191 | |||
| 192 |         self::assertSame('/foo', $uri->getPath()); | ||
| 193 | } | ||
| 194 | |||
| 195 | /** | ||
| 196 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 197 | * @covers \OAuth\Common\Http\Uri\Uri::getQuery | ||
| 198 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 199 | */ | ||
| 200 | public function testGetQueryWithParams(): void | ||
| 201 |     { | ||
| 202 |         $uri = new Uri('http://example.com?param1=first¶m2=second'); | ||
| 203 | |||
| 204 |         self::assertSame('param1=first¶m2=second', $uri->getQuery()); | ||
| 205 | } | ||
| 206 | |||
| 207 | /** | ||
| 208 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 209 | * @covers \OAuth\Common\Http\Uri\Uri::getQuery | ||
| 210 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 211 | */ | ||
| 212 | public function testGetQueryWithoutParams(): void | ||
| 213 |     { | ||
| 214 |         $uri = new Uri('http://example.com'); | ||
| 215 | |||
| 216 |         self::assertSame('', $uri->getQuery()); | ||
| 217 | } | ||
| 218 | |||
| 219 | /** | ||
| 220 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 221 | * @covers \OAuth\Common\Http\Uri\Uri::getFragment | ||
| 222 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 223 | */ | ||
| 224 | public function testGetFragmentExists(): void | ||
| 225 |     { | ||
| 226 |         $uri = new Uri('http://example.com#foo'); | ||
| 227 | |||
| 228 |         self::assertSame('foo', $uri->getFragment()); | ||
| 229 | } | ||
| 230 | |||
| 231 | /** | ||
| 232 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 233 | * @covers \OAuth\Common\Http\Uri\Uri::getFragment | ||
| 234 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 235 | */ | ||
| 236 | public function testGetFragmentNotExists(): void | ||
| 237 |     { | ||
| 238 |         $uri = new Uri('http://example.com'); | ||
| 239 | |||
| 240 |         self::assertSame('', $uri->getFragment()); | ||
| 241 | } | ||
| 242 | |||
| 243 | /** | ||
| 244 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 245 | * @covers \OAuth\Common\Http\Uri\Uri::getAuthority | ||
| 246 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 247 | */ | ||
| 248 | public function testGetAuthorityWithoutUserInfo(): void | ||
| 249 |     { | ||
| 250 |         $uri = new Uri('http://example.com'); | ||
| 251 | |||
| 252 |         self::assertSame('example.com', $uri->getAuthority()); | ||
| 253 | } | ||
| 254 | |||
| 255 | /** | ||
| 256 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 257 | * @covers \OAuth\Common\Http\Uri\Uri::getAuthority | ||
| 258 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 259 | */ | ||
| 260 | public function testGetAuthorityWithoutUserInfoWithExplicitPort(): void | ||
| 261 |     { | ||
| 262 |         $uri = new Uri('http://example.com:21'); | ||
| 263 | |||
| 264 |         self::assertSame('example.com:21', $uri->getAuthority()); | ||
| 265 | } | ||
| 266 | |||
| 267 | /** | ||
| 268 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 269 | * @covers \OAuth\Common\Http\Uri\Uri::getAuthority | ||
| 270 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 271 | * @covers \OAuth\Common\Http\Uri\Uri::protectUserInfo | ||
| 272 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 273 | */ | ||
| 274 | public function testGetAuthorityWithUsernameWithExplicitPort(): void | ||
| 275 |     { | ||
| 276 |         $uri = new Uri('http://[email protected]:21'); | ||
| 277 | |||
| 278 |         self::assertSame('[email protected]:21', $uri->getAuthority()); | ||
| 279 | } | ||
| 280 | |||
| 281 | /** | ||
| 282 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 283 | * @covers \OAuth\Common\Http\Uri\Uri::getAuthority | ||
| 284 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 285 | * @covers \OAuth\Common\Http\Uri\Uri::protectUserInfo | ||
| 286 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 287 | */ | ||
| 288 | public function testGetAuthorityWithUsernameAndPassWithExplicitPort(): void | ||
| 289 |     { | ||
| 290 |         $uri = new Uri('http://peehaa:[email protected]:21'); | ||
| 291 | |||
| 292 |         self::assertSame('peehaa:********@example.com:21', $uri->getAuthority()); | ||
| 293 | } | ||
| 294 | |||
| 295 | /** | ||
| 296 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 297 | * @covers \OAuth\Common\Http\Uri\Uri::getAuthority | ||
| 298 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 299 | * @covers \OAuth\Common\Http\Uri\Uri::protectUserInfo | ||
| 300 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 301 | */ | ||
| 302 | public function testGetAuthorityWithUsernameAndPassWithoutExplicitPort(): void | ||
| 303 |     { | ||
| 304 |         $uri = new Uri('http://peehaa:[email protected]'); | ||
| 305 | |||
| 306 |         self::assertSame('peehaa:********@example.com', $uri->getAuthority()); | ||
| 307 | } | ||
| 308 | |||
| 309 | /** | ||
| 310 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 311 | * @covers \OAuth\Common\Http\Uri\Uri::getRawAuthority | ||
| 312 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 313 | */ | ||
| 314 | public function testGetRawAuthorityWithoutUserInfo(): void | ||
| 315 |     { | ||
| 316 |         $uri = new Uri('http://example.com'); | ||
| 317 | |||
| 318 |         self::assertSame('example.com', $uri->getRawAuthority()); | ||
| 319 | } | ||
| 320 | |||
| 321 | /** | ||
| 322 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 323 | * @covers \OAuth\Common\Http\Uri\Uri::getRawAuthority | ||
| 324 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 325 | */ | ||
| 326 | public function testGetRawAuthorityWithoutUserInfoWithExplicitPort(): void | ||
| 327 |     { | ||
| 328 |         $uri = new Uri('http://example.com:21'); | ||
| 329 | |||
| 330 |         self::assertSame('example.com:21', $uri->getRawAuthority()); | ||
| 331 | } | ||
| 332 | |||
| 333 | /** | ||
| 334 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 335 | * @covers \OAuth\Common\Http\Uri\Uri::getRawAuthority | ||
| 336 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 337 | * @covers \OAuth\Common\Http\Uri\Uri::protectUserInfo | ||
| 338 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 339 | */ | ||
| 340 | public function testGetRawAuthorityWithUsernameWithExplicitPort(): void | ||
| 341 |     { | ||
| 342 |         $uri = new Uri('http://[email protected]:21'); | ||
| 343 | |||
| 344 |         self::assertSame('[email protected]:21', $uri->getRawAuthority()); | ||
| 345 | } | ||
| 346 | |||
| 347 | /** | ||
| 348 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 349 | * @covers \OAuth\Common\Http\Uri\Uri::getRawAuthority | ||
| 350 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 351 | * @covers \OAuth\Common\Http\Uri\Uri::protectUserInfo | ||
| 352 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 353 | */ | ||
| 354 | public function testGetRawAuthorityWithUsernameAndPassWithExplicitPort(): void | ||
| 355 |     { | ||
| 356 |         $uri = new Uri('http://peehaa:[email protected]:21'); | ||
| 357 | |||
| 358 |         self::assertSame('peehaa:[email protected]:21', $uri->getRawAuthority()); | ||
| 359 | } | ||
| 360 | |||
| 361 | /** | ||
| 362 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 363 | * @covers \OAuth\Common\Http\Uri\Uri::getRawAuthority | ||
| 364 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 365 | * @covers \OAuth\Common\Http\Uri\Uri::protectUserInfo | ||
| 366 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 367 | */ | ||
| 368 | public function testGetRawAuthorityWithUsernameAndPassWithoutExplicitPort(): void | ||
| 369 |     { | ||
| 370 |         $uri = new Uri('http://peehaa:[email protected]'); | ||
| 371 | |||
| 372 |         self::assertSame('peehaa:[email protected]', $uri->getRawAuthority()); | ||
| 373 | } | ||
| 374 | |||
| 375 | /** | ||
| 376 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 377 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 378 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 379 | */ | ||
| 380 | public function testGetAbsoluteUriBare(): void | ||
| 381 |     { | ||
| 382 |         $uri = new Uri('http://example.com'); | ||
| 383 | |||
| 384 |         self::assertSame('http://example.com', $uri->getAbsoluteUri()); | ||
| 385 | } | ||
| 386 | |||
| 387 | /** | ||
| 388 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 389 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 390 | * @covers \OAuth\Common\Http\Uri\Uri::getRawAuthority | ||
| 391 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 392 | * @covers \OAuth\Common\Http\Uri\Uri::protectUserInfo | ||
| 393 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 394 | */ | ||
| 395 | public function testGetAbsoluteUriWithAuthority(): void | ||
| 396 |     { | ||
| 397 |         $uri = new Uri('http://peehaa:[email protected]'); | ||
| 398 | |||
| 399 |         self::assertSame('http://peehaa:[email protected]', $uri->getAbsoluteUri()); | ||
| 400 | } | ||
| 401 | |||
| 402 | /** | ||
| 403 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 404 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 405 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 406 | */ | ||
| 407 | public function testGetAbsoluteUriWithPath(): void | ||
| 408 |     { | ||
| 409 |         $uri = new Uri('http://example.com/foo'); | ||
| 410 | |||
| 411 |         self::assertSame('http://example.com/foo', $uri->getAbsoluteUri()); | ||
| 412 | } | ||
| 413 | |||
| 414 | /** | ||
| 415 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 416 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 417 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 418 | */ | ||
| 419 | public function testGetAbsoluteUriWithoutPath(): void | ||
| 420 |     { | ||
| 421 |         $uri = new Uri('http://example.com'); | ||
| 422 | |||
| 423 |         self::assertSame('http://example.com', $uri->getAbsoluteUri()); | ||
| 424 | } | ||
| 425 | |||
| 426 | /** | ||
| 427 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 428 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 429 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 430 | */ | ||
| 431 | public function testGetAbsoluteUriWithoutPathExplicitTrailingSlash(): void | ||
| 432 |     { | ||
| 433 |         $uri = new Uri('http://example.com/'); | ||
| 434 | |||
| 435 |         self::assertSame('http://example.com/', $uri->getAbsoluteUri()); | ||
| 436 | } | ||
| 437 | |||
| 438 | /** | ||
| 439 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 440 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 441 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 442 | */ | ||
| 443 | public function testGetAbsoluteUriWithQuery(): void | ||
| 444 |     { | ||
| 445 |         $uri = new Uri('http://example.com?param1=value1'); | ||
| 446 | |||
| 447 |         self::assertSame('http://example.com?param1=value1', $uri->getAbsoluteUri()); | ||
| 448 | } | ||
| 449 | |||
| 450 | /** | ||
| 451 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 452 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 453 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 454 | */ | ||
| 455 | public function testGetAbsoluteUriWithFragment(): void | ||
| 456 |     { | ||
| 457 |         $uri = new Uri('http://example.com#foo'); | ||
| 458 | |||
| 459 |         self::assertSame('http://example.com#foo', $uri->getAbsoluteUri()); | ||
| 460 | } | ||
| 461 | |||
| 462 | /** | ||
| 463 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 464 | * @covers \OAuth\Common\Http\Uri\Uri::getRelativeUri | ||
| 465 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 466 | */ | ||
| 467 | public function testGetRelativeUriWithoutPath(): void | ||
| 468 |     { | ||
| 469 |         $uri = new Uri('http://example.com'); | ||
| 470 | |||
| 471 |         self::assertSame('', $uri->getRelativeUri()); | ||
| 472 | } | ||
| 473 | |||
| 474 | /** | ||
| 475 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 476 | * @covers \OAuth\Common\Http\Uri\Uri::getRelativeUri | ||
| 477 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 478 | */ | ||
| 479 | public function testGetRelativeUriWithPath(): void | ||
| 480 |     { | ||
| 481 |         $uri = new Uri('http://example.com/foo'); | ||
| 482 | |||
| 483 |         self::assertSame('/foo', $uri->getRelativeUri()); | ||
| 484 | } | ||
| 485 | |||
| 486 | /** | ||
| 487 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 488 | * @covers \OAuth\Common\Http\Uri\Uri::getRelativeUri | ||
| 489 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 490 | */ | ||
| 491 | public function testGetRelativeUriWithExplicitTrailingSlash(): void | ||
| 492 |     { | ||
| 493 |         $uri = new Uri('http://example.com/'); | ||
| 494 | |||
| 495 |         self::assertSame('/', $uri->getRelativeUri()); | ||
| 496 | } | ||
| 497 | |||
| 498 | /** | ||
| 499 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 500 | * @covers \OAuth\Common\Http\Uri\Uri::__toString | ||
| 501 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 502 | */ | ||
| 503 | public function testToStringBare(): void | ||
| 504 |     { | ||
| 505 |         $uri = new Uri('http://example.com'); | ||
| 506 | |||
| 507 |         self::assertSame('http://example.com', (string) $uri); | ||
| 508 | } | ||
| 509 | |||
| 510 | /** | ||
| 511 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 512 | * @covers \OAuth\Common\Http\Uri\Uri::__toString | ||
| 513 | * @covers \OAuth\Common\Http\Uri\Uri::getRawAuthority | ||
| 514 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 515 | * @covers \OAuth\Common\Http\Uri\Uri::protectUserInfo | ||
| 516 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 517 | */ | ||
| 518 | public function testToStringWithAuthority(): void | ||
| 519 |     { | ||
| 520 |         $uri = new Uri('http://peehaa:[email protected]'); | ||
| 521 | |||
| 522 |         self::assertSame('http://peehaa:********@example.com', (string) $uri); | ||
| 523 | } | ||
| 524 | |||
| 525 | /** | ||
| 526 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 527 | * @covers \OAuth\Common\Http\Uri\Uri::__toString | ||
| 528 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 529 | */ | ||
| 530 | public function testToStringWithPath(): void | ||
| 531 |     { | ||
| 532 |         $uri = new Uri('http://example.com/foo'); | ||
| 533 | |||
| 534 |         self::assertSame('http://example.com/foo', (string) $uri); | ||
| 535 | } | ||
| 536 | |||
| 537 | /** | ||
| 538 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 539 | * @covers \OAuth\Common\Http\Uri\Uri::__toString | ||
| 540 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 541 | */ | ||
| 542 | public function testToStringWithoutPath(): void | ||
| 543 |     { | ||
| 544 |         $uri = new Uri('http://example.com'); | ||
| 545 | |||
| 546 |         self::assertSame('http://example.com', (string) $uri); | ||
| 547 | } | ||
| 548 | |||
| 549 | /** | ||
| 550 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 551 | * @covers \OAuth\Common\Http\Uri\Uri::__toString | ||
| 552 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 553 | */ | ||
| 554 | public function testToStringWithoutPathExplicitTrailingSlash(): void | ||
| 559 | } | ||
| 560 | |||
| 561 | /** | ||
| 562 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 563 | * @covers \OAuth\Common\Http\Uri\Uri::__toString | ||
| 564 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 565 | */ | ||
| 566 | public function testToStringWithQuery(): void | ||
| 567 |     { | ||
| 568 |         $uri = new Uri('http://example.com?param1=value1'); | ||
| 569 | |||
| 570 |         self::assertSame('http://example.com?param1=value1', (string) $uri); | ||
| 571 | } | ||
| 572 | |||
| 573 | /** | ||
| 574 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 575 | * @covers \OAuth\Common\Http\Uri\Uri::__toString | ||
| 576 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 577 | */ | ||
| 578 | public function testToStringWithFragment(): void | ||
| 579 |     { | ||
| 580 |         $uri = new Uri('http://example.com#foo'); | ||
| 581 | |||
| 582 |         self::assertSame('http://example.com#foo', (string) $uri); | ||
| 583 | } | ||
| 584 | |||
| 585 | /** | ||
| 586 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 587 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 588 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 589 | * @covers \OAuth\Common\Http\Uri\Uri::setPath | ||
| 590 | */ | ||
| 591 | public function testSetPathEmpty(): void | ||
| 592 |     { | ||
| 593 |         $uri = new Uri('http://example.com'); | ||
| 594 |         $uri->setPath(''); | ||
| 595 | |||
| 596 |         self::assertSame('http://example.com', $uri->getAbsoluteUri()); | ||
| 597 | } | ||
| 598 | |||
| 599 | /** | ||
| 600 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 601 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 602 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 603 | * @covers \OAuth\Common\Http\Uri\Uri::setPath | ||
| 604 | */ | ||
| 605 | public function testSetPathWithPath(): void | ||
| 606 |     { | ||
| 607 |         $uri = new Uri('http://example.com'); | ||
| 608 |         $uri->setPath('/foo'); | ||
| 609 | |||
| 610 |         self::assertSame('http://example.com/foo', $uri->getAbsoluteUri()); | ||
| 611 | } | ||
| 612 | |||
| 613 | /** | ||
| 614 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 615 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 616 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 617 | * @covers \OAuth\Common\Http\Uri\Uri::setPath | ||
| 618 | */ | ||
| 619 | public function testSetPathWithOnlySlash(): void | ||
| 620 |     { | ||
| 621 |         $uri = new Uri('http://example.com'); | ||
| 622 |         $uri->setPath('/'); | ||
| 623 | |||
| 624 |         self::assertSame('http://example.com/', $uri->getAbsoluteUri()); | ||
| 625 | } | ||
| 626 | |||
| 627 | /** | ||
| 628 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 629 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 630 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 631 | * @covers \OAuth\Common\Http\Uri\Uri::setQuery | ||
| 632 | */ | ||
| 633 | public function testSetQueryEmpty(): void | ||
| 634 |     { | ||
| 635 |         $uri = new Uri('http://example.com'); | ||
| 636 |         $uri->setQuery(''); | ||
| 637 | |||
| 638 |         self::assertSame('http://example.com', $uri->getAbsoluteUri()); | ||
| 639 | } | ||
| 640 | |||
| 641 | /** | ||
| 642 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 643 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 644 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 645 | * @covers \OAuth\Common\Http\Uri\Uri::setQuery | ||
| 646 | */ | ||
| 647 | public function testSetQueryFilled(): void | ||
| 648 |     { | ||
| 649 |         $uri = new Uri('http://example.com'); | ||
| 650 |         $uri->setQuery('param1=value1¶m2=value2'); | ||
| 651 | |||
| 652 |         self::assertSame('http://example.com?param1=value1¶m2=value2', $uri->getAbsoluteUri()); | ||
| 653 | } | ||
| 654 | |||
| 655 | /** | ||
| 656 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 657 | * @covers \OAuth\Common\Http\Uri\Uri::addToQuery | ||
| 658 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 659 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 660 | */ | ||
| 661 | public function testAddToQueryAppend(): void | ||
| 662 |     { | ||
| 663 |         $uri = new Uri('http://example.com?param1=value1'); | ||
| 664 |         $uri->addToQuery('param2', 'value2'); | ||
| 665 | |||
| 666 |         self::assertSame('http://example.com?param1=value1¶m2=value2', $uri->getAbsoluteUri()); | ||
| 667 | } | ||
| 668 | |||
| 669 | /** | ||
| 670 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 671 | * @covers \OAuth\Common\Http\Uri\Uri::addToQuery | ||
| 672 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 673 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 674 | */ | ||
| 675 | public function testAddToQueryCreate(): void | ||
| 676 |     { | ||
| 677 |         $uri = new Uri('http://example.com'); | ||
| 678 |         $uri->addToQuery('param1', 'value1'); | ||
| 679 | |||
| 680 |         self::assertSame('http://example.com?param1=value1', $uri->getAbsoluteUri()); | ||
| 681 | } | ||
| 682 | |||
| 683 | /** | ||
| 684 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 685 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 686 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 687 | * @covers \OAuth\Common\Http\Uri\Uri::setFragment | ||
| 688 | */ | ||
| 689 | public function testSetFragmentEmpty(): void | ||
| 690 |     { | ||
| 691 |         $uri = new Uri('http://example.com'); | ||
| 692 |         $uri->setFragment(''); | ||
| 693 | |||
| 694 |         self::assertSame('http://example.com', $uri->getAbsoluteUri()); | ||
| 695 | } | ||
| 696 | |||
| 697 | /** | ||
| 698 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 699 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 700 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 701 | * @covers \OAuth\Common\Http\Uri\Uri::setFragment | ||
| 702 | */ | ||
| 703 | public function testSetFragmentWithData(): void | ||
| 704 |     { | ||
| 705 |         $uri = new Uri('http://example.com'); | ||
| 706 |         $uri->setFragment('foo'); | ||
| 707 | |||
| 708 |         self::assertSame('http://example.com#foo', $uri->getAbsoluteUri()); | ||
| 709 | } | ||
| 710 | |||
| 711 | /** | ||
| 712 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 713 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 714 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 715 | * @covers \OAuth\Common\Http\Uri\Uri::setScheme | ||
| 716 | */ | ||
| 717 | public function testSetSchemeWithEmpty(): void | ||
| 718 |     { | ||
| 719 |         $uri = new Uri('http://example.com'); | ||
| 720 |         $uri->setScheme(''); | ||
| 721 | |||
| 722 |         self::assertSame('://example.com', $uri->getAbsoluteUri()); | ||
| 723 | } | ||
| 724 | |||
| 725 | /** | ||
| 726 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 727 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 728 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 729 | * @covers \OAuth\Common\Http\Uri\Uri::setScheme | ||
| 730 | */ | ||
| 731 | public function testSetSchemeWithData(): void | ||
| 732 |     { | ||
| 733 |         $uri = new Uri('http://example.com'); | ||
| 734 |         $uri->setScheme('foo'); | ||
| 735 | |||
| 736 |         self::assertSame('foo://example.com', $uri->getAbsoluteUri()); | ||
| 737 | } | ||
| 738 | |||
| 739 | /** | ||
| 740 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 741 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 742 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 743 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 744 | */ | ||
| 745 | public function testSetUserInfoEmpty(): void | ||
| 746 |     { | ||
| 747 |         $uri = new Uri('http://example.com'); | ||
| 748 |         $uri->setUserInfo(''); | ||
| 749 | |||
| 750 |         self::assertSame('http://example.com', $uri->getAbsoluteUri()); | ||
| 751 | } | ||
| 752 | |||
| 753 | /** | ||
| 754 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 755 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 756 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 757 | * @covers \OAuth\Common\Http\Uri\Uri::protectUserInfo | ||
| 758 | * @covers \OAuth\Common\Http\Uri\Uri::setUserInfo | ||
| 759 | */ | ||
| 760 | public function testSetUserInfoWithData(): void | ||
| 761 |     { | ||
| 762 |         $uri = new Uri('http://example.com'); | ||
| 763 |         $uri->setUserInfo('foo:bar'); | ||
| 764 | |||
| 765 |         self::assertSame('http://foo:[email protected]', $uri->getAbsoluteUri()); | ||
| 766 | } | ||
| 767 | |||
| 768 | /** | ||
| 769 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 770 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 771 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 772 | * @covers \OAuth\Common\Http\Uri\Uri::setPort | ||
| 773 | */ | ||
| 774 | public function testSetPortCustom(): void | ||
| 775 |     { | ||
| 776 |         $uri = new Uri('http://example.com'); | ||
| 777 |         $uri->setPort('21'); | ||
| 778 | |||
| 779 |         self::assertSame('http://example.com:21', $uri->getAbsoluteUri()); | ||
| 780 | } | ||
| 781 | |||
| 782 | /** | ||
| 783 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 784 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 785 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 786 | * @covers \OAuth\Common\Http\Uri\Uri::setPort | ||
| 787 | */ | ||
| 788 | public function testSetPortHttpImplicit(): void | ||
| 789 |     { | ||
| 790 |         $uri = new Uri('http://example.com'); | ||
| 791 | $uri->setPort(80); | ||
| 792 | |||
| 793 |         self::assertSame('http://example.com', $uri->getAbsoluteUri()); | ||
| 794 | } | ||
| 795 | |||
| 796 | /** | ||
| 797 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 798 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 799 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 800 | * @covers \OAuth\Common\Http\Uri\Uri::setPort | ||
| 801 | */ | ||
| 802 | public function testSetPortHttpsImplicit(): void | ||
| 803 |     { | ||
| 804 |         $uri = new Uri('https://example.com'); | ||
| 805 | $uri->setPort(443); | ||
| 806 | |||
| 807 |         self::assertSame('https://example.com', $uri->getAbsoluteUri()); | ||
| 808 | } | ||
| 809 | |||
| 810 | /** | ||
| 811 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 812 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 813 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 814 | * @covers \OAuth\Common\Http\Uri\Uri::setPort | ||
| 815 | */ | ||
| 816 | public function testSetPortHttpExplicit(): void | ||
| 817 |     { | ||
| 818 |         $uri = new Uri('http://example.com'); | ||
| 819 | $uri->setPort(443); | ||
| 820 | |||
| 821 |         self::assertSame('http://example.com:443', $uri->getAbsoluteUri()); | ||
| 822 | } | ||
| 823 | |||
| 824 | /** | ||
| 825 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 826 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 827 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 828 | * @covers \OAuth\Common\Http\Uri\Uri::setPort | ||
| 829 | */ | ||
| 830 | public function testSetPortHttpsExplicit(): void | ||
| 831 |     { | ||
| 832 |         $uri = new Uri('https://example.com'); | ||
| 833 | $uri->setPort(80); | ||
| 834 | |||
| 835 |         self::assertSame('https://example.com:80', $uri->getAbsoluteUri()); | ||
| 836 | } | ||
| 837 | |||
| 838 | /** | ||
| 839 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 840 | * @covers \OAuth\Common\Http\Uri\Uri::getAbsoluteUri | ||
| 841 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 842 | * @covers \OAuth\Common\Http\Uri\Uri::setHost | ||
| 843 | */ | ||
| 844 | public function testSetHost(): void | ||
| 845 |     { | ||
| 846 |         $uri = new Uri('http://example.com'); | ||
| 847 |         $uri->setHost('pieterhordijk.com'); | ||
| 848 | |||
| 849 |         self::assertSame('http://pieterhordijk.com', $uri->getAbsoluteUri()); | ||
| 850 | } | ||
| 851 | |||
| 852 | /** | ||
| 853 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 854 | * @covers \OAuth\Common\Http\Uri\Uri::hasExplicitTrailingHostSlash | ||
| 855 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 856 | */ | ||
| 857 | public function testHasExplicitTrailingHostSlashTrue(): void | ||
| 862 | } | ||
| 863 | |||
| 864 | /** | ||
| 865 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 866 | * @covers \OAuth\Common\Http\Uri\Uri::hasExplicitTrailingHostSlash | ||
| 867 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 868 | */ | ||
| 869 | public function testHasExplicitTrailingHostSlashFalse(): void | ||
| 870 |     { | ||
| 871 |         $uri = new Uri('http://example.com/foo'); | ||
| 872 | |||
| 873 | self::assertFalse($uri->hasExplicitTrailingHostSlash()); | ||
| 874 | } | ||
| 875 | |||
| 876 | /** | ||
| 877 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 878 | * @covers \OAuth\Common\Http\Uri\Uri::hasExplicitPortSpecified | ||
| 879 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 880 | */ | ||
| 881 | public function testHasExplicitPortSpecifiedTrue(): void | ||
| 886 | } | ||
| 887 | |||
| 888 | /** | ||
| 889 | * @covers \OAuth\Common\Http\Uri\Uri::__construct | ||
| 890 | * @covers \OAuth\Common\Http\Uri\Uri::hasExplicitPortSpecified | ||
| 891 | * @covers \OAuth\Common\Http\Uri\Uri::parseUri | ||
| 892 | */ | ||
| 893 | public function testHasExplicitPortSpecifiedFalse(): void | ||
| 894 |     { | ||
| 895 |         $uri = new Uri('http://example.com'); | ||
| 896 | |||
| 897 | self::assertFalse($uri->hasExplicitPortSpecified()); | ||
| 898 | } | ||
| 899 | } | ||
| 900 |