From f77408fda83b743018a9952e2b0827033da1e9da Mon Sep 17 00:00:00 2001 From: Pen-y-Fan <40126936+Pen-y-Fan@users.noreply.github.com> Date: Sun, 3 Oct 2021 23:27:32 +0100 Subject: [PATCH] Bump PHPUnit to 9.5 - Add script to composer to run tests - update README.md with `composer test` script - add phpunit.xml (PHPUnit config file) - PHP minimum version now 7.4, PHP 8 will now `composer install` - add .phpunit.result.cache to git ignore list - update all Tests with @expectedException to expectException - update CommandTestCase setUp to return type of void Tested with PHP 8.0.8, all 33 tests are passing. --- .gitignore | 1 + README.md | 4 ++++ composer.json | 7 +++++-- phpunit.xml | 2 +- tests/unit/Command/AsciiTest.php | 3 ++- tests/unit/Command/CapturesTest.php | 3 ++- tests/unit/Command/HistoryTest.php | 3 ++- tests/unit/Command/IsCheckTest.php | 3 ++- tests/unit/Command/IsMateTest.php | 3 ++- tests/unit/Command/PieceTest.php | 3 ++- tests/unit/Command/PiecesTest.php | 5 +++-- tests/unit/Command/QuitTest.php | 3 ++- tests/unit/Command/StartTest.php | 7 ++++--- tests/unit/Command/StatusTest.php | 3 ++- tests/unit/Command/TakebackTest.php | 7 ++++--- tests/unit/Command/UndoMoveTest.php | 3 ++- tests/unit/CommandTestCase.php | 2 +- 17 files changed, 41 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 88b53c68..2ce2b5b0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ /ssl/*.key /storage/*.log +/.phpunit.result.cache diff --git a/README.md b/README.md index e50038c1..bb739007 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,10 @@ Create an `.env` file: $ cp .env.example .env +Run all the tests + + $ composer test + ### WebSocket Server Start the server: diff --git a/composer.json b/composer.json index 381ea1b8..adb80af0 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=7.1", + "php": ">=7.4", "chesslablab/php-chess": "dev-master", "rubix/ml": "^1.1", "cboden/ratchet": "^0.4", @@ -24,7 +24,7 @@ "monolog/monolog": "^2.3" }, "require-dev": { - "phpunit/phpunit": "~5.7" + "phpunit/phpunit": "^9.5" }, "autoload": { "psr-4": { @@ -35,5 +35,8 @@ "psr-4": { "ChessServer\\Tests\\Unit\\": "tests/unit/" } + }, + "scripts": { + "tests": "phpunit" } } diff --git a/phpunit.xml b/phpunit.xml index 9b9d4856..6dd83f3b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,6 +6,6 @@ - tests + tests diff --git a/tests/unit/Command/AsciiTest.php b/tests/unit/Command/AsciiTest.php index 397d531f..9a79e4b2 100644 --- a/tests/unit/Command/AsciiTest.php +++ b/tests/unit/Command/AsciiTest.php @@ -3,6 +3,7 @@ namespace ChessServer\Tests\Unit\Command; use ChessServer\Command\AsciiCommand; +use ChessServer\Exception\ParserException; use ChessServer\Tests\Unit\CommandTestCase; class AsciiTest extends CommandTestCase @@ -20,10 +21,10 @@ public function validate_ascii() /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_ascii_foo() { + $this->expectException(ParserException::class); self::$parser->validate('/ascii foo'); } } diff --git a/tests/unit/Command/CapturesTest.php b/tests/unit/Command/CapturesTest.php index 29dc3be3..e2190605 100644 --- a/tests/unit/Command/CapturesTest.php +++ b/tests/unit/Command/CapturesTest.php @@ -3,6 +3,7 @@ namespace ChessServer\Tests\Unit\Command; use ChessServer\Command\CapturesCommand; +use ChessServer\Exception\ParserException; use ChessServer\Tests\Unit\CommandTestCase; class CapturesTest extends CommandTestCase @@ -20,10 +21,10 @@ public function validate_captures() /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_captures_foo() { + $this->expectException(ParserException::class); self::$parser->validate('/captures foo'); } } diff --git a/tests/unit/Command/HistoryTest.php b/tests/unit/Command/HistoryTest.php index 2503d0d6..fef945cd 100644 --- a/tests/unit/Command/HistoryTest.php +++ b/tests/unit/Command/HistoryTest.php @@ -3,6 +3,7 @@ namespace ChessServer\Tests\Unit\Command; use ChessServer\Command\HistoryCommand; +use ChessServer\Exception\ParserException; use ChessServer\Tests\Unit\CommandTestCase; class HistoryTest extends CommandTestCase @@ -20,10 +21,10 @@ public function validate_history() /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_history_foo() { + $this->expectException(ParserException::class); self::$parser->validate('/history foo'); } } diff --git a/tests/unit/Command/IsCheckTest.php b/tests/unit/Command/IsCheckTest.php index bc80500b..10562686 100644 --- a/tests/unit/Command/IsCheckTest.php +++ b/tests/unit/Command/IsCheckTest.php @@ -3,6 +3,7 @@ namespace ChessServer\Tests\Unit\Command; use ChessServer\Command\IsCheckCommand; +use ChessServer\Exception\ParserException; use ChessServer\Tests\Unit\CommandTestCase; class IsCheckTest extends CommandTestCase @@ -20,10 +21,10 @@ public function validate_ischeck() /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_ischeck_foo() { + $this->expectException(ParserException::class); self::$parser->validate('/ischeck foo'); } } diff --git a/tests/unit/Command/IsMateTest.php b/tests/unit/Command/IsMateTest.php index bc2c0b28..035b103a 100644 --- a/tests/unit/Command/IsMateTest.php +++ b/tests/unit/Command/IsMateTest.php @@ -3,6 +3,7 @@ namespace ChessServer\Tests\Unit\Command; use ChessServer\Command\IsMateCommand; +use ChessServer\Exception\ParserException; use ChessServer\Tests\Unit\CommandTestCase; class IsMateTest extends CommandTestCase @@ -20,10 +21,10 @@ public function validate_ismate() /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_ismate_foo() { + $this->expectException(ParserException::class); self::$parser->validate('/ismate foo'); } } diff --git a/tests/unit/Command/PieceTest.php b/tests/unit/Command/PieceTest.php index 0008eb38..aaa3d79b 100644 --- a/tests/unit/Command/PieceTest.php +++ b/tests/unit/Command/PieceTest.php @@ -3,6 +3,7 @@ namespace ChessServer\Tests\Unit\Command; use ChessServer\Command\PieceCommand; +use ChessServer\Exception\ParserException; use ChessServer\Tests\Unit\CommandTestCase; class PieceTest extends CommandTestCase @@ -31,10 +32,10 @@ public function validate_piece_h1() /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_piece_e4_e5() { + $this->expectException(ParserException::class); self::$parser->validate('/piece e4 e5'); } } diff --git a/tests/unit/Command/PiecesTest.php b/tests/unit/Command/PiecesTest.php index 6b72cb79..fbbf0612 100644 --- a/tests/unit/Command/PiecesTest.php +++ b/tests/unit/Command/PiecesTest.php @@ -3,6 +3,7 @@ namespace ChessServer\Tests\Unit\Command; use ChessServer\Command\PiecesCommand; +use ChessServer\Exception\ParserException; use ChessServer\Tests\Unit\CommandTestCase; class PiecesTest extends CommandTestCase @@ -31,19 +32,19 @@ public function validate_pieces_b() /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_pieces_w_foo() { + $this->expectException(ParserException::class); self::$parser->validate('/pieces w foo'); } /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_pieces_b_foo() { + $this->expectException(ParserException::class); self::$parser->validate('/pieces b foo'); } } diff --git a/tests/unit/Command/QuitTest.php b/tests/unit/Command/QuitTest.php index d9e0441e..31884d97 100644 --- a/tests/unit/Command/QuitTest.php +++ b/tests/unit/Command/QuitTest.php @@ -3,6 +3,7 @@ namespace ChessServer\Tests\Unit\Command; use ChessServer\Command\QuitCommand; +use ChessServer\Exception\ParserException; use ChessServer\Tests\Unit\CommandTestCase; class QuitTest extends CommandTestCase @@ -20,10 +21,10 @@ public function validate_quit() /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_quit_foo() { + $this->expectException(ParserException::class); self::$parser->validate('/quit foo'); } } diff --git a/tests/unit/Command/StartTest.php b/tests/unit/Command/StartTest.php index 64d47679..a5993208 100644 --- a/tests/unit/Command/StartTest.php +++ b/tests/unit/Command/StartTest.php @@ -3,6 +3,7 @@ namespace ChessServer\Tests\Unit\Command; use ChessServer\Command\StartCommand; +use ChessServer\Exception\ParserException; use ChessServer\Tests\Unit\CommandTestCase; class StartTest extends CommandTestCase @@ -20,28 +21,28 @@ public function validate_start_analysis() /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_start_analysis_w() { + $this->expectException(ParserException::class); self::$parser->validate('/start analysis w'); } /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_start_foo() { + $this->expectException(ParserException::class); self::$parser->validate('/start foo'); } /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_start_bar() { + $this->expectException(ParserException::class); self::$parser->validate('/start bar'); } } diff --git a/tests/unit/Command/StatusTest.php b/tests/unit/Command/StatusTest.php index 77d51ff4..b5aa2c46 100644 --- a/tests/unit/Command/StatusTest.php +++ b/tests/unit/Command/StatusTest.php @@ -3,6 +3,7 @@ namespace ChessServer\Tests\Unit\Command; use ChessServer\Command\StatusCommand; +use ChessServer\Exception\ParserException; use ChessServer\Tests\Unit\CommandTestCase; class StatusTest extends CommandTestCase @@ -20,10 +21,10 @@ public function validate_status() /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_status_foo() { + $this->expectException(ParserException::class); self::$parser->validate('/status foo'); } } diff --git a/tests/unit/Command/TakebackTest.php b/tests/unit/Command/TakebackTest.php index cc94c466..e74c1f3d 100644 --- a/tests/unit/Command/TakebackTest.php +++ b/tests/unit/Command/TakebackTest.php @@ -3,6 +3,7 @@ namespace ChessServer\Tests\Unit\Command; use ChessServer\Command\TakebackCommand; +use ChessServer\Exception\ParserException; use ChessServer\Tests\Unit\CommandTestCase; class TakebackTest extends CommandTestCase @@ -42,28 +43,28 @@ public function validate_takeback_proposes() /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_takeback_foo() { + $this->expectException(ParserException::class); self::$parser->validate('/takeback foo'); } /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_takeback_bar() { + $this->expectException(ParserException::class); self::$parser->validate('/takeback bar'); } /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_takeback_accept_foo() { + $this->expectException(ParserException::class); self::$parser->validate('/takeback accept foo'); } } diff --git a/tests/unit/Command/UndoMoveTest.php b/tests/unit/Command/UndoMoveTest.php index d84277cc..577caf6b 100644 --- a/tests/unit/Command/UndoMoveTest.php +++ b/tests/unit/Command/UndoMoveTest.php @@ -3,6 +3,7 @@ namespace ChessServer\Tests\Unit\Command; use ChessServer\Command\UndoMoveCommand; +use ChessServer\Exception\ParserException; use ChessServer\Tests\Unit\CommandTestCase; class UndoMoveTest extends CommandTestCase @@ -20,10 +21,10 @@ public function validate_undomove() /** * @test - * @expectedException ChessServer\Exception\ParserException */ public function validate_undomove_foo() { + $this->expectException(ParserException::class); self::$parser->validate('/undomove foo'); } } diff --git a/tests/unit/CommandTestCase.php b/tests/unit/CommandTestCase.php index 2bf81551..cf307766 100644 --- a/tests/unit/CommandTestCase.php +++ b/tests/unit/CommandTestCase.php @@ -9,7 +9,7 @@ class CommandTestCase extends TestCase { protected static $parser; - public function setUp() + public function setUp(): void { self::$parser = new CommandParser(); }