-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix debug classes and add more tests (#224)
- Loading branch information
Showing
7 changed files
with
186 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Router\Tests\Debug; | ||
|
||
use Nyholm\Psr7\ServerRequest; | ||
use PHPUnit\Framework\TestCase; | ||
use Yiisoft\Router\CurrentRoute; | ||
use Yiisoft\Router\Debug\RouterCollector; | ||
use Yiisoft\Router\Debug\UrlMatcherInterfaceProxy; | ||
use Yiisoft\Router\MatchingResult; | ||
use Yiisoft\Router\Route; | ||
use Yiisoft\Router\Tests\Support\UrlMatcherStub; | ||
use Yiisoft\Test\Support\Container\SimpleContainer; | ||
|
||
final class UrlMatcherInterfaceProxyTest extends TestCase | ||
{ | ||
public function testBase(): void | ||
{ | ||
$request = new ServerRequest('GET', '/'); | ||
$route = Route::get('/'); | ||
$arguments = ['a' => 19]; | ||
$result = MatchingResult::fromSuccess($route, $arguments); | ||
|
||
$currentRoute = new CurrentRoute(); | ||
$currentRoute->setRouteWithArguments($result->route(), $result->arguments()); | ||
|
||
$collector = new RouterCollector( | ||
new SimpleContainer([ | ||
CurrentRoute::class => $currentRoute, | ||
]) | ||
); | ||
$collector->startup(); | ||
|
||
$proxy = new UrlMatcherInterfaceProxy(new UrlMatcherStub($result), $collector); | ||
|
||
$proxyResult = $proxy->match($request); | ||
$summary = $collector->getSummary(); | ||
|
||
$this->assertSame($result, $proxyResult); | ||
$this->assertGreaterThan(0, $summary['router']['matchTime']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Router\Tests\Support; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
use Yiisoft\Router\MatchingResult; | ||
use Yiisoft\Router\UrlMatcherInterface; | ||
|
||
final class UrlMatcherStub implements UrlMatcherInterface | ||
{ | ||
public function __construct( | ||
private MatchingResult $result | ||
) { | ||
} | ||
|
||
public function match(ServerRequestInterface $request): MatchingResult | ||
{ | ||
return $this->result; | ||
} | ||
} |