Skip to content

Commit

Permalink
Merge pull request #9 from nazg-hack/feature/added-namespace
Browse files Browse the repository at this point in the history
added namespace NazgTest
  • Loading branch information
ytake authored Jan 22, 2018
2 parents 64ca52e + 57894b4 commit 850aea9
Show file tree
Hide file tree
Showing 24 changed files with 82 additions and 40 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
]
},
"autoload-dev": {
"classmap": [
"tests/"
],
"psr-4": {
"NazgTest\\": "tests/"
},
"files": [
"tests/Struct/Shapes.php"
]
Expand Down
5 changes: 3 additions & 2 deletions src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ protected function middlewareProcessor(
ContainerInterface $container,
): RequestHandlerInterface {
$appMiddleware =
$this->im->concat($this->middleware())
|> $$->concat($middleware)->toArray();
$this->im
->concat($this->middleware())
->concat($middleware)->toArray();
$dispatcher = new Dispatcher(
new MiddlewareStack(
$appMiddleware,
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/Exception/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function toImmMap(\Exception $e): ExceptionMap {
'line' => $e->getLine(),
'trace' => map(
$e->getTrace(),
$v ==> (new Map($v)) |> $$->removeKey('args') |> $$->toArray(),
$v ==> (new Map($v))->removeKey('args')->toArray(),
),
],
);
Expand Down
9 changes: 5 additions & 4 deletions src/Foundation/Exception/ExceptionServiceModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ private function invariantExceptionHandler(
FactoryContainer $container,
): ExceptionHandleInterface {
$instance = $container->get(ExceptionHandleInterface::class);
if ($instance instanceof ExceptionHandleInterface) {
return $instance;
}
throw new \LogicException();
invariant(
$instance instanceof ExceptionHandleInterface,
"Interface '\Nazg\Exceptions\ExceptionHandleInterface' is not implemented by this class",
);
return $instance;
}
}
3 changes: 3 additions & 0 deletions tests/Action/IndexAction.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?hh // strict

namespace NazgTest\Action;

use NazgTest\Responder\IndexResponder;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Interop\Http\Server\MiddlewareInterface;
Expand Down
2 changes: 2 additions & 0 deletions tests/Action/ParameterAction.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?hh

namespace NazgTest\Action;

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Interop\Http\Server\MiddlewareInterface;
Expand Down
5 changes: 4 additions & 1 deletion tests/Action/ValidateAction.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?hh

namespace NazgTest\Action;

use Nazg\Foundation\Validation\Attribute;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Interop\Http\Server\MiddlewareInterface;
use Interop\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\JsonResponse;
use NazgTest\Validation\MockValidateActionFaild;

final class ValidateAction implements MiddlewareInterface {

<<RequestValidation(\MockValidateActionFaild::class)>>
<<RequestValidation(MockValidateActionFaild::class)>>
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler,
Expand Down
2 changes: 2 additions & 0 deletions tests/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?hh

namespace NazgTest;

use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use Nazg\Foundation\Application;
Expand Down
2 changes: 2 additions & 0 deletions tests/Exception/ExceptionHandlerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?hh // strict

namespace NazgTest\Exception;

use PHPUnit\Framework\TestCase;
use Ytake\HHContainer\ServiceModule;
use Ytake\HHContainer\FactoryContainer;
Expand Down
2 changes: 2 additions & 0 deletions tests/Log/LogServiceModuleTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?hh

namespace NazgTest\Middleware;

use Nazg\Log\LogServiceModule;
use PHPUnit\Framework\TestCase;
use Ytake\HHContainer\ServiceModule;
Expand Down
2 changes: 2 additions & 0 deletions tests/Middleware/FakeAttributeMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?hh // strict

namespace NazgTest\Middleware;

use Interop\Http\Server\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down
2 changes: 2 additions & 0 deletions tests/Middleware/FakeThrowExceptionMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?hh // strict

namespace NazgTest\Middleware;

use Interop\Http\Server\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down
3 changes: 3 additions & 0 deletions tests/Middleware/LogExceptionMiddlewareTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?hh

namespace NazgTest\Middleware;

use Nazg\Log\LogServiceModule;
use Nazg\Middleware\LogExceptionMiddleware;
use PHPUnit\Framework\TestCase;
Expand All @@ -10,6 +12,7 @@
use Nazg\Heredity\MiddlewareStack;
use Nazg\Heredity\PsrContainerResolver;
use Nazg\Foundation\Middleware\Dispatcher;
use NazgTest\StubRequestHandler;

class LogExceptionMiddlewareTest extends TEstCase {
/**
Expand Down
5 changes: 3 additions & 2 deletions tests/Middleware/OverrideLogServiceModule.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?hh

namespace NazgTest\Middleware;

use Ytake\HHContainer\ServiceModule;
use Ytake\HHContainer\FactoryContainer;
use Psr\Log\LoggerInterface;
use Monolog\Logger;
use Monolog\Monolog;
use Monolog\Handler\StreamHandler;

class OverrideLogServiceModule extends Nazg\Log\LogServiceModule {
class OverrideLogServiceModule extends \Nazg\Log\LogServiceModule {

const string LOG_FILE = __DIR__ . '/../logs/tests.log';

<<__Override>>
protected function defaultLogger(): LoggerInterface {
$monolog = new \Monolog\Logger("Nazg.Log");
$monolog->pushHandler(
Expand Down
4 changes: 3 additions & 1 deletion tests/Middleware/SimpleCorsMiddlewareTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?hh

namespace NazgTest\Middleware;

use Nazg\Http\HttpMethod;
use Nazg\Middleware\SimpleCorsMiddleware;
use Nazg\Middleware\AccessControl;
Expand All @@ -20,7 +22,7 @@ public function testShouldThrowException(): void {
[SimpleCorsMiddleware::class],
new PsrContainerResolver($container),
),
new StubRequestHandler(),
new \NazgTest\StubRequestHandler(),
);
$response = $heredity->handle(
ServerRequestFactory::fromGlobals(),
Expand Down
4 changes: 3 additions & 1 deletion tests/Responder/IndexResponder.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?hh

namespace NazgTest\Responder;

use Psr\Http\Message\ResponseInterface;
use Zend\Diactoros\Response\JsonResponse;
use IndexStructure;
use NazgTest\IndexStructure;

final class IndexResponder {

Expand Down
8 changes: 5 additions & 3 deletions tests/Routing/RouterTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?hh

namespace NazgTest\Routing;

use PHPUnit\Framework\TestCase;
use Nazg\Routing\Router;
use Nazg\Foundation\Service;
Expand All @@ -12,7 +14,7 @@ public function testShouldBeMatchRoute(): void {
$router = new Router(ImmMap{
HttpMethod::GET => ImmMap {
'/' => ImmVector{
IndexAction::class
\NazgTest\Action\IndexAction::class
},
},
});
Expand All @@ -23,7 +25,7 @@ public function testShouldBeMatchRoute(): void {
])
);
$this->assertInternalType('array', $match);
$this->assertContains(\IndexAction::class, $match[0]);
$this->assertContains(\NazgTest\Action\IndexAction::class, $match[0][0]);
}

/**
Expand All @@ -32,7 +34,7 @@ public function testShouldBeMatchRoute(): void {
public function testShouldNotBeMatchRoute(): void {
$router = new Router(ImmMap{
HttpMethod::GET => ImmMap {
'/' => ImmVector{IndexAction::class},
'/' => ImmVector{\NazgTest\Action\IndexAction::class},
},
});
$match = $router->routePsr7Request(
Expand Down
2 changes: 2 additions & 0 deletions tests/Struct/Shapes.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?hh // strict

namespace NazgTest;

type IndexStructure = shape('language' => string, 'version' => string);
2 changes: 2 additions & 0 deletions tests/StubRequestHandler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?hh

namespace NazgTest;

use Interop\Http\Server\RequestHandlerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
Expand Down
23 changes: 14 additions & 9 deletions tests/TestingServiceModule.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
<?hh // strict

namespace NazgTest;

use Ytake\HHContainer\FactoryContainer;
use Ytake\HHContainer\ServiceModule;

class TestingServiceModule extends ServiceModule {
public function provide(FactoryContainer $container): void {
$container->set(stdClass::class, $container ==> new stdClass());
$container->set(
\IndexAction::class,
$container ==> new \IndexAction()
\NazgTest\Action\IndexAction::class,
$container ==> new \NazgTest\Action\IndexAction()
);
$container->set(
\NazgTest\Action\ParameterAction::class,
$container ==> new \NazgTest\Action\ParameterAction()
);
$container->set(
\ParameterAction::class,
$container ==> new \ParameterAction()
\NazgTest\Action\ValidateAction::class,
$container ==> new \NazgTest\Action\ValidateAction()
);
$container->set(
\ValidateAction::class,
$container ==> new \ValidateAction()
\NazgTest\Middleware\FakeAttributeMiddleware::class,
$container ==> new \NazgTest\Middleware\FakeAttributeMiddleware()
);
$container->set(
\FakeAttributeMiddleware::class,
$container ==> new \FakeAttributeMiddleware()
\NazgTest\Validation\MockValidateActionFaild::class,
$container ==> new \NazgTest\Validation\MockValidateActionFaild()
);
}
}
2 changes: 2 additions & 0 deletions tests/Validation/MockValidateActionFaild.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?hh // strict

namespace NazgTest\Validation;

use Nazg\Foundation\Validation\Validator;
use Psr\Http\Message\ServerRequestInterface;

Expand Down
2 changes: 2 additions & 0 deletions tests/Validation/ValidatorTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?hh

namespace NazgTest\Validation;

use Facebook\TypeAssert;
use PHPUnit\Framework\TestCase;
use Nazg\Foundation\Validation\Validator;
Expand Down
6 changes: 2 additions & 4 deletions tests/config/modules.testing.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?hh

use Nazg\Foundation\Service;

return [
Service::MODULES => ImmVector{
\TestingServiceModule::class,
\Nazg\Foundation\Service::MODULES => ImmVector{
\NazgTest\TestingServiceModule::class,
},
];
19 changes: 10 additions & 9 deletions tests/config/routes.testing.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?hh

use Nazg\Foundation\Service;
use Nazg\Http\HttpMethod;

return [
Service::ROUTES => ImmMap {
HttpMethod::GET => ImmMap {
'/' => ImmVector {IndexAction::class},
\Nazg\Foundation\Service::ROUTES => ImmMap {
\Nazg\Http\HttpMethod::GET => ImmMap {
'/' => ImmVector {
\NazgTest\Action\IndexAction::class
},
'/testing/{id}' => ImmVector {
FakeAttributeMiddleware::class,
ParameterAction::class,
\NazgTest\Middleware\FakeAttributeMiddleware::class,
\NazgTest\Action\ParameterAction::class,
},
'/validate/{id}' => ImmVector {
\NazgTest\Action\ValidateAction::class
},
'/validate/{id}' => ImmVector {ValidateAction::class},
},
},
];

0 comments on commit 850aea9

Please sign in to comment.