OSDN Git Service

(try to) fix unit tests
authorfrostbane <frostbane@programmer.net>
Wed, 27 Nov 2019 07:39:01 +0000 (16:39 +0900)
committerfrostbane <frostbane@programmer.net>
Wed, 27 Nov 2019 07:46:02 +0000 (16:46 +0900)
.gitignore
composer.json
phpunit.xml [moved from phpunit.xml.dist with 66% similarity]
src/Route.php
tests/Bootstrap.php [deleted file]
tests/Fixtures/SomeController.php
tests/src/PHPRouterTest/RouteTest.php
tests/src/PHPRouterTest/RouterTest.php

index 3806554..1ad27cc 100644 (file)
@@ -1,3 +1,5 @@
 /vendor
 /.idea
 composer.lock
+logs/*
+*.iml
index f95c368..8a3eec2 100644 (file)
@@ -1,14 +1,14 @@
 {
-    "name"       : "axas/php-router",
-    "description": "Simple PHP Router, supports REST and reverse routing.",
-    "keywords"   : [
+    "name"        : "frostbane/php-router",
+    "description" : "Simple PHP Router, supports REST and reverse routing.",
+    "keywords"    : [
         "router",
         "routing",
         "rest"
     ],
-    "homepage"   : "https://github.com/dannyvankooten/PHP-Router",
-    "license"    : "MIT",
-    "authors"    : [
+    "homepage"    : "https://github.com/dannyvankooten/PHP-Router",
+    "license"     : "MIT",
+    "authors"     : [
         {
             "name"    : "Danny van Kooten",
             "email"   : "dannyvankooten@gmail.com",
             "email": "malukenho@phpse.net"
         }
     ],
-    "require"    : {
+    "require"     : {
         "php"                  : "^5.3.0|^7.0",
         "fig/http-message-util": "^1.1"
     },
-    "require-dev": {
+    "require-dev" : {
         "malukenho/docheader"      : "^0.1.5",
         "phpunit/phpunit"          : "4.8.*",
         "squizlabs/php_codesniffer": "2.*"
     },
-    "autoload"   : {
+    "autoload"    : {
         "psr-4": {
             "PHPRouter\\": "src/"
         }
+    },
+    "autoload-dev": {
+        "psr-4": {
+            "PHPRouter\\Test\\"          : "tests/src/PHPRouterTest/",
+            "PHPRouter\\Test\\Fixtures\\": "tests/Fixtures/"
+        }
     }
 }
similarity index 66%
rename from phpunit.xml.dist
rename to phpunit.xml
index 002f867..75d6537 100644 (file)
@@ -1,16 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
-
-<phpunit
-         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
-         backupGlobals="true"
+<phpunit backupGlobals="false"
          backupStaticAttributes="false"
+         bootstrap="vendor/autoload.php"
          colors="true"
          convertErrorsToExceptions="true"
          convertNoticesToExceptions="true"
          convertWarningsToExceptions="true"
-         bootstrap="tests/Bootstrap.php">
-
+         processIsolation="false"
+         stopOnFailure="true">
     <testsuites>
         <testsuite name="PHP Router">
             <directory>tests</directory>
@@ -21,7 +18,7 @@
         <whitelist>
             <directory>./</directory>
             <exclude>
-                <directory>./tests</directory>
+                <directory>./tests/Fixtures</directory>
                 <directory>./vendor</directory>
             </exclude>
         </whitelist>
@@ -29,7 +26,7 @@
 
     <logging>
         <log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
-        <log type="coverage-clover" target="build/logs/clover.xml"/>
+        <log type="coverage-clover" target="logs/clover.xml"/>
     </logging>
 
 </phpunit>
index aa8d4bf..d4e11fe 100755 (executable)
@@ -180,6 +180,7 @@ class Route
             return null;
         }
 
+        // todo use reflection
         $instance = new $class();
 
         if (empty($action[1]) || trim($action[1]) === '') {
diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php
deleted file mode 100644 (file)
index cf4d0b3..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-
-/**
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * and is licensed under the MIT license.
- */
-
-error_reporting(E_ALL);
-if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) {
-    date_default_timezone_set(@date_default_timezone_get());
-}
-
-require_once __DIR__ . '/../vendor/autoload.php';
-require __DIR__ . '/Fixtures/SomeController.php';
index c92c817..2361b3c 100644 (file)
@@ -15,7 +15,7 @@
  * This software consists of voluntary contributions made by many individuals
  * and is licensed under the MIT license.
  */
