Skip to content

Commit

Permalink
Upgrade to the latest version of PHPUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
laxity7 committed Sep 27, 2023
1 parent 09a77d8 commit e8b2df6
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 31 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 160
tab_width = 4
26 changes: 26 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Autodetect text files
* text=auto eol=lf

# Definitively text files
*.php text
*.md text
*.xml text
*.json text
*.yml text

# Ignore some meta files when creating an archive of this repository
/.travis.yml export-ignore
/.github export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.phpunit-watcher.yml export-ignore
/.styleci.yml export-ignore
/phpunit.xml.dist export-ignore
/phpunit.xml export-ignore
/psalm.xml export-ignore
/tests export-ignore

# Avoid merge conflicts in CHANGELOG
# https://about.gitlab.com/2015/02/10/gitlab-reduced-merge-conflicts-by-90-percent-with-changelog-placeholders/
/CHANGELOG.md merge=union
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor/
.phpunit.result.cache
composer.lock
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"php": "^7.4|^8.0"
},
"require-dev": {
"phpunit/phpunit": "~5.3.0"
"php": ">=8.1",
"phpunit/phpunit": "^10.0"
},
"autoload": {
"psr-4": {
Expand Down
62 changes: 32 additions & 30 deletions tests/Glicko2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,54 @@

namespace laxity7\glicko2\Test;

use PHPUnit_Framework_TestCase;
use laxity7\glicko2\MatchGame;
use laxity7\glicko2\MatchCollection;
use laxity7\glicko2\MatchGame;
use laxity7\glicko2\Player;
use PHPUnit\Framework\TestCase;

final class Glicko2Test extends PHPUnit_Framework_TestCase
final class Glicko2Test extends TestCase
{

public function testDefaultPlayer()
public function testDefaultPlayer(): void
{
$player = new Player();

$this->assertEquals(Player::DEFAULT_RATING, $player->getRating());
$this->assertEquals(Player::DEFAULT_RATING_DEVIATION, $player->getRatingDeviation());
$this->assertEquals(Player::DEFAULT_RATING_VOLATILITY, $player->getRatingVolatility());
self::assertEquals(Player::DEFAULT_RATING, $player->getRating());
self::assertEquals(Player::DEFAULT_RATING_DEVIATION, $player->getRatingDeviation());
self::assertEquals(Player::DEFAULT_RATING_VOLATILITY, $player->getRatingVolatility());
}

public function testCustomPlayer()
public function testCustomPlayer(): void
{
$r = 1700;
$rd = 300;
$sigma = 0.04;

$player = new Player($r, $rd, $sigma);

$this->assertEquals($r, $player->getRating());
$this->assertEquals($rd, $player->getRatingDeviation());
$this->assertEquals($sigma, $player->getRatingVolatility());
self::assertEquals($r, $player->getRating());
self::assertEquals($rd, $player->getRatingDeviation());
self::assertEquals($sigma, $player->getRatingVolatility());
}

public function testCalculateMatch()
public function testCalculateMatch(): void
{
$player1 = new Player(1500, 200, 0.06);
$player2 = new Player(1400, 30, 0.06);

$match = new MatchGame($player1, $player2, 1, 0);
$match->calculate();

$this->assertEquals(1563.564, $this->round($player1->getRating()));
$this->assertEquals(175.403, $this->round($player1->getRatingDeviation()));
$this->assertEquals(0.06, $this->round($player1->getRatingVolatility()));
self::assertEquals(1563.564, $this->round($player1->getRating()));
self::assertEquals(175.403, $this->round($player1->getRatingDeviation()));
self::assertEquals(0.06, $this->round($player1->getRatingVolatility()));

$this->assertEquals(1398.144, $this->round($player2->getRating()));
$this->assertEquals(31.67, $this->round($player2->getRatingDeviation()));
$this->assertEquals(0.06, $this->round($player2->getRatingVolatility()));
self::assertEquals(1398.144, $this->round($player2->getRating()));
self::assertEquals(31.67, $this->round($player2->getRatingDeviation()));
self::assertEquals(0.06, $this->round($player2->getRatingVolatility()));
}

public function testCalculateMatchCollection()
public function testCalculateMatchCollection(): void
{
$player1 = new Player(1500, 200, 0.06);
$player2 = new Player(1400, 30, 0.06);
Expand All @@ -67,22 +67,24 @@ public function testCalculateMatchCollection()
$matchCollection->addMatch(new MatchGame($player3, $player4, 1, 0));
$matchCollection->calculate();

$this->assertEquals($this->round($player1->getRating()), $this->round($player3->getRating()));
$this->assertEquals($this->round($player2->getRating()), $this->round($player4->getRating()));
$this->assertEquals($this->round($player1->getRatingDeviation()), $this->round($player3->getRatingDeviation()));
$this->assertEquals($this->round($player2->getRatingDeviation()), $this->round($player4->getRatingDeviation()));
$this->assertEquals($this->round($player1->getRatingVolatility()), $this->round($player3->getRatingVolatility()));
$this->assertEquals($this->round($player2->getRatingVolatility()), $this->round($player4->getRatingVolatility()));
self::assertEquals($this->round($player1->getRating()), $this->round($player3->getRating()));
self::assertEquals($this->round($player2->getRating()), $this->round($player4->getRating()));
self::assertEquals($this->round($player1->getRatingDeviation()), $this->round($player3->getRatingDeviation()));
self::assertEquals($this->round($player2->getRatingDeviation()), $this->round($player4->getRatingDeviation()));
self::assertEquals(
$this->round($player1->getRatingVolatility()),
$this->round($player3->getRatingVolatility())
);
self::assertEquals(
$this->round($player2->getRatingVolatility()),
$this->round($player4->getRatingVolatility())
);
}

/**
* For different platforms compatibility
*
* @param float $value
*
* @return float
*/
private function round($value)
private function round(float $value): float
{
return round($value, 3);
}
Expand Down

0 comments on commit e8b2df6

Please sign in to comment.