From 9c670418bd679dc2a38227df76c8e61781b0e913 Mon Sep 17 00:00:00 2001 From: kaifsaif Date: Tue, 3 Oct 2023 18:41:44 +0530 Subject: [PATCH 1/2] This commit fixes the issue #190 Write-a-functional-test-to-check-the-/legal-command --- tests/functional/LegalCommandTest.php | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 tests/functional/LegalCommandTest.php diff --git a/tests/functional/LegalCommandTest.php b/tests/functional/LegalCommandTest.php new file mode 100644 index 00000000..6f359a46 --- /dev/null +++ b/tests/functional/LegalCommandTest.php @@ -0,0 +1,67 @@ +promise(); + } + + /** + * @test + */ + + 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("/start classical fen"); + }); + + $response = \React\Async\await(self::$promise->then(function (string $result): string { + return $result; + })); + + $expected = '{"\/start":{"variant":"classical","mode":"fen","fen":"rnbqkbnr\/pppppppp\/8\/8\/8\/8\/PPPPPPPP\/RNBQKBNR w KQkq -"}}'; + + if($this->assertEquals($expected,$response)){ + 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); + } + + } + +} \ No newline at end of file From 1320753e21ba18483060e79ccc53bcf14ffc9d7a Mon Sep 17 00:00:00 2001 From: kaifkh20 Date: Thu, 5 Oct 2023 21:10:54 +0530 Subject: [PATCH 2/2] Updated The LegalCommandTest file to not rewrite start_classical_fen method everytime --- tests/functional/LegalCommandTest.php | 43 ++++++++++++--------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/tests/functional/LegalCommandTest.php b/tests/functional/LegalCommandTest.php index 6f359a46..a8d1be7f 100644 --- a/tests/functional/LegalCommandTest.php +++ b/tests/functional/LegalCommandTest.php @@ -7,6 +7,8 @@ use React\Socket\Connector; use React\Socket\ConnectionInterface; +include_once __DIR__."/StartCommandTest.php"; + class LegalCommandTest extends AbstractFunctionalTestCase { @@ -16,52 +18,45 @@ class LegalCommandTest extends AbstractFunctionalTestCase 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(); + self::$deferred->resolve($data); + $conn->close(); }); - $conn->write("/start classical fen"); + $conn->write('/legal e2'); }); $response = \React\Async\await(self::$promise->then(function (string $result): string { return $result; })); - $expected = '{"\/start":{"variant":"classical","mode":"fen","fen":"rnbqkbnr\/pppppppp\/8\/8\/8\/8\/PPPPPPPP\/RNBQKBNR w KQkq -"}}'; - - if($this->assertEquals($expected,$response)){ - 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); - } + $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); } -} \ No newline at end of file +}