new: pkg: add test cases to back-end w/ real database connection in it #10
This commit is contained in:
142
tests/Entity/UserStatsTest.php
Normal file
142
tests/Entity/UserStatsTest.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2026 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Entity;
|
||||
|
||||
use App\Entity\UserStats;
|
||||
use PHPUnit\Framework\Attributes\Test;
|
||||
use PHPUnit\Framework\Attributes\TestDox;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Class UserStatsTest
|
||||
*
|
||||
* @package App\Tests\Entity
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 21.
|
||||
*/
|
||||
#[TestDox('User Stats')]
|
||||
class UserStatsTest extends TestCase
|
||||
{
|
||||
#[Test]
|
||||
#[TestDox('Get win rate calculates correctly')]
|
||||
public function getWinRateCalculatesCorrectly(): void
|
||||
{
|
||||
$stats = new UserStats();
|
||||
$stats->wins = 60;
|
||||
$stats->gamesWithScores = 100;
|
||||
|
||||
$result = $stats->getWinRate();
|
||||
|
||||
$this->assertSame(60, $result);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[TestDox('Get win rate with zero games returns zero')]
|
||||
public function getWinRateWithZeroGamesReturnsZero(): void
|
||||
{
|
||||
$stats = new UserStats();
|
||||
$stats->wins = 10;
|
||||
$stats->gamesWithScores = 0;
|
||||
|
||||
$result = $stats->getWinRate();
|
||||
|
||||
$this->assertSame(0, $result);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[TestDox('Get win rate rounds correctly')]
|
||||
public function getWinRateRoundsCorrectly(): void
|
||||
{
|
||||
$stats = new UserStats();
|
||||
$stats->wins = 33;
|
||||
$stats->gamesWithScores = 100;
|
||||
|
||||
$result = $stats->getWinRate();
|
||||
|
||||
$this->assertSame(33, $result);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[TestDox('Get avg score calculates correctly')]
|
||||
public function getAvgScoreCalculatesCorrectly(): void
|
||||
{
|
||||
$stats = new UserStats();
|
||||
$stats->totalMines = 550;
|
||||
$stats->gamesWithScores = 100;
|
||||
|
||||
$result = $stats->getAvgScore();
|
||||
|
||||
$this->assertSame(6, $result); // 550/100 = 5.5 -> 6
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[TestDox('Get avg score with zero games returns zero')]
|
||||
public function getAvgScoreWithZeroGamesReturnsZero(): void
|
||||
{
|
||||
$stats = new UserStats();
|
||||
$stats->totalMines = 100;
|
||||
$stats->gamesWithScores = 0;
|
||||
|
||||
$result = $stats->getAvgScore();
|
||||
|
||||
$this->assertSame(0, $result);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[TestDox('Get avg score rounds down')]
|
||||
public function getAvgScoreRoundsDown(): void
|
||||
{
|
||||
$stats = new UserStats();
|
||||
$stats->totalMines = 101;
|
||||
$stats->gamesWithScores = 100;
|
||||
|
||||
$result = $stats->getAvgScore();
|
||||
|
||||
$this->assertSame(1, $result); // 101/100 = 1.01 -> 1
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[TestDox('Get avg score rounds up')]
|
||||
public function getAvgScoreRoundsUp(): void
|
||||
{
|
||||
$stats = new UserStats();
|
||||
$stats->totalMines = 151;
|
||||
$stats->gamesWithScores = 100;
|
||||
|
||||
$result = $stats->getAvgScore();
|
||||
|
||||
$this->assertSame(2, $result); // 151/100 = 1.51 -> 2
|
||||
}
|
||||
|
||||
#[Test]
|
||||
#[TestDox('Default values')]
|
||||
public function defaultValues(): void
|
||||
{
|
||||
$stats = new UserStats();
|
||||
|
||||
$this->assertSame(0, $stats->userId);
|
||||
$this->assertSame(0, $stats->totalGames);
|
||||
$this->assertSame(0, $stats->wins);
|
||||
$this->assertSame(0, $stats->losses);
|
||||
$this->assertSame(0, $stats->draws);
|
||||
$this->assertSame(0, $stats->totalMines);
|
||||
$this->assertSame('0.0', $stats->totalBonusPoints);
|
||||
$this->assertSame('0.0', $stats->avgBonus);
|
||||
$this->assertSame(0, $stats->bestChain);
|
||||
$this->assertSame(0, $stats->blindHits);
|
||||
$this->assertSame(0, $stats->edgeMines);
|
||||
$this->assertSame(0, $stats->gamesWithScores);
|
||||
$this->assertNull($stats->lastGameAt);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user