-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Adding getRoutes() method to Router class.
- Dropping MiddlewareManager::remove() method as nothing was using it. - Adding test coverage for MiddlewareManager. - Adding additional test coverage for Router. - Adding test coverage for \class_method()
- Loading branch information
Brent Scheffler
committed
Aug 29, 2019
1 parent
afe1106
commit 87efec3
Showing
7 changed files
with
296 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Limber\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @covers ::class_method | ||
*/ | ||
class TestFunctions extends TestCase | ||
{ | ||
public function test_class_method() | ||
{ | ||
$this->assertTrue( | ||
\is_callable( | ||
\class_method(TestFunctions::class . "@test_class_method") | ||
) | ||
); | ||
} | ||
|
||
public function test_class_method_not_callable() | ||
{ | ||
$this->expectException(\Exception::class); | ||
\class_method("FooClass"); | ||
} | ||
} |
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,89 @@ | ||
<?php | ||
|
||
namespace Limber\Tests; | ||
|
||
use Capsule\Response; | ||
use Capsule\ResponseStatus; | ||
use Capsule\ServerRequest; | ||
use Limber\Middleware\CallableMiddlewareLayer; | ||
use Limber\Middleware\MiddlewareLayerInterface; | ||
use Limber\Middleware\MiddlewareManager; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
|
||
/** | ||
* @covers Limber\Middleware\MiddlewareManager | ||
* @covers Limber\Middleware\CallableMiddlewareLayer | ||
*/ | ||
class MiddlewareTest extends TestCase | ||
{ | ||
public function test_constructor_compiles_class_references() | ||
{ | ||
$middlewareManager = new MiddlewareManager([ | ||
SampleMiddleware::class | ||
]); | ||
|
||
$middleware = $middlewareManager->getMiddleware(); | ||
|
||
$this->assertTrue($middleware[0] instanceof MiddlewareLayerInterface); | ||
} | ||
|
||
public function test_constructor_compiles_callables() | ||
{ | ||
$middlewareManager = new MiddlewareManager([ | ||
function(ServerRequestInterface $request, callable $next): ResponseInterface { | ||
$request = $request->withAddedHeader("X-Request-Header", "Limber"); | ||
return $next($request); | ||
} | ||
]); | ||
|
||
$middleware = $middlewareManager->getMiddleware(); | ||
|
||
$this->assertTrue($middleware[0] instanceof CallableMiddlewareLayer); | ||
} | ||
|
||
public function test_constructor_adds_layer_instances() | ||
{ | ||
$middlewareManager = new MiddlewareManager([ | ||
new SampleMiddleware | ||
]); | ||
|
||
$middleware = $middlewareManager->getMiddleware(); | ||
|
||
$this->assertTrue($middleware[0] instanceof MiddlewareLayerInterface); | ||
} | ||
|
||
public function test_add() | ||
{ | ||
$middlewareManager = new MiddlewareManager([ | ||
new SampleMiddleware | ||
]); | ||
|
||
$middlewareManager->add(new SampleMiddleware); | ||
|
||
$middleware = $middlewareManager->getMiddleware(); | ||
|
||
$this->assertEquals(2, \count($middleware)); | ||
$this->assertTrue($middleware[1] instanceof MiddlewareLayerInterface); | ||
} | ||
|
||
public function test_run() | ||
{ | ||
$middlewareManager = new MiddlewareManager([ | ||
new SampleMiddleware | ||
]); | ||
|
||
$response = $middlewareManager->run( | ||
ServerRequest::create("get", "/books", null, [], [], [], []), | ||
function(ServerRequestInterface $request) { | ||
return new Response( | ||
ResponseStatus::OK | ||
); | ||
} | ||
); | ||
|
||
$this->assertEquals(ResponseStatus::OK, $response->getStatusCode()); | ||
$this->assertEquals("X-Sample-Middleware: Limber", $response->getHeaderLine("X-Sample-Middleware")); | ||
} | ||
} |
Oops, something went wrong.