Skip to content

Commit

Permalink
version 0.5.0
Browse files Browse the repository at this point in the history
updates namespace structure
updates test coverage and coverage reporting
  • Loading branch information
sndsgd committed Jan 12, 2015
1 parent 82bfe61 commit a94ebea
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 59 deletions.
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ php:
- 5.4
- 5.5
- 5.6
- hhvm
- hhvm-nightly

before_install:
- composer self-update
matrix:
allow_failures:
- php: hhvm
- php: hhvm-nightly

install:
- composer install --no-interaction --prefer-source --dev
- composer require satooshi/php-coveralls:dev-master

script:
- phpunit --coverage-clover tests/coverage-clover.xml

after_script:
- vendor/bin/coveralls -v
- bin/aftertest
8 changes: 8 additions & 0 deletions bin/aftertest
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash


if [ "5.5" = "$(phpenv version-name)" ]; then
composer require satooshi/php-coveralls:dev-master
vendor/bin/coveralls -v
fi

3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
},
"require": {
"php": ">=5.4.0",
"sndsgd/util": "dev-master",
"sndsgd/issue": "dev-master"
"sndsgd/util": "~0.5"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
Expand Down
2 changes: 1 addition & 1 deletion src/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace sndsgd\http;

use \InvalidArgumentException;
use \sndsgd\util\Arr;
use \sndsgd\Arr;


class Header
Expand Down
22 changes: 11 additions & 11 deletions src/UploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace sndsgd\http;

use \sndsgd\util\Temp;
use \sndsgd\Temp;


/**
Expand All @@ -14,35 +14,35 @@ class UploadedFile

/**
* The name of the input field
*
*
* @var string
*/
protected $name;

/**
* The basename of the uploaded file (filename.ext)
*
*
* @var string
*/
protected $filename;

/**
* The absolute path to the uploaded file in the temp directory
*
*
* @var string
*/
protected $tempPath;

/**
* The content type of the file
*
*
* @var string
*/
protected $contentType;

/**
* The bytesize of the file
*
*
* @var integer
*/
protected $size;
Expand All @@ -61,20 +61,20 @@ public function __construct($name, $filename, $contentType)

/**
* Get the temp path to the file
*
*
* @return string An absolute file path
*/
public function getTempPath()
{
if ($this->tempPath === null) {
$this->tempPath = Temp::file("upload-{$this->filename}");
$this->tempPath = Temp::file("uploaded-file-{$this->filename}");
}
return $this->tempPath;
}

/**
* Get the name of the file as it was saved on the client computer
*
*
* @return string
*/
public function getFilename()
Expand All @@ -84,7 +84,7 @@ public function getFilename()

/**
* Set the size of the file
*
*
* @param integer $bytes
* @return sndsgd\http\UploadedFile
*/
Expand All @@ -96,7 +96,7 @@ public function setSize($bytes)

/**
* Rename the file to move it from the temp path
*
*
* @param string $path The absolute path to move the file to
* @return boolean
*/
Expand Down
14 changes: 12 additions & 2 deletions tests/CodeTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<?php

use sndsgd\http\Code;
namespace sndsgd\http;


class CodeTest extends PHPUnit_Framework_TestCase
/**
* @coversDefaultClass \sndsgd\http\Code
*/
class CodeTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers ::getStatusText
*/
public function testGetStatusText()
{
$this->assertEquals('OK', Code::getStatusText(200));
Expand All @@ -23,6 +29,9 @@ public function testGetStatusText()
$this->assertNull(Code::getStatusText(0));
}

/**
* @covers ::matches
*/
public function testMatches()
{
$this->assertTrue(Code::matches(200, '2xx'));
Expand All @@ -33,6 +42,7 @@ public function testMatches()
}

/**
* @covers ::matches
* @expectedException InvalidArgumentException
*/
public function testMatchesIntegerException()
Expand Down
72 changes: 57 additions & 15 deletions tests/HeaderTest.php
Original file line number Diff line number Diff line change
@@ -1,52 +1,94 @@
<?php

use sndsgd\http\Header;
namespace sndsgd\http;


class HeaderTest extends PHPUnit_Framework_TestCase
/**
* @coversDefaultClass \sndsgd\http\Header
*/
class HeaderTest extends \PHPUnit_Framework_TestCase
{
protected static $rawHeaders = [];
protected static $headers = [];

public static function setUpBeforeClass()
/**
* @coversNothing
*/
public static function addHeader($name, $content)
{
$dir = __DIR__.DIRECTORY_SEPARATOR.'headers';
$files = array_diff(scandir($dir), ['.', '..']);
foreach ($files as $file) {
$path = $dir.DIRECTORY_SEPARATOR.$file;
$contents = file_get_contents($path);
self::$rawHeaders[$file] = str_replace("\n", "\r\n", $contents);
}
self::$headers[$name] = str_replace("\n", "\r\n", $content);
}

/**
* @coversNothing
*/
public static function tearDownAfterClass()
{
self::$rawHeaders = null;
self::$headers = null;
}

/**
* @covers \sndsgd\http\Header
*/
public function testParseHttpGoogle()
{
$h = Header::parse(self::$rawHeaders['http-google.com']);
$h = Header::parse(self::$headers['http://google.com']);
$this->assertEquals('HTTP/1.1', $h->getProtocol());
$this->assertEquals(301, $h->getStatusCode());
$this->assertEquals('Moved Permanently', $h->getStatusText());
$this->assertEquals(219, $h->getFieldValue('content-length'));
}

/**
* @covers \sndsgd\http\Header
*/
public function testParseHttpsGoogle()
{
$h = Header::parse(self::$rawHeaders['https-www.google.com']);
$h = Header::parse(self::$headers['https://www.google.com']);
$this->assertEquals('HTTP/1.1', $h->getProtocol());
$this->assertEquals(200, $h->getStatusCode());
$this->assertEquals('OK', $h->getStatusText());
$this->assertNull($h->getFieldValue('content-length'));
}

/**
* @covers \sndsgd\http\Header
* @expectedException InvalidArgumentException
*/
public function testBadHeader()
{
$h = Header::parse("HTTP/1.1 200 OK\nContent-Length: 219\n");
Header::parse("HTTP/1.1 200 OK\nContent-Length: 219\n");
}
}


HeaderTest::addHeader('http://google.com', <<<HEADER
HTTP/1.1 301 Moved Permanently
Alternate-Protocol: 80:quic,p=0.01
Cache-Control: public, max-age=2592000
Content-Length: 219
Content-Type: text/html; charset=UTF-8
Date: Tue, 11 Nov 2014 19:05:32 GMT
Expires: Thu, 11 Dec 2014 19:05:32 GMT
Location: http://www.google.com/
Server: gws
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
HEADER
);

HeaderTest::addHeader('https://www.google.com', <<<HEADER
HTTP/1.1 200 OK
Alternate-Protocol: 443:quic,p=0.01
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Date: Tue, 11 Nov 2014 19:31:45 GMT
Expires: -1
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
Server: gws
Set-Cookie: PREF=ID=471601aaf6d05f78:FF=0:TM=1415734305:LM=1415734305:S=LMH3Xd8mevGWt0kG; expires=Thu, 10-Nov-2016 19:31:45 GMT; path=/; domain=.google.com
Set-Cookie: NID=asdasdasd; expires=Wed, 13-May-2015 19:31:45 GMT; path=/; domain=.google.com; HttpOnly
Transfer-Encoding: chunked
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
HEADER
);
11 changes: 0 additions & 11 deletions tests/headers/http-google.com

This file was deleted.

13 changes: 0 additions & 13 deletions tests/headers/https-www.google.com

This file was deleted.

0 comments on commit a94ebea

Please sign in to comment.