Skip to content

Commit 1321531

Browse files
committed
Code standards
* Add missing documentation. * Re-order methods to move public first.
1 parent ff1f370 commit 1321531

File tree

1 file changed

+100
-82
lines changed

1 file changed

+100
-82
lines changed

src/Redirects.php

Lines changed: 100 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,122 @@
11
<?php
2+
/**
3+
* Redirects module for Codeception.
4+
*
5+
* @package gamajo\codeception-redirects
6+
* @author Gary Jones
7+
* @copyright 2016 Gamajo Tech
8+
* @license MIT
9+
*/
210

311
namespace Codeception\Module;
412

513
use Codeception\Module;
614

7-
class Redirects extends Module{
8-
15+
/**
16+
* Class Redirects
17+
*
18+
* @package Codeception\Module
19+
* @author Gary Jones
20+
*/
21+
class Redirects extends Module
22+
{
923
/**
10-
* Protocol constants that can be used with permanentRedirectForProtocol() method.
24+
* Protocol (http) constant that can be used with permanentRedirectForProtocol() method.
1125
*/
1226
const PROTOCOL_HTTP = 'http';
27+
28+
/**
29+
* Protocol (https) constant that can be used with permanentRedirectForProtocol() method.
30+
*/
1331
const PROTOCOL_HTTPS = 'https';
1432

15-
/**
16-
* Check that a 301 HTTP Status is returned with the correct Location URL.
17-
*
18-
* @since 0.1.0
19-
*
20-
* @param string $url Relative or absolute URL of redirect destination.
21-
*/
22-
public function seePermanentRedirectTo($url)
23-
{
24-
$response = $this->getModule('PhpBrowser')->client->getInternalResponse();
25-
$responseCode = $response->getStatus();
26-
$locationHeader = $response->getHeader('Location', true);
33+
/**
34+
* Toggle redirections on and off.
35+
*
36+
* By default, BrowserKit will follow redirections, so to check for 30*
37+
* HTTP status codes and Location headers, they have to be turned off.
38+
*
39+
* @since 0.1.0
40+
*
41+
* @param bool $followRedirects Optional. Whether to follow redirects or not.
42+
* Default is true.
43+
*/
44+
public function followRedirects($followRedirects = true)
45+
{
46+
$this->getModule('PhpBrowser')->client->followRedirects($followRedirects);
47+
}
2748

28-
// Check for 301 response code.
29-
$this->assertEquals(301, $responseCode);
49+
/**
50+
* Check that a 200 HTTP Status is returned with the correct Location URL.
51+
*
52+
* Should be HTTP.
53+
*
54+
* @since 0.1.0
55+
*
56+
* @param string $url Relative or absolute URL of redirect destination.
57+
*/
58+
public function seePermanentRedirectToHttpFor($url)
59+
{
60+
$this->permanentRedirectForProtocol($url, self::PROTOCOL_HTTP);
61+
}
3062

31-
// Check location header URL contains submitted URL.
32-
$this->assertContains($url, $locationHeader);
33-
}
63+
/**
64+
* Check that a 301 HTTP Status is returned with the correct Location URL.
65+
*
66+
* @since 0.1.0
67+
*
68+
* @param string $url Relative or absolute URL of redirect destination.
69+
*/
70+
public function seePermanentRedirectTo($url)
71+
{
72+
$response = $this->getModule('PhpBrowser')->client->getInternalResponse();
73+
$responseCode = $response->getStatus();
74+
$locationHeader = $response->getHeader('Location', true);
3475

35-
/**
36-
* Check that a 200 HTTP Status is returned with the correct Location URL.
37-
*
38-
* Should be HTTPS.
39-
*
40-
* @since 0.1.0
41-
*
42-
* @param string $url Relative or absolute URL of redirect destination.
43-
*/
44-
public function seePermanentRedirectToHttpsFor($url)
45-
{
46-
$this->permanentRedirectForProtocol($url, self::PROTOCOL_HTTPS);
47-
}
76+
// Check for 301 response code.
77+
$this->assertEquals(301, $responseCode);
4878

49-
/**
50-
* Check that a 200 HTTP Status is returned with the correct Location URL.
51-
*
52-
* Should be HTTP.
53-
*
54-
* @since 0.1.0
55-
*
56-
* @param string $url Relative or absolute URL of redirect destination.
57-
*/
58-
public function seePermanentRedirectToHttpFor($url)
59-
{
60-
$this->permanentRedirectForProtocol($url, self::PROTOCOL_HTTP);
61-
}
79+
// Check location header URL contains submitted URL.
80+
$this->assertContains($url, $locationHeader);
81+
}
6282

63-
/**
64-
* Toggle redirections on and off.
65-
*
66-
* By default, BrowserKit will follow redirections, so to check for 30*
67-
* HTTP status codes and Location headers, they have to be turned off.
68-
*
69-
* @since 0.1.0
70-
*
71-
* @param bool $followRedirects Optional. Whether to follow redirects or not.
72-
* Default is true.
73-
*/
74-
public function followRedirects($followRedirects = true)
75-
{
76-
$this->getModule('PhpBrowser')->client->followRedirects($followRedirects);
77-
}
83+
/**
84+
* Check that a 200 HTTP Status is returned with the correct Location URL.
85+
*
86+
* Should be HTTPS.
87+
*
88+
* @since 0.1.0
89+
*
90+
* @param string $url Relative or absolute URL of redirect destination.
91+
*/
92+
public function seePermanentRedirectToHttpsFor($url)
93+
{
94+
$this->permanentRedirectForProtocol($url, self::PROTOCOL_HTTPS);
95+
}
7896

79-
/**
80-
* Check that a 200 HTTP Status is returned with the correct Location URL.
81-
*
82-
* @param string $url Relative or absolute URL of redirect destination.
83-
* @param string $protocol Protocol: 'http' or 'https'.
84-
*/
85-
protected function permanentRedirectForProtocol($url, $protocol)
86-
{
87-
$url = ltrim($url, '/');
88-
$this->getModule('REST')->sendHead($url);
97+
/**
98+
* Check that a 200 HTTP Status is returned with the correct Location URL.
99+
*
100+
* @param string $url Relative or absolute URL of redirect destination.
101+
* @param string $protocol Protocol: 'http' or 'https'.
102+
*/
103+
protected function permanentRedirectForProtocol($url, $protocol)
104+
{
105+
$url = ltrim($url, '/');
106+
$this->getModule('REST')->sendHead($url);
89107

90-
$client = $this->getModule('PhpBrowser')->client;
91-
$responseCode = $client->getInternalResponse()->getStatus();
92-
$responseUri = $client->getHistory()->current()->getUri();
93-
$scheme = parse_url($responseUri, PHP_URL_SCHEME);
108+
$client = $this->getModule('PhpBrowser')->client;
109+
$responseCode = $client->getInternalResponse()->getStatus();
110+
$responseUri = $client->getHistory()->current()->getUri();
111+
$scheme = parse_url($responseUri, PHP_URL_SCHEME);
94112

95-
// Check for 200 response code.
96-
$this->assertEquals(200, $responseCode);
113+
// Check for 200 response code.
114+
$this->assertEquals(200, $responseCode);
97115

98-
// Check for submitted http/https value matches destination URL.
99-
$this->assertEquals($protocol, $scheme);
116+
// Check for submitted http/https value matches destination URL.
117+
$this->assertEquals($protocol, $scheme);
100118

101-
// Check that destination URL contains submitted URL part.
102-
$this->assertContains($url, $responseUri);
103-
}
119+
// Check that destination URL contains submitted URL part.
120+
$this->assertContains($url, $responseUri);
121+
}
104122
}

0 commit comments

Comments
 (0)