diff options
author | Arnold Daniels <arnold@jasny.net> | 2016-10-13 20:50:08 +0200 |
---|---|---|
committer | Arnold Daniels <arnold@jasny.net> | 2016-10-13 20:50:08 +0200 |
commit | 31668d6e3bcfcd50d8dc0982b87bc4b2e261f021 (patch) | |
tree | 8f6ab18b83d3c50d69e1588b371fbaa74ba9392d | |
parent | 148c5199d15bbc3e5a0287078315089863e82a7e (diff) | |
download | router-31668d6e3bcfcd50d8dc0982b87bc4b2e261f021.zip router-31668d6e3bcfcd50d8dc0982b87bc4b2e261f021.tar.gz router-31668d6e3bcfcd50d8dc0982b87bc4b2e261f021.tar.bz2 |
Use phpunit 5's createMock rather than getMock
Minor fixes in tests and code
-rw-r--r-- | composer.json | 6 | ||||
-rw-r--r-- | src/Router/Routes/Glob.php | 14 | ||||
-rw-r--r-- | tests/Router/Routes/GlobTest.php | 27 |
3 files changed, 23 insertions, 24 deletions
diff --git a/composer.json b/composer.json index 17ef845..ad0d2cc 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,12 @@ "jasny/php-functions": "^2.0", "psr/http-message": "^1.0" }, + "require-dev": { + "jasny/php-code-quality": "^1.2" + }, "autoload": { "psr-4": { "Jasny\\": "src/" } - }, - "require-dev": { - "jasny/php-code-quality": "^1.2" } } diff --git a/src/Router/Routes/Glob.php b/src/Router/Routes/Glob.php index 97483d8..cb1abf4 100644 --- a/src/Router/Routes/Glob.php +++ b/src/Router/Routes/Glob.php @@ -3,6 +3,7 @@ namespace Jasny\Router\Routes; use ArrayObject; +use ArrayIterator; use Jasny\Router\UrlParsing; use Jasny\Router\Routes; use Jasny\Router\Route; @@ -61,19 +62,6 @@ class Glob extends ArrayObject implements Routes } /** - * Class constructor - * - * @param Route[]|array|\Traversable $input - * @param type $flags - * @param type $iterator_class - */ - public function __construct($input = [], $flags = 0, $iterator_class = "ArrayIterator") - { - parent::__construct($input, $flags, $iterator_class); - } - - - /** * {@inheritdoc} */ public function append($route) diff --git a/tests/Router/Routes/GlobTest.php b/tests/Router/Routes/GlobTest.php index e0dc9da..fef0f64 100644 --- a/tests/Router/Routes/GlobTest.php +++ b/tests/Router/Routes/GlobTest.php @@ -1,9 +1,16 @@ <?php +namespace Jasny\Router\Routes; + use Jasny\Router\Routes\Glob; use Psr\Http\Message\ServerRequestInterface; -class GlobTest extends PHPUnit_Framework_TestCase +use ArrayObject; +use BadMethodCallException; +use InvalidArgumentException; +use AppendIterator; + +class GlobTest extends \PHPUnit_Framework_TestCase { /** * Test creating Glob object @@ -25,18 +32,22 @@ class GlobTest extends PHPUnit_Framework_TestCase } $this->assertEquals(0, $count); - + } + + public function testConstructorWithArguments() + { #Test with params $values = [ '/foo/bar' => ['controller' => 'value1'], '/foo/*' => ['fn' => 'value3'], '/foo/*/bar' => ['file' => 'value5'], ]; - $glob = new Glob($values, ArrayObject::ARRAY_AS_PROPS, 'AppendIterator'); + + $glob = new Glob($values, ArrayObject::ARRAY_AS_PROPS, AppendIterator::class); $this->assertEquals(count($values), $glob->count(), "Routes count is not match"); $this->assertEquals(ArrayObject::ARRAY_AS_PROPS, $glob->getFlags(), "Flags are not correct"); - $this->assertEquals('AppendIterator', $glob->getIteratorClass(), "Iterator class is not correct"); + $this->assertEquals(AppendIterator::class, $glob->getIteratorClass(), "Iterator class is not correct"); foreach ($values as $pattern => $options) { $this->assertTrue($glob->offsetExists($pattern), "Key '$pattern' is missing"); @@ -121,8 +132,7 @@ class GlobTest extends PHPUnit_Framework_TestCase ['/foo/*', ['fn' => 'bar'], ''], ['/foo/*', ['file' => 'bar'], ''], ['', ['controller' => 'bar'], BadMethodCallException::class], - ['/bar', ['foo' => 'bar'], InvalidArgumentException::class], - ['', '', BadMethodCallException::class] + ['foo', 'bar', InvalidArgumentException::class], ]; } @@ -149,7 +159,8 @@ class GlobTest extends PHPUnit_Framework_TestCase { $glob = new Glob(); - $this->assertEquals($positive, $glob->fnmatch($pattern, $uri), "Pattern and uri should " . ($positive ? "" : "not") . " match"); + $this->assertEquals($positive, $glob->fnmatch($pattern, $uri), + "Pattern and uri should " . ($positive ? "" : "not") . " match"); } /** @@ -402,7 +413,7 @@ class GlobTest extends PHPUnit_Framework_TestCase */ public function getServerRequest($uri, $method = 'GET', $globals = [], $header = '') { - $request = $this->getMock(ServerRequestInterface::class); + $request = $this->createMock(ServerRequestInterface::class); $request->method('getUri')->willReturn($uri); $request->method('getMethod')->willReturn($method); $request->method('getQueryParams')->willReturn(isset($globals['get']) ? $globals['get'] : []); |