From f757d7741c750140331e63f18b140eafa325e931 Mon Sep 17 00:00:00 2001 From: Prasetyo Date: Mon, 10 Aug 2015 15:20:40 +0700 Subject: [PATCH] add and fix test --- spec/ApplicationSpec.php | 4 +- .../Swoole/ServerRequestHandlerSpec.php | 11 +-- spec/Providers/KernelServiceProviderSpec.php | 72 +++++++++++++++++++ 3 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 spec/Providers/KernelServiceProviderSpec.php diff --git a/spec/ApplicationSpec.php b/spec/ApplicationSpec.php index b814822..2cf6630 100644 --- a/spec/ApplicationSpec.php +++ b/spec/ApplicationSpec.php @@ -187,7 +187,8 @@ public function it_should_throw_exception_when_server_is_not_exist(ContainerInte public function it_should_able_to_run( ContainerInterface $container, RouteCollector $collector, - ServerInterface $server + ServerInterface $server, + EventDispatcherInterface $event ) { /** * predictions @@ -208,6 +209,7 @@ public function it_should_able_to_run( ]]); $container->offsetGet('Server')->willReturn($server); $container->offsetGet('RouteCollector')->willReturn($collector); + $container->offsetGet('EventDispatcher')->willReturn($event); /** * test method diff --git a/spec/Lib/Server/Swoole/ServerRequestHandlerSpec.php b/spec/Lib/Server/Swoole/ServerRequestHandlerSpec.php index c8923a6..9c32918 100644 --- a/spec/Lib/Server/Swoole/ServerRequestHandlerSpec.php +++ b/spec/Lib/Server/Swoole/ServerRequestHandlerSpec.php @@ -7,15 +7,15 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Relay\RelayBuilder; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Vinnige\Contracts\ContainerInterface; use Vinnige\Contracts\ServerResponderInterface; -use Vinnige\Lib\ErrorHandler\ErrorHandler; class ServerRequestHandlerSpec extends ObjectBehavior { - public function let(ContainerInterface $container) + public function let(ContainerInterface $container, EventDispatcherInterface $event) { - $this->beConstructedWith($container); + $this->beConstructedWith($container, $event); } public function it_is_initializable() @@ -30,7 +30,8 @@ public function it_should_able_handle_incoming_request( ResponseInterface $response, RelayBuilder $relayBuilder, ContainerInterface $container, - ServerResponderInterface $serverResponder + ServerResponderInterface $serverResponder, + EventDispatcherInterface $event ) { unset($GLOBALS['_COOKIE']); unset($GLOBALS['_GET']); @@ -46,6 +47,8 @@ public function it_should_able_handle_incoming_request( $container->offsetGet('Middlewares')->willReturn([]); + $container->offsetGet('EventDispatcher')->willReturn($event); + $relayBuilder->newInstance([])->willReturn( function (ServerRequestInterface $req, ResponseInterface $res) { return $res; diff --git a/spec/Providers/KernelServiceProviderSpec.php b/spec/Providers/KernelServiceProviderSpec.php new file mode 100644 index 0000000..6425d0f --- /dev/null +++ b/spec/Providers/KernelServiceProviderSpec.php @@ -0,0 +1,72 @@ +container = new LaravelContainer(new Container()); + $this->container['Config'] = new Config([ + 'http.streams' => [ + StringStream::class => '' + ], + 'http.response' => [ + 'class' => Response::class, + 'protocol.version' => '1.1', + 'header' => [], + 'stream' => StringStream::class + ], + ]); + + $this->beConstructedWith(); + + $this->register($this->container); + } + + public function it_is_initializable() + { + $this->shouldHaveType('Vinnige\Providers\KernelServiceProvider'); + } + + public function it_should_return_http_message() + { + $this->container['Http']; + } + + public function it_should_return_request(HTTP $http) + { + $this->container['Http'] = $http; + $this->container['Request']; + } + + public function it_should_return_response() + { + $this->container['Response']; + } + + public function it_should_return_event_dispatcher() + { + $this->container['EventDispatcher']; + } + + public function it_should_able_to_register_event_listener( + ContainerInterface $container, + EventDispatcherInterface $event + ) { + $this->subscribe($container, $event); + } +}