Skip to content

Commit 895119e

Browse files
committed
update: add more unit tests. declare return type for all methods
1 parent 6780c9a commit 895119e

29 files changed

+262
-216
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ language: php
33
php:
44
- 7.1
55
- 7.2
6+
- 7.3
67

78
#matrix:
89
# include:

example/Controllers/Admin/UserController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
*/
1515
class UserController
1616
{
17-
public function indexAction()
17+
public function indexAction(): void
1818
{
1919
echo 'hello, this is ' . __METHOD__ . '<br>';
2020
}
2121

22-
public function infoAction()
22+
public function infoAction(): void
2323
{
2424
echo 'hello, this is ' . __METHOD__ . '<br>';
2525
}

example/Controllers/DemoController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
*/
1515
class DemoController
1616
{
17-
public function indexAction()
17+
public function indexAction(): void
1818
{
1919
echo 'hello, this is ' . __METHOD__ . '<br>';
2020
}
2121

22-
public function testAction()
22+
public function testAction(): void
2323
{
2424
echo 'hello, this is ' . __METHOD__ . '<br>';
2525
}
2626

2727
// you can access by '/demo/oneTwo' or '/demo/one-two'
28-
public function oneTwoAction()
28+
public function oneTwoAction(): void
2929
{
3030
echo 'hello, this is ' . __METHOD__ . '<br>';
3131
}

example/Controllers/HomeController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
*/
1515
class HomeController
1616
{
17-
public function indexAction()
17+
public function indexAction(): void
1818
{
1919
echo 'hello, this is ' . __METHOD__ . '<br>';
2020
}
2121

22-
public function testAction()
22+
public function testAction(): void
2323
{
2424
echo 'hello, this is ' . __METHOD__ . '<br>';
2525
}
2626

27-
public function aboutAction()
27+
public function aboutAction(): void
2828
{
2929
echo 'hello, this is about page';
3030
}

example/Controllers/RestController.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,33 @@
1414
*/
1515
class RestController
1616
{
17-
public function indexAction()
17+
public function indexAction(): void
1818
{
1919
echo __METHOD__ . PHP_EOL;
2020
}
2121

22-
public function viewAction()
22+
public function viewAction(): void
2323
{
2424
echo __METHOD__ . PHP_EOL;
2525
}
2626

27-
public function createAction()
27+
public function createAction(): void
2828
{
2929
echo __METHOD__ . PHP_EOL;
3030
}
3131

32-
public function updateAction()
32+
public function updateAction(): void
3333
{
3434
echo __METHOD__ . PHP_EOL;
3535
}
3636

37-
public function patchAction()
37+
public function patchAction(): void
3838
{
3939
echo __METHOD__ . PHP_EOL;
4040
}
4141

42-
public function deleteAction()
42+
public function deleteAction(): void
4343
{
4444
echo __METHOD__ . PHP_EOL;
4545
}
46-
}
46+
}

src/CachedRouter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct(array $config = [])
6060
/**
6161
* talk to me routes collect completed.
6262
*/
63-
public function completed()
63+
public function completed(): void
6464
{
6565
$this->dumpRoutesCache();
6666
}
@@ -72,7 +72,7 @@ public function add(string $method, string $path, $handler, array $binds = [], a
7272
{
7373
// file cache exists check.
7474
if ($this->cacheLoaded) {
75-
return Route::createFromArray([]);
75+
return Route::createFromArray();
7676
}
7777

7878
return parent::add($method, $path, $handler, $binds, $opts);
@@ -200,7 +200,7 @@ public function isCacheEnable(): bool
200200
/**
201201
* @param bool $cacheEnable
202202
*/
203-
public function setCacheEnable($cacheEnable)
203+
public function setCacheEnable($cacheEnable): void
204204
{
205205
$this->cacheEnable = (bool)$cacheEnable;
206206
}
@@ -216,7 +216,7 @@ public function getCacheFile(): string
216216
/**
217217
* @param string $cacheFile
218218
*/
219-
public function setCacheFile(string $cacheFile)
219+
public function setCacheFile(string $cacheFile): void
220220
{
221221
$this->cacheFile = \trim($cacheFile);
222222
}

src/Dispatcher/Dispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function dispatch(int $status, string $path, string $method, $route)
8686
* 'schemes' => ['https'],
8787
* ]
8888
*/
89-
protected function validateMetadata(array $options)
89+
protected function validateMetadata(array $options): void
9090
{
9191
// 1. validate Schema
9292

src/Dispatcher/DispatcherInterface.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
*/
1818
interface DispatcherInterface
1919
{
20-
const FAV_ICON = '/favicon.ico';
20+
public const FAV_ICON = '/favicon.ico';
2121

2222
// some route events
23-
const ON_FOUND = 'found';
24-
const ON_NOT_FOUND = 'notFound';
25-
const ON_METHOD_NOT_ALLOWED = 'methodNotAllowed';
26-
const ON_EXEC_START = 'execStart';
27-
const ON_EXEC_END = 'execEnd';
28-
const ON_EXEC_ERROR = 'execError';
23+
public const ON_FOUND = 'found';
24+
public const ON_NOT_FOUND = 'notFound';
25+
public const ON_METHOD_NOT_ALLOWED = 'methodNotAllowed';
26+
public const ON_EXEC_START = 'execStart';
27+
public const ON_EXEC_END = 'execEnd';
28+
public const ON_EXEC_ERROR = 'execError';
2929

3030
/**
3131
* Runs the callback for the given path and method.

src/Dispatcher/Psr15Dispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
3434
$method = $request->getMethod();
3535

3636
/** @var Route $route */
37-
list($status, $path, $route) = $this->getRouter()->match($path, $method);
37+
[$status, $path, $route] = $this->getRouter()->match($path, $method);
3838

3939
$chains = $this->getRouter()->getChains();
4040

src/Dispatcher/SimpleDispatcher.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function __construct(array $options = [], RouterInterface $router = null)
9191
* @param array $options
9292
* @throws \LogicException
9393
*/
94-
public function initOptions(array $options)
94+
public function initOptions(array $options): void
9595
{
9696
if ($this->initialized) {
9797
throw new \LogicException('Has already started to distributed routing, and configuration is not allowed!');
@@ -133,7 +133,7 @@ public function dispatchUri(string $path = null, string $method = null)
133133
$method = \strtoupper($method);
134134

135135
/** @var Route $route */
136-
list($status, $path, $route) = $this->router->match($path, $method);
136+
[$status, $path, $route] = $this->router->match($path, $method);
137137

138138
return $this->dispatch($status, $path, $method, $route);
139139
}
@@ -381,7 +381,7 @@ protected function fire(string $event, array $args = [])
381381
* @param string $name
382382
* @param $value
383383
*/
384-
public function setOption(string $name, $value)
384+
public function setOption(string $name, $value): void
385385
{
386386
$this->options[$name] = $value;
387387
}
@@ -455,7 +455,7 @@ public function getOptions(): array
455455
/**
456456
* @param array $options
457457
*/
458-
public function setOptions(array $options)
458+
public function setOptions(array $options): void
459459
{
460460
$this->options = \array_merge($this->options, $options);
461461
}

0 commit comments

Comments
 (0)