Skip to content

Commit

Permalink
Use phpunit.xml for testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
rsur committed Apr 6, 2017
1 parent ce36f41 commit da3119f
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ php:
- 7.0

before_script:
- composer install -n -o --prefer-dist
- composer install -no --prefer-dist

script:
- php ./vendor/bin/phpunit --bootstrap ./vendor/autoload.php tests
- php ./vendor/bin/phpunit -c phpunit.xml

10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.5/phpunit.xsd"

backupGlobals="false"
backupStaticAttributes="false"
cacheTokens="false"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
forceCoversAnnotation="false"
mapTestClassNameToCoveredClassName="false"
printerClass="PHPUnit_TextUI_ResultPrinter"

processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"

timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"

verbose="false"

bootstrap="./vendor/autoload.php"
>
<testsuites>
<testsuite name="AllTests">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./docs/coverage" lowUpperBound="35"
highLowerBound="70"/>
<!--
<log type="coverage-clover" target="./docs/coverage/coverage.xml"/>
-->
</logging>
</phpunit>
6 changes: 4 additions & 2 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@ final public function route(

// verify request method

$request_method = isset($_SERVER['REQUEST_METHOD'])
? $_SERVER['REQUEST_METHOD'] : 'GET';
$request_method = (
isset($_SERVER['REQUEST_METHOD']) &&
!empty($_SERVER['REQUEST_METHOD'])
) ? strtoupper($_SERVER['REQUEST_METHOD']) : 'GET';
$this->current_method = $request_method;

# always allow HEAD
Expand Down
11 changes: 8 additions & 3 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ public function test_path_parser() {
public function test_route_post() {
# mock input
$_POST['x'] = 'y';
$_SERVER['REQUEST_URI'] = '/test/z';
$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['REQUEST_URI'] = '/test/z';
$_SERVER['HTTP_REFERER'] = 'http://localhost';

$core = new RouterAlive();
Expand Down Expand Up @@ -180,6 +180,7 @@ public function test_route_post() {
public function test_route_get() {
# mock input; this fake REQUEST_URI can't populate QUERY_STRING
$_GET['x'] = 'y';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/getme/';
$_SERVER['HTTP_REFERER'] = 'http://localhost';

Expand All @@ -192,8 +193,8 @@ public function test_route_get() {

public function test_route_patch() {
# mock input
$_SERVER['REQUEST_URI'] = '/patchme/';
$_SERVER['REQUEST_METHOD'] = 'PATCH';
$_SERVER['REQUEST_URI'] = '/patchme/';

$core = new RouterAlive();
$this->assertEquals($core->get_request_path(), '/patchme');
Expand All @@ -208,8 +209,8 @@ public function test_route_patch() {
*/
public function test_route_trace() {
# mock input
$_SERVER['REQUEST_URI'] = '/traceme/';
$_SERVER['REQUEST_METHOD'] = 'TRACE';
$_SERVER['REQUEST_URI'] = '/traceme/';

$core = new RouterAlive();
ob_start();
Expand All @@ -224,6 +225,7 @@ public function test_route_trace() {
*/
public function test_route_notfound() {
# mock input
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/findme/';

# patched router
Expand All @@ -244,6 +246,7 @@ public function test_route_notfound() {
*/
public function test_route_static() {
# mock input
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REQUEST_URI'] = '/static/' . basename(__FILE__);

$core = new RouterAlive();
Expand Down Expand Up @@ -272,6 +275,7 @@ public function test_route_static() {
public function test_route_abort() {
# mock input
$_SERVER['REQUEST_URI'] = '/notfound';
$_SERVER['REQUEST_METHOD'] = 'GET';

$core = new RouterAlive();
$core->route('/notfound', function($args) use($core) {
Expand Down Expand Up @@ -300,6 +304,7 @@ public function test_route_abort() {
public function test_route_redirect() {
# mock input
$_SERVER['REQUEST_URI'] = '/redirect';
$_SERVER['REQUEST_METHOD'] = 'GET';

$core = new RouterAlive();
$core->route('/redirect', function($args) use($core) {
Expand Down

0 comments on commit da3119f

Please sign in to comment.