diff --git a/.gitignore b/.gitignore index 19d1aff..8c97686 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ tests/cov/ # Composer binaries bin/phpunit bin/phpcs +bin/php-cs-fixer +bin/sabre-cs-fixer # Vim .*.swp diff --git a/.travis.yml b/.travis.yml index 37f4b24..2589790 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,4 +23,4 @@ before_script: script: - ./bin/phpunit --configuration tests/phpunit.xml - - ./bin/phpcs -p --standard=tests/phpcs/ruleset.xml lib/ + - ./bin/sabre-cs-fixer fix lib/ --dry-run --diff diff --git a/CHANGELOG.md b/CHANGELOG.md index 450b3a7..b515304 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ChangeLog * #45: Don't send more data than what is promised in the HTTP content-length. (@dratini0). * #43: `getCredentials` returns null if incomplete. (@Hywan) +* #48: Now using php-cs-fixer to make our CS consistent (yay!) * This includes fixes released in version 3.0.5. diff --git a/composer.json b/composer.json index 54e0999..5c22e55 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ }, "require-dev" : { "phpunit/phpunit" : "~4.3", - "squizlabs/php_codesniffer": "~1.5.3" + "sabre/cs" : "~0.0.1" }, "suggest" : { "ext-curl" : " to make http requests with the Client class" diff --git a/lib/Auth/AWS.php b/lib/Auth/AWS.php index 34c11c8..0c4a8a5 100644 --- a/lib/Auth/AWS.php +++ b/lib/Auth/AWS.php @@ -54,14 +54,14 @@ class AWS extends AbstractAuth { function init() { $authHeader = $this->request->getHeader('Authorization'); - $authHeader = explode(' ',$authHeader); + $authHeader = explode(' ', $authHeader); - if ($authHeader[0]!='AWS' || !isset($authHeader[1])) { + if ($authHeader[0] != 'AWS' || !isset($authHeader[1])) { $this->errorCode = self::ERR_NOAWSHEADER; return false; } - list($this->accessKey,$this->signature) = explode(':',$authHeader[1]); + list($this->accessKey, $this->signature) = explode(':', $authHeader[1]); return true; @@ -91,9 +91,9 @@ function validate($secretKey) { if ($contentMD5) { // We need to validate the integrity of the request $body = $this->request->getBody(true); - $this->request->setBody($body,true); + $this->request->setBody($body, true); - if ($contentMD5!=base64_encode(md5($body,true))) { + if ($contentMD5 != base64_encode(md5($body, true))) { // content-md5 header did not match md5 signature of body $this->errorCode = self::ERR_MD5CHECKSUMWRONG; return false; @@ -141,7 +141,7 @@ function validate($secretKey) { */ function requireLogin() { - $this->response->addHeader('WWW-Authenticate','AWS'); + $this->response->addHeader('WWW-Authenticate', 'AWS'); $this->response->setStatus(401); } @@ -191,15 +191,15 @@ protected function getAmzHeaders() { $amzHeaders = []; $headers = $this->request->getHeaders(); foreach($headers as $headerName => $headerValue) { - if (strpos(strtolower($headerName),'x-amz-')===0) { - $amzHeaders[strtolower($headerName)] = str_replace( ["\r\n"], [' '],$headerValue[0]) . "\n"; + if (strpos(strtolower($headerName), 'x-amz-') === 0) { + $amzHeaders[strtolower($headerName)] = str_replace(["\r\n"], [' '], $headerValue[0]) . "\n"; } } ksort($amzHeaders); $headerStr = ''; - foreach($amzHeaders as $h=>$v) { - $headerStr.=$h.':'.$v; + foreach($amzHeaders as $h => $v) { + $headerStr .= $h . ':' . $v; } return $headerStr; @@ -219,14 +219,14 @@ private function hmacsha1($key, $message) { return hash_hmac('sha1', $message, $key, true); } - $blocksize=64; - if (strlen($key)>$blocksize) { - $key=pack('H*', sha1($key)); + $blocksize = 64; + if (strlen($key) > $blocksize) { + $key = pack('H*', sha1($key)); } - $key=str_pad($key,$blocksize,chr(0x00)); - $ipad=str_repeat(chr(0x36),$blocksize); - $opad=str_repeat(chr(0x5c),$blocksize); - $hmac = pack('H*',sha1(($key^$opad).pack('H*',sha1(($key^$ipad).$message)))); + $key = str_pad($key, $blocksize, chr(0x00)); + $ipad = str_repeat(chr(0x36), $blocksize); + $opad = str_repeat(chr(0x5c), $blocksize); + $hmac = pack('H*', sha1(($key ^ $opad) . pack('H*', sha1(($key ^ $ipad) . $message)))); return $hmac; } diff --git a/lib/Auth/AbstractAuth.php b/lib/Auth/AbstractAuth.php index 914d638..a883dba 100644 --- a/lib/Auth/AbstractAuth.php +++ b/lib/Auth/AbstractAuth.php @@ -2,9 +2,8 @@ namespace Sabre\HTTP\Auth; -use - Sabre\HTTP\RequestInterface, - Sabre\HTTP\ResponseInterface; +use Sabre\HTTP\RequestInterface; +use Sabre\HTTP\ResponseInterface; /** * HTTP Authentication base class. diff --git a/lib/Auth/Basic.php b/lib/Auth/Basic.php index ae30e8a..2fe5229 100644 --- a/lib/Auth/Basic.php +++ b/lib/Auth/Basic.php @@ -33,11 +33,11 @@ function getCredentials() { return null; } - if (strtolower(substr($auth,0,6))!=='basic ') { + if (strtolower(substr($auth, 0, 6)) !== 'basic ') { return null; } - $credentials = explode(':',base64_decode(substr($auth, 6)), 2); + $credentials = explode(':', base64_decode(substr($auth, 6)), 2); if (2 !== count($credentials)) { return null; @@ -55,7 +55,7 @@ function getCredentials() { */ function requireLogin() { - $this->response->addHeader('WWW-Authenticate','Basic realm="' . $this->realm . '"'); + $this->response->addHeader('WWW-Authenticate', 'Basic realm="' . $this->realm . '"'); $this->response->setStatus(401); } diff --git a/lib/Auth/Digest.php b/lib/Auth/Digest.php index 3701d55..59c216c 100644 --- a/lib/Auth/Digest.php +++ b/lib/Auth/Digest.php @@ -2,9 +2,8 @@ namespace Sabre\HTTP\Auth; -use - Sabre\HTTP\RequestInterface, - Sabre\HTTP\ResponseInterface; +use Sabre\HTTP\RequestInterface; +use Sabre\HTTP\ResponseInterface; /** * HTTP Digest Authentication handler @@ -138,7 +137,7 @@ protected function validate() { $A2 = $this->request->getMethod() . ':' . $this->digestParts['uri']; - if ($this->digestParts['qop']=='auth-int') { + if ($this->digestParts['qop'] == 'auth-int') { // Making sure we support this qop value if (!($this->qop & self::QOP_AUTHINT)) return false; // We need to add an md5 of the entire request body to the A2 part of the hash @@ -155,7 +154,7 @@ protected function validate() { $validResponse = md5("{$this->A1}:{$this->digestParts['nonce']}:{$this->digestParts['nc']}:{$this->digestParts['cnonce']}:{$this->digestParts['qop']}:{$A2}"); - return $this->digestParts['response']==$validResponse; + return $this->digestParts['response'] == $validResponse; } @@ -182,7 +181,7 @@ function requireLogin() { break; } - $this->response->addHeader('WWW-Authenticate','Digest realm="' . $this->realm . '",qop="'.$qop.'",nonce="' . $this->nonce . '",opaque="' . $this->opaque . '"'); + $this->response->addHeader('WWW-Authenticate', 'Digest realm="' . $this->realm . '",qop="' . $qop . '",nonce="' . $this->nonce . '",opaque="' . $this->opaque . '"'); $this->response->setStatus(401); } @@ -215,7 +214,7 @@ function getDigest() { protected function parseDigest($digest) { // protect against missing data - $needed_parts = ['nonce'=>1, 'nc'=>1, 'cnonce'=>1, 'qop'=>1, 'username'=>1, 'uri'=>1, 'response'=>1]; + $needed_parts = ['nonce' => 1, 'nc' => 1, 'cnonce' => 1, 'qop' => 1, 'username' => 1, 'uri' => 1, 'response' => 1]; $data = []; preg_match_all('@(\w+)=(?:(?:")([^"]+)"|([^\s,$]+))@', $digest, $matches, PREG_SET_ORDER); diff --git a/lib/Client.php b/lib/Client.php index 42ef01a..398c298 100644 --- a/lib/Client.php +++ b/lib/Client.php @@ -72,8 +72,8 @@ function __construct() { $this->curlSettings = [ CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => true, - CURLOPT_NOBODY => false, + CURLOPT_HEADER => true, + CURLOPT_NOBODY => false, ]; } @@ -100,7 +100,7 @@ function send(RequestInterface $request) { $response = $this->doRequest($request); - $code = (int) $response->getStatus(); + $code = (int)$response->getStatus(); // We are doing in-PHP redirects, because curl's // FOLLOW_LOCATION throws errors when PHP is configured with @@ -428,7 +428,7 @@ protected function createCurlSettingsArray(RequestInterface $request) { } $nHeaders = []; - foreach($request->getHeaders() as $key=>$values) { + foreach($request->getHeaders() as $key => $values) { foreach($values as $value) { $nHeaders[] = $key . ': ' . $value; @@ -483,8 +483,8 @@ protected function parseCurlResult($response, $curlHandle) { if ($curlErrNo) { return [ - 'status' => self::STATUS_CURLERROR, - 'curl_errno' => $curlErrNo, + 'status' => self::STATUS_CURLERROR, + 'curl_errno' => $curlErrNo, 'curl_errmsg' => $curlErrMsg, ]; } @@ -503,7 +503,7 @@ protected function parseCurlResult($response, $curlHandle) { $headerBlob = explode("\r\n\r\n", trim($headerBlob, "\r\n")); // We only care about the last set of headers - $headerBlob = $headerBlob[count($headerBlob)-1]; + $headerBlob = $headerBlob[count($headerBlob) - 1]; // Splitting headers $headerBlob = explode("\r\n", $headerBlob); @@ -513,7 +513,7 @@ protected function parseCurlResult($response, $curlHandle) { foreach($headerBlob as $header) { $parts = explode(':', $header, 2); - if (count($parts)==2) { + if (count($parts) == 2) { $response->addHeader(trim($parts[0]), trim($parts[1])); } } diff --git a/lib/Request.php b/lib/Request.php index 5c277a1..05e7aa3 100644 --- a/lib/Request.php +++ b/lib/Request.php @@ -107,10 +107,10 @@ function setUrl($url) { function getQueryParameters() { $url = $this->getUrl(); - if (($index = strpos($url,'?'))===false) { + if (($index = strpos($url, '?')) === false) { return []; } else { - parse_str(substr($url, $index+1), $queryParams); + parse_str(substr($url, $index + 1), $queryParams); return $queryParams; } @@ -191,21 +191,21 @@ function getBaseUrl() { function getPath() { // Removing duplicated slashes. - $uri = str_replace('//','/',$this->getUrl()); + $uri = str_replace('//', '/', $this->getUrl()); $uri = Uri\normalize($uri); $baseUri = Uri\normalize($this->getBaseUrl()); - if (strpos($uri,$baseUri)===0) { + if (strpos($uri, $baseUri) === 0) { // We're not interested in the query part (everything after the ?). list($uri) = explode('?', $uri); - return trim(URLUtil::decodePath(substr($uri,strlen($baseUri))),'/'); + return trim(URLUtil::decodePath(substr($uri, strlen($baseUri))), '/'); } // A special case, if the baseUri was accessed without a trailing // slash, we'll accept it as well. - elseif ($uri.'/' === $baseUri) { + elseif ($uri . '/' === $baseUri) { return ''; @@ -297,10 +297,10 @@ function __toString() { $out = $this->getMethod() . ' ' . $this->getUrl() . ' HTTP/' . $this->getHTTPVersion() . "\r\n"; - foreach($this->getHeaders() as $key=>$value) { + foreach($this->getHeaders() as $key => $value) { foreach($value as $v) { - if ($key==='Authorization') { - list($v) = explode(' ', $v,2); + if ($key === 'Authorization') { + list($v) = explode(' ', $v, 2); $v .= ' REDACTED'; } $out .= $key . ": " . $v . "\r\n"; diff --git a/lib/Response.php b/lib/Response.php index d9aa076..1c65a22 100644 --- a/lib/Response.php +++ b/lib/Response.php @@ -153,7 +153,7 @@ function setStatus($status) { if (ctype_digit($status) || is_int($status)) { $statusCode = $status; - $statusText = isset(self::$statusCodes[$status])?self::$statusCodes[$status]:'Unknown'; + $statusText = isset(self::$statusCodes[$status]) ? self::$statusCodes[$status] : 'Unknown'; } else { list( @@ -180,13 +180,13 @@ function setStatus($status) { function __toString() { $str = 'HTTP/' . $this->httpVersion . ' ' . $this->getStatus() . ' ' . $this->getStatusText() . "\r\n"; - foreach($this->getHeaders() as $key=>$value) { + foreach($this->getHeaders() as $key => $value) { foreach($value as $v) { - $str.= $key . ": " . $v . "\r\n"; + $str .= $key . ": " . $v . "\r\n"; } } - $str.="\r\n"; - $str.=$this->getBodyAsString(); + $str .= "\r\n"; + $str .= $this->getBodyAsString(); return $str; } diff --git a/lib/Sapi.php b/lib/Sapi.php index f0d5e8b..0568dd0 100644 --- a/lib/Sapi.php +++ b/lib/Sapi.php @@ -39,7 +39,7 @@ class Sapi { static function getRequest() { $r = self::createFromServerArray($_SERVER); - $r->setBody(fopen('php://input','r')); + $r->setBody(fopen('php://input', 'r')); $r->setPostData($_POST); return $r; @@ -56,9 +56,9 @@ static function getRequest() { static function sendResponse(ResponseInterface $response) { header('HTTP/' . $response->getHttpVersion() . ' ' . $response->getStatus() . ' ' . $response->getStatusText()); - foreach($response->getHeaders() as $key=>$value) { + foreach($response->getHeaders() as $key => $value) { - foreach($value as $k=>$v) { + foreach($value as $k => $v) { if ($k === 0) { header($key . ': ' . $v); } else { @@ -102,12 +102,12 @@ static function createFromServerArray(array $serverArray) { $protocol = 'http'; $hostName = 'localhost'; - foreach($serverArray as $key=>$value) { + foreach($serverArray as $key => $value) { switch($key) { case 'SERVER_PROTOCOL' : - if ($value==='HTTP/1.0') { + if ($value === 'HTTP/1.0') { $httpVersion = '1.0'; } break; @@ -151,17 +151,17 @@ static function createFromServerArray(array $serverArray) { break; case 'HTTPS' : - if (!empty($value) && $value!=='off') { + if (!empty($value) && $value !== 'off') { $protocol = 'https'; } break; default : - if (substr($key,0,5)==='HTTP_') { + if (substr($key, 0, 5) === 'HTTP_') { // It's a HTTP header // Normalizing it to be prettier - $header = strtolower(substr($key,5)); + $header = strtolower(substr($key, 5)); // Transforming dashes into spaces, and uppercasing // every first letter. diff --git a/lib/URLUtil.php b/lib/URLUtil.php index bc5d216..b597c74 100644 --- a/lib/URLUtil.php +++ b/lib/URLUtil.php @@ -32,9 +32,9 @@ class URLUtil { */ static function encodePath($path) { - return preg_replace_callback('/([^A-Za-z0-9_\-\.~\(\)\/:@])/',function($match) { + return preg_replace_callback('/([^A-Za-z0-9_\-\.~\(\)\/:@])/', function($match) { - return '%'.sprintf('%02x',ord($match[0])); + return '%' . sprintf('%02x', ord($match[0])); }, $path); @@ -50,9 +50,9 @@ static function encodePath($path) { */ static function encodePathSegment($pathSegment) { - return preg_replace_callback('/([^A-Za-z0-9_\-\.~\(\):@])/',function($match) { + return preg_replace_callback('/([^A-Za-z0-9_\-\.~\(\):@])/', function($match) { - return '%'.sprintf('%02x',ord($match[0])); + return '%' . sprintf('%02x', ord($match[0])); }, $pathSegment); } @@ -78,7 +78,7 @@ static function decodePath($path) { static function decodePathSegment($path) { $path = rawurldecode($path); - $encoding = mb_detect_encoding($path, ['UTF-8','ISO-8859-1']); + $encoding = mb_detect_encoding($path, ['UTF-8', 'ISO-8859-1']); switch($encoding) { diff --git a/lib/Util.php b/lib/Util.php index 5136f14..0b1bb7a 100644 --- a/lib/Util.php +++ b/lib/Util.php @@ -160,8 +160,8 @@ static function negotiateContentType($acceptHeaderValue, array $availableOptions // subtype. We need to calculate a score for how specific the // match was. $specificity = - ($proposal['type']!=='*'?20:0) + - ($proposal['subType']!=='*'?10:0) + + ($proposal['type'] !== '*' ? 20 : 0) + + ($proposal['subType'] !== '*' ? 10 : 0) + count($option['parameters']); @@ -210,7 +210,7 @@ private static function parseMimeType($str) { $mimeType = array_shift($parts); $mimeType = explode('/', trim($mimeType)); - if (count($mimeType)!==2) { + if (count($mimeType) !== 2) { // Illegal value return null; } @@ -231,7 +231,7 @@ private static function parseMimeType($str) { // the parameter list. Anything after the q= counts as an // 'accept extension' and could introduce new semantics in // content-negotation. - if ($partName!=='q') { + if ($partName !== 'q') { $parameters[$partName] = $part; } else { $quality = (float)$partValue; @@ -241,9 +241,9 @@ private static function parseMimeType($str) { } return [ - 'type' => $type, - 'subType' => $subType, - 'quality' => $quality, + 'type' => $type, + 'subType' => $subType, + 'quality' => $quality, 'parameters' => $parameters, ]; diff --git a/tests/HTTP/Auth/AWSTest.php b/tests/HTTP/Auth/AWSTest.php index 5979c2a..8f4d6ce 100644 --- a/tests/HTTP/Auth/AWSTest.php +++ b/tests/HTTP/Auth/AWSTest.php @@ -2,9 +2,8 @@ namespace Sabre\HTTP\Auth; -use - Sabre\HTTP\Request, - Sabre\HTTP\Response; +use Sabre\HTTP\Request; +use Sabre\HTTP\Response; class AWSTest extends \PHPUnit_Framework_TestCase { @@ -25,7 +24,7 @@ class AWSTest extends \PHPUnit_Framework_TestCase { const REALM = 'SabreDAV unittest'; - public function setUp() { + function setUp() { $this->response = new Response(); $this->request = new Request(); @@ -33,17 +32,17 @@ public function setUp() { } - public function testNoHeader() { + function testNoHeader() { $this->request->setMethod('GET'); $result = $this->auth->init(); - $this->assertFalse($result,'No AWS Authorization header was supplied, so we should have gotten false'); - $this->assertEquals(AWS::ERR_NOAWSHEADER,$this->auth->errorCode); + $this->assertFalse($result, 'No AWS Authorization header was supplied, so we should have gotten false'); + $this->assertEquals(AWS::ERR_NOAWSHEADER, $this->auth->errorCode); } - public function testIncorrectContentMD5() { + function testIncorrectContentMD5() { $accessKey = 'accessKey'; $secretKey = 'secretKey'; @@ -59,16 +58,16 @@ public function testIncorrectContentMD5() { $result = $this->auth->validate($secretKey); $this->assertFalse($result); - $this->assertEquals(AWS::ERR_MD5CHECKSUMWRONG,$this->auth->errorCode); + $this->assertEquals(AWS::ERR_MD5CHECKSUMWRONG, $this->auth->errorCode); } - public function testNoDate() { + function testNoDate() { $accessKey = 'accessKey'; $secretKey = 'secretKey'; $content = 'thisisthebody'; - $contentMD5 = base64_encode(md5($content,true)); + $contentMD5 = base64_encode(md5($content, true)); $this->request->setMethod('POST'); $this->request->setHeaders([ @@ -82,18 +81,18 @@ public function testNoDate() { $result = $this->auth->validate($secretKey); $this->assertFalse($result); - $this->assertEquals(AWS::ERR_INVALIDDATEFORMAT,$this->auth->errorCode); + $this->assertEquals(AWS::ERR_INVALIDDATEFORMAT, $this->auth->errorCode); } - public function testFutureDate() { + function testFutureDate() { $accessKey = 'accessKey'; $secretKey = 'secretKey'; $content = 'thisisthebody'; - $contentMD5 = base64_encode(md5($content,true)); + $contentMD5 = base64_encode(md5($content, true)); - $date = new \DateTime('@' . (time() + (60*20))); + $date = new \DateTime('@' . (time() + (60 * 20))); $date->setTimeZone(new \DateTimeZone('GMT')); $date = $date->format('D, d M Y H:i:s \\G\\M\\T'); @@ -110,18 +109,18 @@ public function testFutureDate() { $result = $this->auth->validate($secretKey); $this->assertFalse($result); - $this->assertEquals(AWS::ERR_REQUESTTIMESKEWED,$this->auth->errorCode); + $this->assertEquals(AWS::ERR_REQUESTTIMESKEWED, $this->auth->errorCode); } - public function testPastDate() { + function testPastDate() { $accessKey = 'accessKey'; $secretKey = 'secretKey'; $content = 'thisisthebody'; - $contentMD5 = base64_encode(md5($content,true)); + $contentMD5 = base64_encode(md5($content, true)); - $date = new \DateTime('@' . (time() - (60*20))); + $date = new \DateTime('@' . (time() - (60 * 20))); $date->setTimeZone(new \DateTimeZone('GMT')); $date = $date->format('D, d M Y H:i:s \\G\\M\\T'); @@ -138,17 +137,17 @@ public function testPastDate() { $result = $this->auth->validate($secretKey); $this->assertFalse($result); - $this->assertEquals(AWS::ERR_REQUESTTIMESKEWED,$this->auth->errorCode); + $this->assertEquals(AWS::ERR_REQUESTTIMESKEWED, $this->auth->errorCode); } - public function testIncorrectSignature() { + function testIncorrectSignature() { $accessKey = 'accessKey'; $secretKey = 'secretKey'; $content = 'thisisthebody'; - $contentMD5 = base64_encode(md5($content,true)); + $contentMD5 = base64_encode(md5($content, true)); $date = new \DateTime('now'); $date->setTimeZone(new \DateTimeZone('GMT')); @@ -169,16 +168,16 @@ public function testIncorrectSignature() { $result = $this->auth->validate($secretKey); $this->assertFalse($result); - $this->assertEquals(AWS::ERR_INVALIDSIGNATURE,$this->auth->errorCode); + $this->assertEquals(AWS::ERR_INVALIDSIGNATURE, $this->auth->errorCode); } - public function testValidRequest() { + function testValidRequest() { $accessKey = 'accessKey'; $secretKey = 'secretKey'; $content = 'thisisthebody'; - $contentMD5 = base64_encode(md5($content,true)); + $contentMD5 = base64_encode(md5($content, true)); $date = new \DateTime('now'); $date->setTimeZone(new \DateTimeZone('GMT')); @@ -202,16 +201,16 @@ public function testValidRequest() { $this->auth->init(); $result = $this->auth->validate($secretKey); - $this->assertTrue($result,'Signature did not validate, got errorcode ' . $this->auth->errorCode); - $this->assertEquals($accessKey,$this->auth->getAccessKey()); + $this->assertTrue($result, 'Signature did not validate, got errorcode ' . $this->auth->errorCode); + $this->assertEquals($accessKey, $this->auth->getAccessKey()); } - public function test401() { + function test401() { $this->auth->requireLogin(); - $test = preg_match('/^AWS$/',$this->response->getHeader('WWW-Authenticate'),$matches); - $this->assertTrue($test==true,'The WWW-Authenticate response didn\'t match our pattern'); + $test = preg_match('/^AWS$/', $this->response->getHeader('WWW-Authenticate'), $matches); + $this->assertTrue($test == true, 'The WWW-Authenticate response didn\'t match our pattern'); } @@ -224,13 +223,13 @@ public function test401() { */ private function hmacsha1($key, $message) { - $blocksize=64; - if (strlen($key)>$blocksize) - $key=pack('H*', sha1($key)); - $key=str_pad($key,$blocksize,chr(0x00)); - $ipad=str_repeat(chr(0x36),$blocksize); - $opad=str_repeat(chr(0x5c),$blocksize); - $hmac = pack('H*',sha1(($key^$opad).pack('H*',sha1(($key^$ipad).$message)))); + $blocksize = 64; + if (strlen($key) > $blocksize) + $key = pack('H*', sha1($key)); + $key = str_pad($key, $blocksize, chr(0x00)); + $ipad = str_repeat(chr(0x36), $blocksize); + $opad = str_repeat(chr(0x5c), $blocksize); + $hmac = pack('H*', sha1(($key ^ $opad) . pack('H*', sha1(($key ^ $ipad) . $message)))); return $hmac; } diff --git a/tests/HTTP/Auth/BasicTest.php b/tests/HTTP/Auth/BasicTest.php index 8a512b9..cd5d83e 100644 --- a/tests/HTTP/Auth/BasicTest.php +++ b/tests/HTTP/Auth/BasicTest.php @@ -9,24 +9,24 @@ class BasicTest extends \PHPUnit_Framework_TestCase { function testGetCredentials() { - $request = new Request('GET','/',array( + $request = new Request('GET', '/', [ 'Authorization' => 'Basic ' . base64_encode('user:pass:bla') - )); + ]); $basic = new Basic('Dagger', $request, new Response()); - $this->assertEquals(array( + $this->assertEquals([ 'user', 'pass:bla', - ), $basic->getCredentials($request)); + ], $basic->getCredentials($request)); } function testGetInvalidCredentialsColonMissing() { - $request = new Request('GET','/',array( + $request = new Request('GET', '/', [ 'Authorization' => 'Basic ' . base64_encode('userpass') - )); + ]); $basic = new Basic('Dagger', $request, new Response()); @@ -36,7 +36,7 @@ function testGetInvalidCredentialsColonMissing() { function testGetCredentialsNoheader() { - $request = new Request('GET','/',array()); + $request = new Request('GET', '/', []); $basic = new Basic('Dagger', $request, new Response()); $this->assertNull($basic->getCredentials($request)); @@ -45,9 +45,9 @@ function testGetCredentialsNoheader() { function testGetCredentialsNotBasic() { - $request = new Request('GET','/',array( + $request = new Request('GET', '/', [ 'Authorization' => 'QBasic ' . base64_encode('user:pass:bla') - )); + ]); $basic = new Basic('Dagger', $request, new Response()); $this->assertNull($basic->getCredentials($request)); diff --git a/tests/HTTP/Auth/DigestTest.php b/tests/HTTP/Auth/DigestTest.php index 2e7122f..b4753e2 100644 --- a/tests/HTTP/Auth/DigestTest.php +++ b/tests/HTTP/Auth/DigestTest.php @@ -2,9 +2,8 @@ namespace Sabre\HTTP\Auth; -use - Sabre\HTTP\Request, - Sabre\HTTP\Response; +use Sabre\HTTP\Request; +use Sabre\HTTP\Response; class DigestTest extends \PHPUnit_Framework_TestCase { @@ -27,7 +26,7 @@ class DigestTest extends \PHPUnit_Framework_TestCase { const REALM = 'SabreDAV unittest'; - public function setUp() { + function setUp() { $this->response = new Response(); $this->request = new Request(); @@ -36,9 +35,9 @@ public function setUp() { } - public function testDigest() { + function testDigest() { - list($nonce,$opaque) = $this->getServerTokens(); + list($nonce, $opaque) = $this->getServerTokens(); $username = 'admin'; $password = 12345; @@ -55,20 +54,20 @@ public function testDigest() { ); $this->request->setMethod('GET'); - $this->request->setHeader('Authorization','Digest username="'.$username.'", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth,nc='.$nc.',cnonce="' . $cnonce . '"'); + $this->request->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth,nc=' . $nc . ',cnonce="' . $cnonce . '"'); $this->auth->init(); - $this->assertEquals($username,$this->auth->getUserName()); - $this->assertEquals(self::REALM,$this->auth->getRealm()); - $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)),'Authentication is deemed invalid through validateA1'); - $this->assertTrue($this->auth->validatePassword($password),'Authentication is deemed invalid through validatePassword'); + $this->assertEquals($username, $this->auth->getUserName()); + $this->assertEquals(self::REALM, $this->auth->getRealm()); + $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)), 'Authentication is deemed invalid through validateA1'); + $this->assertTrue($this->auth->validatePassword($password), 'Authentication is deemed invalid through validatePassword'); } - public function testInvalidDigest() { + function testInvalidDigest() { - list($nonce,$opaque) = $this->getServerTokens(); + list($nonce, $opaque) = $this->getServerTokens(); $username = 'admin'; $password = 12345; @@ -85,18 +84,18 @@ public function testInvalidDigest() { ); $this->request->setMethod('GET'); - $this->request->setHeader('Authorization', 'Digest username="'.$username.'", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth,nc='.$nc.',cnonce="' . $cnonce . '"'); + $this->request->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth,nc=' . $nc . ',cnonce="' . $cnonce . '"'); $this->auth->init(); - $this->assertFalse($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . ($password . 'randomness'))),'Authentication is deemed invalid through validateA1'); + $this->assertFalse($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . ($password . 'randomness'))), 'Authentication is deemed invalid through validateA1'); } - public function testInvalidDigest2() { + function testInvalidDigest2() { $this->request->setMethod('GET'); - $this->request->setHeader('Authorization','basic blablabla'); + $this->request->setHeader('Authorization', 'basic blablabla'); $this->auth->init(); $this->assertFalse($this->auth->validateA1(md5('user:realm:password'))); @@ -104,10 +103,10 @@ public function testInvalidDigest2() { } - public function testDigestAuthInt() { + function testDigestAuthInt() { $this->auth->setQOP(Digest::QOP_AUTHINT); - list($nonce,$opaque) = $this->getServerTokens(Digest::QOP_AUTHINT); + list($nonce, $opaque) = $this->getServerTokens(Digest::QOP_AUTHINT); $username = 'admin'; $password = 12345; @@ -124,19 +123,19 @@ public function testDigestAuthInt() { ); $this->request->setMethod('POST'); - $this->request->setHeader('Authorization','Digest username="'.$username.'", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth-int,nc='.$nc.',cnonce="' . $cnonce . '"'); + $this->request->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth-int,nc=' . $nc . ',cnonce="' . $cnonce . '"'); $this->request->setBody('body'); $this->auth->init(); - $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)),'Authentication is deemed invalid through validateA1'); + $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)), 'Authentication is deemed invalid through validateA1'); } - public function testDigestAuthBoth() { + function testDigestAuthBoth() { $this->auth->setQOP(Digest::QOP_AUTHINT | Digest::QOP_AUTH); - list($nonce,$opaque) = $this->getServerTokens(Digest::QOP_AUTHINT| Digest::QOP_AUTH); + list($nonce, $opaque) = $this->getServerTokens(Digest::QOP_AUTHINT | Digest::QOP_AUTH); $username = 'admin'; $password = 12345; @@ -153,12 +152,12 @@ public function testDigestAuthBoth() { ); $this->request->setMethod('POST'); - $this->request->setHeader('Authorization','Digest username="'.$username.'", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth-int,nc='.$nc.',cnonce="' . $cnonce . '"'); + $this->request->setHeader('Authorization', 'Digest username="' . $username . '", realm="' . self::REALM . '", nonce="' . $nonce . '", uri="/", response="' . $digestHash . '", opaque="' . $opaque . '", qop=auth-int,nc=' . $nc . ',cnonce="' . $cnonce . '"'); $this->request->setBody('body'); $this->auth->init(); - $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)),'Authentication is deemed invalid through validateA1'); + $this->assertTrue($this->auth->validateA1(md5($username . ':' . self::REALM . ':' . $password)), 'Authentication is deemed invalid through validateA1'); } @@ -168,15 +167,15 @@ private function getServerTokens($qop = Digest::QOP_AUTH) { $this->auth->requireLogin(); switch($qop) { - case Digest::QOP_AUTH : $qopstr='auth'; break; - case Digest::QOP_AUTHINT : $qopstr='auth-int'; break; - default : $qopstr='auth,auth-int'; break; + case Digest::QOP_AUTH : $qopstr = 'auth'; break; + case Digest::QOP_AUTHINT : $qopstr = 'auth-int'; break; + default : $qopstr = 'auth,auth-int'; break; } - $test = preg_match('/Digest realm="'.self::REALM.'",qop="'.$qopstr.'",nonce="([0-9a-f]*)",opaque="([0-9a-f]*)"/', - $this->response->getHeader('WWW-Authenticate'),$matches); + $test = preg_match('/Digest realm="' . self::REALM . '",qop="' . $qopstr . '",nonce="([0-9a-f]*)",opaque="([0-9a-f]*)"/', + $this->response->getHeader('WWW-Authenticate'), $matches); - $this->assertTrue($test==true,'The WWW-Authenticate response didn\'t match our pattern. We received: ' . $this->response->getHeader('WWW-Authenticate')); + $this->assertTrue($test == true, 'The WWW-Authenticate response didn\'t match our pattern. We received: ' . $this->response->getHeader('WWW-Authenticate')); $nonce = $matches[1]; $opaque = $matches[2]; @@ -185,7 +184,7 @@ private function getServerTokens($qop = Digest::QOP_AUTH) { $this->setUp(); $this->auth->setQOP($qop); - return array($nonce,$opaque); + return [$nonce,$opaque]; } diff --git a/tests/HTTP/ClientTest.php b/tests/HTTP/ClientTest.php index 0c661bc..8424bb4 100644 --- a/tests/HTTP/ClientTest.php +++ b/tests/HTTP/ClientTest.php @@ -11,18 +11,18 @@ function testCreateCurlSettingsArrayGET() { $client = new ClientMock(); $client->addCurlSetting(CURLOPT_POSTREDIR, 0); - $request = new Request('GET','http://example.org/', ['X-Foo' => 'bar']); + $request = new Request('GET', 'http://example.org/', ['X-Foo' => 'bar']); $settings = [ CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => true, - CURLOPT_POSTREDIR => 0, - CURLOPT_HTTPHEADER => ['X-Foo: bar'], - CURLOPT_NOBODY => false, - CURLOPT_URL => 'http://example.org/', - CURLOPT_CUSTOMREQUEST => 'GET', - CURLOPT_POSTFIELDS => null, - CURLOPT_PUT => false, + CURLOPT_HEADER => true, + CURLOPT_POSTREDIR => 0, + CURLOPT_HTTPHEADER => ['X-Foo: bar'], + CURLOPT_NOBODY => false, + CURLOPT_URL => 'http://example.org/', + CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_POSTFIELDS => null, + CURLOPT_PUT => false, ]; // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM @@ -40,18 +40,18 @@ function testCreateCurlSettingsArrayGET() { function testCreateCurlSettingsArrayHEAD() { $client = new ClientMock(); - $request = new Request('HEAD','http://example.org/', ['X-Foo' => 'bar']); + $request = new Request('HEAD', 'http://example.org/', ['X-Foo' => 'bar']); $settings = [ CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => true, - CURLOPT_NOBODY => true, - CURLOPT_CUSTOMREQUEST => 'HEAD', - CURLOPT_HTTPHEADER => ['X-Foo: bar'], - CURLOPT_URL => 'http://example.org/', - CURLOPT_POSTFIELDS => '', - CURLOPT_PUT => false, + CURLOPT_HEADER => true, + CURLOPT_NOBODY => true, + CURLOPT_CUSTOMREQUEST => 'HEAD', + CURLOPT_HTTPHEADER => ['X-Foo: bar'], + CURLOPT_URL => 'http://example.org/', + CURLOPT_POSTFIELDS => '', + CURLOPT_PUT => false, ]; // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM @@ -68,7 +68,7 @@ function testCreateCurlSettingsArrayHEAD() { function testCreateCurlSettingsArrayGETAfterHEAD() { $client = new ClientMock(); - $request = new Request('HEAD','http://example.org/', ['X-Foo' => 'bar']); + $request = new Request('HEAD', 'http://example.org/', ['X-Foo' => 'bar']); // Parsing the settings for this method, and discarding the result. // This will cause the client to automatically persist previous @@ -76,17 +76,17 @@ function testCreateCurlSettingsArrayGETAfterHEAD() { $client->createCurlSettingsArray($request); // This is the real request. - $request = new Request('GET','http://example.org/', ['X-Foo' => 'bar']); + $request = new Request('GET', 'http://example.org/', ['X-Foo' => 'bar']); $settings = [ - CURLOPT_CUSTOMREQUEST => 'GET', + CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => true, - CURLOPT_HTTPHEADER => ['X-Foo: bar'], - CURLOPT_NOBODY => false, - CURLOPT_URL => 'http://example.org/', - CURLOPT_POSTFIELDS => '', - CURLOPT_PUT => false, + CURLOPT_HEADER => true, + CURLOPT_HTTPHEADER => ['X-Foo: bar'], + CURLOPT_NOBODY => false, + CURLOPT_URL => 'http://example.org/', + CURLOPT_POSTFIELDS => '', + CURLOPT_PUT => false, ]; // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM @@ -106,17 +106,17 @@ function testCreateCurlSettingsArrayPUTStream() { $h = fopen('php://memory', 'r+'); fwrite($h, 'booh'); - $request = new Request('PUT','http://example.org/', ['X-Foo' => 'bar'], $h); + $request = new Request('PUT', 'http://example.org/', ['X-Foo' => 'bar'], $h); $settings = [ CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => true, - CURLOPT_PUT => true, - CURLOPT_INFILE => $h, - CURLOPT_NOBODY => false, - CURLOPT_CUSTOMREQUEST => 'PUT', - CURLOPT_HTTPHEADER => ['X-Foo: bar'], - CURLOPT_URL => 'http://example.org/', + CURLOPT_HEADER => true, + CURLOPT_PUT => true, + CURLOPT_INFILE => $h, + CURLOPT_NOBODY => false, + CURLOPT_CUSTOMREQUEST => 'PUT', + CURLOPT_HTTPHEADER => ['X-Foo: bar'], + CURLOPT_URL => 'http://example.org/', ]; // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM @@ -133,16 +133,16 @@ function testCreateCurlSettingsArrayPUTStream() { function testCreateCurlSettingsArrayPUTString() { $client = new ClientMock(); - $request = new Request('PUT','http://example.org/', ['X-Foo' => 'bar'], 'boo'); + $request = new Request('PUT', 'http://example.org/', ['X-Foo' => 'bar'], 'boo'); $settings = [ CURLOPT_RETURNTRANSFER => true, - CURLOPT_HEADER => true, - CURLOPT_NOBODY => false, - CURLOPT_POSTFIELDS => 'boo', - CURLOPT_CUSTOMREQUEST => 'PUT', - CURLOPT_HTTPHEADER => ['X-Foo: bar'], - CURLOPT_URL => 'http://example.org/', + CURLOPT_HEADER => true, + CURLOPT_NOBODY => false, + CURLOPT_POSTFIELDS => 'boo', + CURLOPT_CUSTOMREQUEST => 'PUT', + CURLOPT_HTTPHEADER => ['X-Foo: bar'], + CURLOPT_URL => 'http://example.org/', ]; // FIXME: CURLOPT_PROTOCOLS and CURLOPT_REDIR_PROTOCOLS are currently unsupported by HHVM @@ -177,7 +177,7 @@ function testSendClientError() { $request = new Request('GET', 'http://example.org/'); $client->on('doRequest', function($request, &$response) { - throw new ClientException('aaah',1); + throw new ClientException('aaah', 1); }); $called = false; $client->on('exception', function() use (&$called) { @@ -211,7 +211,7 @@ function testSendHttpError() { }); $client->send($request); - $this->assertEquals(2,$called); + $this->assertEquals(2, $called); } @@ -239,8 +239,8 @@ function testSendRetry() { }); $response = $client->send($request); - $this->assertEquals(3,$called); - $this->assertEquals(2,$errorCalled); + $this->assertEquals(3, $called); + $this->assertEquals(2, $errorCalled); $this->assertEquals(200, $response->getStatus()); } @@ -273,7 +273,7 @@ function testParseCurlResult() { $return = [ [ 'header_size' => 33, - 'http_code' => 200, + 'http_code' => 200, ], 0, '', @@ -328,7 +328,7 @@ function testDoRequest() { $return = [ [ 'header_size' => 33, - 'http_code' => 200, + 'http_code' => 200, ], 0, '', @@ -387,7 +387,7 @@ class ClientMock extends Client { * methods after subsequent use. * forces */ - public function createCurlSettingsArray(RequestInterface $request) { + function createCurlSettingsArray(RequestInterface $request) { $settings = parent::createCurlSettingsArray($request); $settings = $settings + $this->persistedSettings; @@ -398,7 +398,7 @@ public function createCurlSettingsArray(RequestInterface $request) { /** * Making this method public. */ - public function parseCurlResult($response, $curlHandle) { + function parseCurlResult($response, $curlHandle) { return parent::parseCurlResult($response, $curlHandle); @@ -410,7 +410,7 @@ public function parseCurlResult($response, $curlHandle) { * @param RequestInterface $request * @return ResponseInterface */ - public function doRequest(RequestInterface $request) { + function doRequest(RequestInterface $request) { $response = null; $this->emit('doRequest', [$request, &$response]); diff --git a/tests/HTTP/MessageDecoratorTest.php b/tests/HTTP/MessageDecoratorTest.php index 64dd4dc..6e2074c 100644 --- a/tests/HTTP/MessageDecoratorTest.php +++ b/tests/HTTP/MessageDecoratorTest.php @@ -61,14 +61,14 @@ function testHeader() { $this->assertEquals('c', $this->inner->getHeader('A')); $this->assertEquals('c', $this->outer->getHeader('A')); - $this->outer->addHeader('A','d'); + $this->outer->addHeader('A', 'd'); $this->assertEquals( - ['c','d'], + ['c', 'd'], $this->inner->getHeaderAsArray('A') ); $this->assertEquals( - ['c','d'], + ['c', 'd'], $this->outer->getHeaderAsArray('A') ); diff --git a/tests/HTTP/MessageTest.php b/tests/HTTP/MessageTest.php index 64bcd26..15703a6 100644 --- a/tests/HTTP/MessageTest.php +++ b/tests/HTTP/MessageTest.php @@ -93,7 +93,7 @@ function testSetHeaders() { $this->assertEquals($headers, $message->getHeaders()); $message->setHeaders([ - 'X-Foo' => ['3','4'], + 'X-Foo' => ['3', '4'], 'X-Bar' => '5', ]); @@ -119,7 +119,7 @@ function testAddHeaders() { $this->assertEquals($headers, $message->getHeaders()); $message->addHeaders([ - 'X-Foo' => ['3','4'], + 'X-Foo' => ['3', '4'], 'X-Bar' => '5', ]); @@ -140,8 +140,8 @@ function testSendBody() { $message->setBody('foo'); // Stream - $h = fopen('php://memory','r+'); - fwrite($h,'bar'); + $h = fopen('php://memory', 'r+'); + fwrite($h, 'bar'); rewind($h); $message->setBody($h); @@ -168,11 +168,11 @@ function testMultipleHeaders() { ); $this->assertEquals( - ['1','2'], + ['1', '2'], $message->getHeaderAsArray('a') ); $this->assertEquals( - ['1','2'], + ['1', '2'], $message->getHeaderAsArray('A') ); $this->assertEquals( diff --git a/tests/HTTP/RequestDecoratorTest.php b/tests/HTTP/RequestDecoratorTest.php index 9f1c03c..08af487 100644 --- a/tests/HTTP/RequestDecoratorTest.php +++ b/tests/HTTP/RequestDecoratorTest.php @@ -103,7 +103,7 @@ function testToString() { $this->inner->setMethod('POST'); $this->inner->setUrl('/foo/bar/'); $this->inner->setBody('foo'); - $this->inner->setHeader('foo','bar'); + $this->inner->setHeader('foo', 'bar'); $this->assertEquals((string)$this->inner, (string)$this->outer); diff --git a/tests/HTTP/RequestTest.php b/tests/HTTP/RequestTest.php index 80e4bfd..e3daab4 100644 --- a/tests/HTTP/RequestTest.php +++ b/tests/HTTP/RequestTest.php @@ -6,14 +6,14 @@ class RequestTest extends \PHPUnit_Framework_TestCase { function testConstruct() { - $request = new Request('GET', '/foo', array( + $request = new Request('GET', '/foo', [ 'User-Agent' => 'Evert', - )); + ]); $this->assertEquals('GET', $request->getMethod()); $this->assertEquals('/foo', $request->getUrl()); - $this->assertEquals(array( + $this->assertEquals([ 'User-Agent' => ['Evert'], - ), $request->getHeaders()); + ], $request->getHeaders()); } @@ -50,7 +50,7 @@ function testCreateFromPHPRequest() { function testGetAbsoluteUrl() { $s = [ - 'HTTP_HOST' => 'sabredav.org', + 'HTTP_HOST' => 'sabredav.org', 'REQUEST_URI' => '/foo' ]; @@ -160,7 +160,7 @@ function testToStringAuthorization() { */ function testConstructorWithArray() { - $request = new Request(array()); + $request = new Request([]); } diff --git a/tests/HTTP/ResponseDecoratorTest.php b/tests/HTTP/ResponseDecoratorTest.php index 0a1b18d..838953b 100644 --- a/tests/HTTP/ResponseDecoratorTest.php +++ b/tests/HTTP/ResponseDecoratorTest.php @@ -28,7 +28,7 @@ function testToString() { $this->inner->setStatus(201); $this->inner->setBody('foo'); - $this->inner->setHeader('foo','bar'); + $this->inner->setHeader('foo', 'bar'); $this->assertEquals((string)$this->inner, (string)$this->outer); diff --git a/tests/HTTP/SapiTest.php b/tests/HTTP/SapiTest.php index 0e5caf1..2dae3e0 100644 --- a/tests/HTTP/SapiTest.php +++ b/tests/HTTP/SapiTest.php @@ -6,22 +6,22 @@ class SapiTest extends \PHPUnit_Framework_TestCase { function testConstructFromServerArray() { - $request = Sapi::createFromServerArray(array( + $request = Sapi::createFromServerArray([ 'REQUEST_URI' => '/foo', 'REQUEST_METHOD' => 'GET', 'HTTP_USER_AGENT' => 'Evert', 'CONTENT_TYPE' => 'text/xml', 'CONTENT_LENGTH' => '400', 'SERVER_PROTOCOL' => 'HTTP/1.0', - )); + ]); $this->assertEquals('GET', $request->getMethod()); $this->assertEquals('/foo', $request->getUrl()); - $this->assertEquals(array( - 'User-Agent' => ['Evert'], - 'Content-Type' => ['text/xml'], + $this->assertEquals([ + 'User-Agent' => ['Evert'], + 'Content-Type' => ['text/xml'], 'Content-Length' => ['400'], - ), $request->getHeaders()); + ], $request->getHeaders()); $this->assertEquals('1.0', $request->getHttpVersion()); @@ -32,50 +32,50 @@ function testConstructFromServerArray() { function testConstructPHPAuth() { - $request = Sapi::createFromServerArray(array( + $request = Sapi::createFromServerArray([ 'REQUEST_URI' => '/foo', 'REQUEST_METHOD' => 'GET', 'PHP_AUTH_USER' => 'user', 'PHP_AUTH_PW' => 'pass', - )); + ]); $this->assertEquals('GET', $request->getMethod()); $this->assertEquals('/foo', $request->getUrl()); - $this->assertEquals(array( + $this->assertEquals([ 'Authorization' => ['Basic ' . base64_encode('user:pass')], - ), $request->getHeaders()); + ], $request->getHeaders()); } function testConstructPHPAuthDigest() { - $request = Sapi::createFromServerArray(array( + $request = Sapi::createFromServerArray([ 'REQUEST_URI' => '/foo', 'REQUEST_METHOD' => 'GET', 'PHP_AUTH_DIGEST' => 'blabla', - )); + ]); $this->assertEquals('GET', $request->getMethod()); $this->assertEquals('/foo', $request->getUrl()); - $this->assertEquals(array( + $this->assertEquals([ 'Authorization' => ['Digest blabla'], - ), $request->getHeaders()); + ], $request->getHeaders()); } function testConstructRedirectAuth() { - $request = Sapi::createFromServerArray(array( + $request = Sapi::createFromServerArray([ 'REQUEST_URI' => '/foo', 'REQUEST_METHOD' => 'GET', 'REDIRECT_HTTP_AUTHORIZATION' => 'Basic bla', - )); + ]); $this->assertEquals('GET', $request->getMethod()); $this->assertEquals('/foo', $request->getUrl()); - $this->assertEquals(array( + $this->assertEquals([ 'Authorization' => ['Basic bla'], - ), $request->getHeaders()); + ], $request->getHeaders()); } diff --git a/tests/HTTP/URLUtilTest.php b/tests/HTTP/URLUtilTest.php index 01474ef..e80c830 100644 --- a/tests/HTTP/URLUtilTest.php +++ b/tests/HTTP/URLUtilTest.php @@ -7,46 +7,46 @@ class URLUtilTest extends \PHPUnit_Framework_TestCase{ function testEncodePath() { $str = ''; - for($i=0;$i<128;$i++) $str.=chr($i); + for($i = 0;$i < 128;$i++) $str .= chr($i); $newStr = URLUtil::encodePath($str); $this->assertEquals( - '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f'. - '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f'. - '%20%21%22%23%24%25%26%27()%2a%2b%2c-./'. - '0123456789:%3b%3c%3d%3e%3f'. + '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f' . + '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f' . + '%20%21%22%23%24%25%26%27()%2a%2b%2c-./' . + '0123456789:%3b%3c%3d%3e%3f' . '@ABCDEFGHIJKLMNO' . 'PQRSTUVWXYZ%5b%5c%5d%5e_' . '%60abcdefghijklmno' . 'pqrstuvwxyz%7b%7c%7d~%7f', $newStr); - $this->assertEquals($str,URLUtil::decodePath($newStr)); + $this->assertEquals($str, URLUtil::decodePath($newStr)); } function testEncodePathSegment() { $str = ''; - for($i=0;$i<128;$i++) $str.=chr($i); + for($i = 0;$i < 128;$i++) $str .= chr($i); $newStr = URLUtil::encodePathSegment($str); // Note: almost exactly the same as the last test, with the // exception of the encoding of / (ascii code 2f) $this->assertEquals( - '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f'. - '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f'. - '%20%21%22%23%24%25%26%27()%2a%2b%2c-.%2f'. - '0123456789:%3b%3c%3d%3e%3f'. + '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f' . + '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f' . + '%20%21%22%23%24%25%26%27()%2a%2b%2c-.%2f' . + '0123456789:%3b%3c%3d%3e%3f' . '@ABCDEFGHIJKLMNO' . 'PQRSTUVWXYZ%5b%5c%5d%5e_' . '%60abcdefghijklmno' . 'pqrstuvwxyz%7b%7c%7d~%7f', $newStr); - $this->assertEquals($str,URLUtil::decodePathSegment($newStr)); + $this->assertEquals($str, URLUtil::decodePathSegment($newStr)); } @@ -54,7 +54,7 @@ function testDecode() { $str = 'Hello%20Test+Test2.txt'; $newStr = URLUtil::decodePath($str); - $this->assertEquals('Hello Test+Test2.txt',$newStr); + $this->assertEquals('Hello Test+Test2.txt', $newStr); } @@ -65,7 +65,7 @@ function testDecodeUmlaut() { $str = 'Hello%C3%BC.txt'; $newStr = URLUtil::decodePath($str); - $this->assertEquals("Hello\xC3\xBC.txt",$newStr); + $this->assertEquals("Hello\xC3\xBC.txt", $newStr); } @@ -76,7 +76,7 @@ function testDecodeUmlautLatin1() { $str = 'Hello%FC.txt'; $newStr = URLUtil::decodePath($str); - $this->assertEquals("Hello\xC3\xBC.txt",$newStr); + $this->assertEquals("Hello\xC3\xBC.txt", $newStr); } @@ -89,33 +89,33 @@ function testDecodeAccentsWindows7() { $str = '/webdav/%C3%A0fo%C3%B3'; $newStr = URLUtil::decodePath($str); - $this->assertEquals(strtolower($str),URLUtil::encodePath($newStr)); + $this->assertEquals(strtolower($str), URLUtil::encodePath($newStr)); } function testSplitPath() { - $strings = array( + $strings = [ // input // expected result - '/foo/bar' => array('/foo','bar'), - '/foo/bar/' => array('/foo','bar'), - 'foo/bar/' => array('foo','bar'), - 'foo/bar' => array('foo','bar'), - 'foo/bar/baz' => array('foo/bar','baz'), - 'foo/bar/baz/' => array('foo/bar','baz'), - 'foo' => array('','foo'), - 'foo/' => array('','foo'), - '/foo/' => array('','foo'), - '/foo' => array('','foo'), - '' => array(null,null), + '/foo/bar' => ['/foo','bar'], + '/foo/bar/' => ['/foo','bar'], + 'foo/bar/' => ['foo','bar'], + 'foo/bar' => ['foo','bar'], + 'foo/bar/baz' => ['foo/bar','baz'], + 'foo/bar/baz/' => ['foo/bar','baz'], + 'foo' => ['','foo'], + 'foo/' => ['','foo'], + '/foo/' => ['','foo'], + '/foo' => ['','foo'], + '' => [null,null], // UTF-8 - "/\xC3\xA0fo\xC3\xB3/bar" => array("/\xC3\xA0fo\xC3\xB3",'bar'), - "/\xC3\xA0foo/b\xC3\xBCr/" => array("/\xC3\xA0foo","b\xC3\xBCr"), - "foo/\xC3\xA0\xC3\xBCr" => array("foo","\xC3\xA0\xC3\xBCr"), + "/\xC3\xA0fo\xC3\xB3/bar" => ["/\xC3\xA0fo\xC3\xB3",'bar'], + "/\xC3\xA0foo/b\xC3\xBCr/" => ["/\xC3\xA0foo","b\xC3\xBCr"], + "foo/\xC3\xA0\xC3\xBCr" => ["foo","\xC3\xA0\xC3\xBCr"], - ); + ]; foreach($strings as $input => $expected) { diff --git a/tests/HTTP/UtilTest.php b/tests/HTTP/UtilTest.php index 447c899..0047c21 100644 --- a/tests/HTTP/UtilTest.php +++ b/tests/HTTP/UtilTest.php @@ -6,11 +6,11 @@ class UtilTest extends \PHPUnit_Framework_TestCase { function testParseHTTPDate() { - $times = array( + $times = [ 'Wed, 13 Oct 2010 10:26:00 GMT', 'Wednesday, 13-Oct-10 10:26:00 GMT', 'Wed Oct 13 10:26:00 2010', - ); + ]; $expected = 1286965560; @@ -26,7 +26,7 @@ function testParseHTTPDate() { function testParseHTTPDateFail() { - $times = array( + $times = [ //random string 'NOW', // not-GMT timezone @@ -43,7 +43,7 @@ function testParseHTTPDateFail() { 'Wed, 13 Oct 2010 24:26:00 GMT', 'Wednesday, 13-Oct-10 24:26:00 GMT', 'Wed Oct 13 24:26:00 2010', - ); + ]; foreach($times as $time) { $this->assertFalse(Util::parseHTTPDate($time), 'We used the string: ' . $time); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 0a544fa..74931b6 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -6,4 +6,3 @@ // Composer autoloader include __DIR__ . '/../vendor/autoload.php'; -