-namespace PHPRouter\Test;
+namespace PHPRouter\Test\Fixtures;
 
 final class SomeController
 {
index e43a18e..5a458b2 100644 (file)
@@ -29,7 +29,7 @@ class RouteTest extends PHPUnit_Framework_TestCase
         $this->routeWithParameters = new Route(
             '/page/:page_id',
             array(
-                '_controller' => 'PHPRouter\Test\SomeController::page',
+                '_controller' => '\PHPRouter\Test\Fixtures\SomeController::page',
                 'methods' => array(
                     'GET'
                 ),
index 330b0e7..1852d6c 100644 (file)
@@ -34,13 +34,15 @@ class RouterTest extends PHPUnit_Framework_TestCase
      */
     public function testMatch($router, $path, $expected)
     {
-        self::assertEquals($expected, (bool)$router->match($path));
+        $result = $router->match($path);
+
+        $this->assertEquals($expected, $result);
     }
 
     public function testMatchWrongMethod()
     {
         $router = $this->getRouter();
-        self::assertFalse($router->match('/users', 'POST'));
+        $this->assertFalse($router->match('/users', 'POST'));
     }
 
     public function testBasePathConfigIsSettedProperly()
@@ -48,14 +50,14 @@ class RouterTest extends PHPUnit_Framework_TestCase
         $router = new Router(new RouteCollection);
         $router->setBasePath('/webroot/');
 
-        self::assertAttributeEquals('/webroot', 'basePath', $router);
+        $this->assertAttributeEquals('/webroot', 'basePath', $router);
     }
 
     public function testMatchRouterUsingBasePath()
     {
         $collection = new RouteCollection();
         $collection->attach(new Route('/users/', array(
-            '_controller' => 'PHPRouter\Test\SomeController::usersCreate',
+            '_controller' => '\PHPRouter\Test\Fixtures\SomeController::usersCreate',
             'methods' => 'GET'
         )));
 
@@ -64,7 +66,7 @@ class RouterTest extends PHPUnit_Framework_TestCase
 
         foreach ($this->serverProvider() as $server) {
             $_SERVER = $server;
-            self::assertTrue((bool)$router->matchCurrentRequest());
+            $this->assertTrue((bool)$router->matchCurrentRequest());
         }
     }
 
@@ -90,7 +92,7 @@ class RouterTest extends PHPUnit_Framework_TestCase
         $route = new Route(
             '/page/:page_id',
             array(
-                '_controller' => 'PHPRouter\Test\SomeController::page',
+                '_controller' => '\PHPRouter\Test\Fixtures\SomeController::page',
                 'methods' => 'GET'
             )
         );
@@ -98,7 +100,7 @@ class RouterTest extends PHPUnit_Framework_TestCase
         $collection->attachRoute($route);
 
         $router = new Router($collection);
-        self::assertEquals(
+        $this->assertEquals(
             array(array('page_id' => 'MySuperPage')),
             $router->match('/page/MySuperPage')->getParameters()
         );
@@ -110,7 +112,7 @@ class RouterTest extends PHPUnit_Framework_TestCase
         $route = new Route(
             '/js/:filename.js',
             array(
-                '_controller' => 'PHPRouter\Test\SomeController::dynamicFilterUrlMatch',
+                '_controller' => '\PHPRouter\Test\Fixtures\SomeController::dynamicFilterUrlMatch',
                 'methods' => 'GET',
             )
         );
@@ -118,17 +120,17 @@ class RouterTest extends PHPUnit_Framework_TestCase
         $collection->attachRoute($route);
 
         $router = new Router($collection);
-        self::assertEquals(
+        $this->assertEquals(
             array(array('filename' => 'someJsFile')),
             $router->match('/js/someJsFile.js')->getParameters()
         );
 
-        self::assertEquals(
+        $this->assertEquals(
             array(array('filename' => 'someJsFile.min')),
             $router->match('/js/someJsFile.min.js')->getParameters()
         );
 
-        self::assertEquals(
+        $this->assertEquals(
             array(array('filename' => 'someJsFile.min.js')),
             $router->match('/js/someJsFile.min.js.js')->getParameters()
         );
@@ -138,14 +140,14 @@ class RouterTest extends PHPUnit_Framework_TestCase
     {
         $config = Config::loadFromFile(__DIR__ . '/../../Fixtures/router.yaml');
         $router = Router::parseConfig($config);
-        self::assertAttributeEquals($config['base_path'], 'basePath', $router);
+        $this->assertAttributeEquals($config['base_path'], 'basePath', $router);
     }
 
     public function testGenerate()
     {
         $router = $this->getRouter();
-        self::assertSame('/users/', $router->generate('users'));
-        self::assertSame('/user/123', $router->generate('user', array('id' => 123)));
+        $this->assertSame('/users/', $router->generate('users'));
+        $this->assertSame('/user/123', $router->generate('user', array('id' => 123)));
     }
 
     /**
@@ -154,7 +156,7 @@ class RouterTest extends PHPUnit_Framework_TestCase
     public function testGenerateNotExistent()
     {
         $router = $this->getRouter();
-        self::assertSame('/notExists/', $router->generate('notThisRoute'));
+        $this->assertSame('/notExists/', $router->generate('notThisRoute'));
     }
 
     /**
@@ -164,17 +166,17 @@ class RouterTest extends PHPUnit_Framework_TestCase
     {
         $collection = new RouteCollection();
         $collection->attachRoute(new Route('/users/', array(
-            '_controller' => 'PHPRouter\Test\SomeController::usersCreate',
+            '_controller' => '\PHPRouter\Test\Fixtures\SomeController::usersCreate',
             'methods' => 'GET',
             'name' => 'users'
         )));
         $collection->attachRoute(new Route('/user/:id', array(
-            '_controller' => 'PHPRouter\Test\SomeController::user',
+            '_controller' => '\PHPRouter\Test\Fixtures\SomeController::user',
             'methods' => 'GET',
             'name' => 'user'
         )));
         $collection->attachRoute(new Route('/', array(
-            '_controller' => 'PHPRouter\Test\SomeController::indexAction',
+            '_controller' => '\PHPRouter\Test\Fixtures\SomeController::indexAction',
             'methods' => 'GET',
             'name' => 'index'
         )));