Skip to content

Commit ec259cc

Browse files
authored
Merge pull request #42 from ChessCom/BP/PHP8
PHP8 support
2 parents 2813c62 + 8364b43 commit ec259cc

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ php:
55
- "7.2"
66
- "7.3"
77
- "7.4"
8+
- "8.0"
89

910
matrix:
1011
fast_finish: true

Tests/ChessGameTest.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ChessGameTest extends TestCase
99
/** @var ChessGame */
1010
private $game;
1111

12-
public function setUp()
12+
public function setUp(): void
1313
{
1414
$this->game = new ChessGame();
1515
}
@@ -1096,6 +1096,20 @@ public function testGameShouldEndInFiveFoldRepetition()
10961096
$this->assertFiveFoldRepetitionDraw();
10971097
}
10981098

1099+
public function testNotInBasicDrawTwoWhiteVsTwoBlack()
1100+
{
1101+
$fen = '8/8/8/8/4k3/8/3Kn3/6Q1 w - -';
1102+
$this->game->resetGame($fen);
1103+
$this->assertFalse($this->game->inBasicDraw());
1104+
}
1105+
1106+
public function testInBasicDrawThreePiecesRemained()
1107+
{
1108+
$fen = '8/8/8/8/4k3/8/3K4/6n1 w - -';
1109+
$this->game->resetGame($fen);
1110+
$this->assertTrue($this->game->inBasicDraw());
1111+
}
1112+
10991113
private function assertFiveFoldRepetitionDraw()
11001114
{
11011115
$this->assertTrue($this->game->inRepetitionDraw());

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"require-dev": {
1818
"friendsofphp/php-cs-fixer": "~2.3",
19-
"phpunit/phpunit": "^7.3"
19+
"phpunit/phpunit": "^7.3 || ^9.5"
2020
},
2121
"config": {
2222
"bin-dir": "bin"

src/Chess/Game/ChessGame.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ protected function getSquareFromParsedMove($parsedMove, $color = null)
600600

601601
if (count($legalMoves) != 1) {
602602
$square = $col = $row = null;
603-
$pieces = implode($legalMoves, ' ');
603+
$pieces = implode(' ', $legalMoves);
604604

605605
return $this->raiseError(
606606
self::GAMES_CHESS_ERROR_TOO_AMBIGUOUS,
@@ -1448,9 +1448,11 @@ public function inBasicDraw()
14481448

14491449
$playerWith3Pieces = count($whitePieces) === 3 ? $whitePieces : $blackPieces;
14501450

1451-
if (in_array($playerWith3Pieces[0], array('K', 'N'))
1451+
if (count($playerWith3Pieces) === 3
1452+
&& in_array($playerWith3Pieces[0], array('K', 'N'))
14521453
&& in_array($playerWith3Pieces[1], array('K', 'N'))
1453-
&& in_array($playerWith3Pieces[2], array('K', 'N'))) {
1454+
&& in_array($playerWith3Pieces[2], array('K', 'N'))
1455+
) {
14541456
return true; //KNN vs K
14551457
}
14561458

0 commit comments

Comments
 (0)