From d857cb2b9090b934bfb9fa8138c3a3c6074c0b14 Mon Sep 17 00:00:00 2001 From: leocavalcante Date: Fri, 21 Apr 2017 13:30:38 -0300 Subject: [PATCH] Complete tests, fix #41 --- phpstan.neon | 1 + src/Graphql/SubscriptionManager.php | 4 +++- src/Graphql/SubscriptionServer.php | 2 ++ src/Ratchet/Ratchet.php | 2 +- tests/Unit/Ratchet/RatchetTest.php | 9 +++++++++ tests/Unit/Route/RoutePsr7Test.php | 18 ++++++++++++++++++ 6 files changed, 34 insertions(+), 2 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 5a32c2db..a19df386 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,3 +1,4 @@ parameters: excludes_analyse: - tests/fixtures/foo.php + - src/Graphql/SubscriptionManager.php diff --git a/src/Graphql/SubscriptionManager.php b/src/Graphql/SubscriptionManager.php index 43cb0bbd..b556ad03 100644 --- a/src/Graphql/SubscriptionManager.php +++ b/src/Graphql/SubscriptionManager.php @@ -59,13 +59,15 @@ public function handleSubscriptionStart(ConnectionInterface $conn, array $data) 'type' => Graphql\SUBSCRIPTION_SUCCESS, 'id' => $data['id'], ]; + + $conn->send(json_encode($response)); } catch (\Exception $exception) { $response = [ 'type' => Graphql\SUBSCRIPTION_FAIL, 'id' => $data['id'], 'payload' => $exception->getMessage(), ]; - } finally { + $conn->send(json_encode($response)); } } diff --git a/src/Graphql/SubscriptionServer.php b/src/Graphql/SubscriptionServer.php index 3ebf3bd6..7bffbc5d 100644 --- a/src/Graphql/SubscriptionServer.php +++ b/src/Graphql/SubscriptionServer.php @@ -9,6 +9,8 @@ class SubscriptionServer implements MessageComponentInterface, WsServerInterface { + protected $manager; + public function __construct(SubscriptionManager $manager) { $this->manager = $manager; diff --git a/src/Ratchet/Ratchet.php b/src/Ratchet/Ratchet.php index c5ace10f..5b9d7430 100644 --- a/src/Ratchet/Ratchet.php +++ b/src/Ratchet/Ratchet.php @@ -34,7 +34,7 @@ function init($port = null) Container\set(RATCHET_CONNECTIONS, new \SplObjectStorage()); - $server->run(); + return $server; } /** diff --git a/tests/Unit/Ratchet/RatchetTest.php b/tests/Unit/Ratchet/RatchetTest.php index 88f4bb1e..2e0ce118 100644 --- a/tests/Unit/Ratchet/RatchetTest.php +++ b/tests/Unit/Ratchet/RatchetTest.php @@ -3,11 +3,20 @@ namespace Siler\Test\Unit; use Ratchet\ConnectionInterface; +use Ratchet\Server\IoServer; use Siler\Container; use Siler\Ratchet; class RatchetTest extends \PHPUnit\Framework\TestCase { + public function testInit() + { + $server = Ratchet\init(); + + $this->assertInstanceOf(\SplObjectStorage::class, Container\get(Ratchet\RATCHET_CONNECTIONS)); + $this->assertInstanceOf(IoServer::class, $server); + } + public function testConnected() { $expected = function () { diff --git a/tests/Unit/Route/RoutePsr7Test.php b/tests/Unit/Route/RoutePsr7Test.php index 94c011ff..5bfc7511 100644 --- a/tests/Unit/Route/RoutePsr7Test.php +++ b/tests/Unit/Route/RoutePsr7Test.php @@ -35,6 +35,24 @@ public function testRoute() $this->assertEquals('foo', $actual); } + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testNullRoute() + { + $server = ['REQUEST_URI' => '/foo']; + $request = ServerRequestFactory::fromGlobals($server); + + Route\psr7($request); + + $actual = Route\get('/bar', function () { + return 'baz'; + }); + + $this->assertNull($actual); + } + public function teardown() { unset(Container\Container::getInstance()->values['psr7_request']);