Skip to content

Commit 7d52148

Browse files
committed
code updates for warnings in php8, test coverage
1 parent 4539545 commit 7d52148

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

Tests/ChessGameTest.php

Lines changed: 13 additions & 1 deletion
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,18 @@ public function testGameShouldEndInFiveFoldRepetition()
10961096
$this->assertFiveFoldRepetitionDraw();
10971097
}
10981098

1099+
/**
1100+
* PHP8
1101+
*
1102+
* E_WARNING: Undefined array key 2
1103+
*/
1104+
public function testInBasicDrawWith3Pieces()
1105+
{
1106+
$fen = '8/8/8/8/4k3/8/3K4/6n1 w - -';
1107+
$this->game->resetGame($fen);
1108+
$this->assertTrue($this->game->inBasicDraw());
1109+
}
1110+
10991111
private function assertFiveFoldRepetitionDraw()
11001112
{
11011113
$this->assertTrue($this->game->inRepetitionDraw());

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
}
1313
],
1414
"require": {
15-
"php": ">=8.0"
15+
"php": ">=7.1"
1616
},
1717
"require-dev": {
1818
"friendsofphp/php-cs-fixer": "~2.3",
19-
"phpunit/phpunit": "^9.5"
19+
"phpunit/phpunit": "^7.3 || ^9.5"
2020
},
2121
"config": {
2222
"bin-dir": "bin"

src/Chess/Game/ChessGame.php

Lines changed: 5 additions & 3 deletions
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)