Skip to content

Commit

Permalink
Bump PHPUnit to 9.5
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Pen-y-Fan committed Oct 3, 2021
1 parent 7bb98d2 commit f77408f
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
/ssl/*.key

/storage/*.log
/.phpunit.result.cache
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Create an `.env` file:

$ cp .env.example .env

Run all the tests

$ composer test

### WebSocket Server

Start the server:
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
],
"require": {
"php": ">=7.1",
"php": ">=7.4",
"chesslablab/php-chess": "dev-master",
"rubix/ml": "^1.1",
"cboden/ratchet": "^0.4",
Expand All @@ -24,7 +24,7 @@
"monolog/monolog": "^2.3"
},
"require-dev": {
"phpunit/phpunit": "~5.7"
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
Expand All @@ -35,5 +35,8 @@
"psr-4": {
"ChessServer\\Tests\\Unit\\": "tests/unit/"
}
},
"scripts": {
"tests": "phpunit"
}
}
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
</include>
</coverage>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
<directory>tests</directory>
</testsuite>
</phpunit>
3 changes: 2 additions & 1 deletion tests/unit/Command/AsciiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
}
3 changes: 2 additions & 1 deletion tests/unit/Command/CapturesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
}
3 changes: 2 additions & 1 deletion tests/unit/Command/HistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
}
3 changes: 2 additions & 1 deletion tests/unit/Command/IsCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
}
3 changes: 2 additions & 1 deletion tests/unit/Command/IsMateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
}
3 changes: 2 additions & 1 deletion tests/unit/Command/PieceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
}
5 changes: 3 additions & 2 deletions tests/unit/Command/PiecesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
}
3 changes: 2 additions & 1 deletion tests/unit/Command/QuitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
}
7 changes: 4 additions & 3 deletions tests/unit/Command/StartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
}
3 changes: 2 additions & 1 deletion tests/unit/Command/StatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
}
7 changes: 4 additions & 3 deletions tests/unit/Command/TakebackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
}
3 changes: 2 additions & 1 deletion tests/unit/Command/UndoMoveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
}
}
2 changes: 1 addition & 1 deletion tests/unit/CommandTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CommandTestCase extends TestCase
{
protected static $parser;

public function setUp()
public function setUp(): void
{
self::$parser = new CommandParser();
}
Expand Down

0 comments on commit f77408f

Please sign in to comment.