Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This commit fixes the issue #190 Write-a-functional-test-to-check-the… #198

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions tests/functional/LegalCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace ChessServer\Tests\Functional;

use ChessServer\Tests\AbstractFunctionalTestCase;
use React\Promise\Deferred;
use React\Socket\Connector;
use React\Socket\ConnectionInterface;

include_once __DIR__."/StartCommandTest.php";


class LegalCommandTest extends AbstractFunctionalTestCase
{
public static $connector;

public static $deferred;

public static $promise;

public static $startcommandtest;

protected function setUp(): void
{
self::$connector = new Connector();
self::$deferred = new Deferred();
self::$promise = self::$deferred->promise();
self::$startcommandtest = new StartCommandTest();
self::$startcommandtest->setUp();
}

/**
* @test
*/
public function start_classical_fen(){
self::$startcommandtest->start_classical_fen();
}

/**
* @depends start_classical_fen
*/

public function legal_e2()
{
self::$connector->connect("$this->host:$this->port")->then(function (ConnectionInterface $conn) {
$conn->on('data', function ($data) use ($conn) {
self::$deferred->resolve($data);
$conn->close();
});
$conn->write('/legal e2');
});

$response = \React\Async\await(self::$promise->then(function (string $result): string {
return $result;
}));

$expected = '{"\/legal":{"color":"w","id":"P","fen":{"e3":"rnbqkbnr\/pppppppp\/8\/8\/8\/4P3\/PPPP1PPP\/RNBQKBNR b KQkq -","e4":"rnbqkbnr\/pppppppp\/8\/8\/4P3\/8\/PPPP1PPP\/RNBQKBNR b KQkq e3"}}}';

$this->assertEquals($expected, $response);
}

}