Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adjust for HTTP status line change from 8d80cde

Also use simpler expectOutputString() tests.
  • Loading branch information...
commit 3067a42c923a51e88859904c0313be4198ae200f 1 parent 8d80cde
@abackstrom abackstrom authored
Showing with 64 additions and 35 deletions.
  1. +19 −3 tests/HeadersTest.php
  2. +44 −31 tests/RoutesTest.php
  3. +1 −1  tests/setup.php
View
22 tests/HeadersTest.php
@@ -3,10 +3,26 @@
require_once dirname(__FILE__) . '/setup.php';
class HeadersTest extends PHPUnit_Framework_TestCase {
- public function testHeaderKey() {
+ public function setUp() {
+ $this->headers = new HeadersEcho;
+ }
+ public function testResponseCode() {
+ $this->expectOutputString("HTTP/1.1 404 Not Found\n");
+ $this->headers->header( 'HTTP/1.1 404 Not Found' );
+ }
+
+ public function testBlankHeader() {
+ $this->expectOutputString("Foo: \n");
+ $this->headers->header( 'Foo', '' );
+ }
+
+ public function testHeaderKeyValue() {
$this->expectOutputString("Foo: Bar\n");
+ $this->headers->header( 'Foo', 'Bar' );
+ }
- $headers = new HeadersEcho;
- $headers->header( 'Foo', 'Bar' );
+ public function testHeaderKeyTransform() {
+ $this->expectOutputString("Foo-Bar: baz\n");
+ $this->headers->header( 'foo bar', 'baz' );
}
}
View
75 tests/RoutesTest.php
@@ -9,71 +9,84 @@ protected function setUp() {
global $__namespace;
$__namespace = null;
+
+ $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
}
public function testBasic() {
+ $this->expectOutputString( 'x' );
+
respond( '/', function(){ echo 'x'; });
respond( '/something', function(){ echo 'y'; });
+ dispatch( '/' );
+ }
+
+ public function testCatchallImplicit() {
+ $this->expectOutputString( 'b' );
- $out = dispatch( '/', 'GET', null, true );
- $this->assertSame( 'x', $out );
+ respond( '/one', function(){ echo 'a'; });
+ respond( function(){ echo 'b'; });
+ respond( '/two', function(){ } );
+ respond( '/three', function(){ echo 'c'; } );
+ dispatch( '/two' );
}
- public function testCatchall() {
- respond( function(){ echo 'a'; });
- respond( '/not', function(){ echo 'b'; });
- respond( '*', function(){ echo 'c'; });
- respond( '/something', function(){ echo 'd'; });
- respond( '*', function(){ echo 'e'; });
- respond( '/not', function(){ echo 'f'; });
- respond( function(){ echo 'g'; });
-
- $out = dispatch( '/something', 'GET', null, true );
- $this->assertSame( 'acdeg', $out );
+ public function testCatchallAsterisk() {
+ $this->expectOutputString( 'b' );
+
+ respond( '/one', function(){ echo 'a'; } );
+ respond( '*', function(){ echo 'b'; } );
+ respond( '/two', function(){ } );
+ respond( '/three', function(){ echo 'c'; } );
+ dispatch( '/two' );
+ }
+
+ public function testCatchallImplicitTriggers404() {
+ $this->expectOutputString( "bHTTP/1.1 404\n" );
+ respond( function(){ echo 'b'; });
+ dispatch( '/' );
}
public function testRegex() {
- respond( '@/bar', function(){ echo 'z'; });
+ $this->expectOutputString( 'z' );
- $out = dispatch( '/bar', 'GET', null, true );
- $this->assertSame( 'z', $out );
+ respond( '@/bar', function(){ echo 'z'; });
+ dispatch( '/bar' );
}
public function testRegexNegate() {
- respond( '!@/foo', function(){ echo 'y'; });
+ $this->expectOutputString( "y" );
- $out = dispatch( '/bar', 'GET', null, true );
- $this->assertSame( 'y', $out );
+ respond( '!@/foo', function(){ echo 'y'; });
+ dispatch( '/bar' );
}
public function test404() {
$this->expectOutputString("HTTP/1.1 404\n");
- $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1';
respond( '/', function(){ echo 'a'; } );
-
dispatch( '/foo' );
}
public function testParamsBasic() {
- respond( '/[:color]', function($request){ echo $request->param('color'); });
+ $this->expectOutputString( 'blue' );
- $out = dispatch( '/blue', 'GET', null, true );
- $this->assertSame( 'blue', $out );
+ respond( '/[:color]', function($request){ echo $request->param('color'); });
+ dispatch( '/blue' );
}
public function testParamsIntegerSuccess() {
- respond( '/[i:age]', function($request){ var_dump( $request->param('age') ); });
+ $this->expectOutputString( "string(3) \"987\"\n" );
- $out = dispatch( '/987', 'GET', null, true );
- $this->assertSame( 'string(3) "987"', trim($out) );
+ respond( '/[i:age]', function($request){ var_dump( $request->param('age') ); });
+ dispatch( '/987' );
}
public function testParamsIntegerFail() {
- respond( '/[i:age]', function($request){ var_dump( $request->param('age') ); });
- respond( '404', function(){ echo '404'; } );
+ $this->expectOutputString( '404 Code' );
- $out = dispatch( '/blue', 'GET', null, true );
- $this->assertSame( '404', trim($out) );
+ respond( '/[i:age]', function($request){ var_dump( $request->param('age') ); });
+ respond( '404', function(){ echo '404 Code'; } );
+ dispatch( '/blue' );
}
}
View
2  tests/setup.php
@@ -3,7 +3,7 @@
include dirname(dirname(__FILE__)) . '/klein.php';
class HeadersEcho extends _Headers {
- public function header($key, $value = '') {
+ public function header($key, $value = null) {
echo $this->_header($key, $value) . "\n";
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.