OSDN Git Service

100% test coverage
authorManuel Dalla Lana <endelwar@aregar.it>
Sun, 27 Sep 2015 13:27:48 +0000 (15:27 +0200)
committerManuel Dalla Lana <endelwar@aregar.it>
Sun, 27 Sep 2015 13:27:48 +0000 (15:27 +0200)
src/PHPRouter/Config.php
src/PHPRouter/RouteCollection.php
src/PHPRouter/Router.php
tests/src/PHPRouterTest/RouterTest.php

index f5fab65..496243c 100644 (file)
@@ -30,6 +30,8 @@ final class Config
 {
     /**
      * Avoid instantiation.
+     *
+     * @codeCoverageIgnore
      */
     private function __construct()
     {
index 5e1b164..221cbd1 100755 (executable)
@@ -35,16 +35,15 @@ class RouteCollection extends \SplObjectStorage
     }
 
     /**
-     * Fetch all routers stored on this collection of router
-     * and return it.
+     * Fetch all routes stored on this collection of routes and return it.
      *
      * @return Route[]
      */
     public function all()
     {
         $temp = array();
-        foreach ($this as $router) {
-            $temp[] = $router;
+        foreach ($this as $route) {
+            $temp[] = $route;
         }
 
         return $temp;
index 041545e..fe61751 100755 (executable)
@@ -26,9 +26,9 @@ use PHPRouter\RouteCollection;
 class Router
 {
     /**
-     * Array that holds all Route objects
+     * RouteCollection that holds all Route objects
      *
-     * @var array
+     * @var RouteCollection
      */
     private $routes = array();
 
index 541e452..31acca6 100644 (file)
@@ -37,6 +37,12 @@ class RouterTest extends PHPUnit_Framework_TestCase
         $this->assertEquals($expected, (bool)$router->match($path));
     }
 
+    public function testMatchWrongMethod()
+    {
+        $router = $this->getRouter();
+        $this->assertFalse($router->match('/users', 'POST'));
+    }
+
     public function testBasePathConfigIsSettedProperly()
     {
         $router = new Router(new RouteCollection);
@@ -56,12 +62,26 @@ class RouterTest extends PHPUnit_Framework_TestCase
         $router = new Router($collection);
         $router->setBasePath('/localhost/webroot');
 
-        $_SERVER = array();
-        $_SERVER['REQUEST_METHOD'] = 'GET';
-        $_SERVER['REQUEST_URI'] = '/localhost/webroot/users/';
-        $_SERVER['SCRIPT_NAME'] = 'index.php';
+        foreach ($this->serverProvider() as $server) {
+            $_SERVER = $server;
+            $this->assertTrue((bool)$router->matchCurrentRequest());
+        }
+    }
 
-        $this->assertTrue((bool)$router->matchCurrentRequest());
+    private function serverProvider()
+    {
+        return array(
+            array(
+                'REQUEST_METHOD' => 'GET',
+                'REQUEST_URI' => '/localhost/webroot/users/',
+                'SCRIPT_NAME' => 'index.php'
+            ),
+            array(
+                'REQUEST_METHOD' => 'GET',
+                'REQUEST_URI' => '/localhost/webroot/users/?foo=bar&bar=foo',
+                'SCRIPT_NAME' => 'index.php'
+            ),
+        );
     }
 
     public function testGetParamsInsideControllerMethod()