Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

Commit

Permalink
Complete tests, fix #41
Browse files Browse the repository at this point in the history
  • Loading branch information
leocavalcante committed Apr 21, 2017
1 parent 644b543 commit d857cb2
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions phpstan.neon
@@ -1,3 +1,4 @@
parameters:
excludes_analyse:
- tests/fixtures/foo.php
- src/Graphql/SubscriptionManager.php
4 changes: 3 additions & 1 deletion src/Graphql/SubscriptionManager.php
Expand Up @@ -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));
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Graphql/SubscriptionServer.php
Expand Up @@ -9,6 +9,8 @@

class SubscriptionServer implements MessageComponentInterface, WsServerInterface
{
protected $manager;

public function __construct(SubscriptionManager $manager)
{
$this->manager = $manager;
Expand Down
2 changes: 1 addition & 1 deletion src/Ratchet/Ratchet.php
Expand Up @@ -34,7 +34,7 @@ function init($port = null)

Container\set(RATCHET_CONNECTIONS, new \SplObjectStorage());

$server->run();
return $server;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Ratchet/RatchetTest.php
Expand Up @@ -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 () {
Expand Down
18 changes: 18 additions & 0 deletions tests/Unit/Route/RoutePsr7Test.php
Expand Up @@ -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']);
Expand Down

0 comments on commit d857cb2

Please sign in to comment.