From 23fc14af0a729087d998ac75fe2bf22f3f0fcd1a Mon Sep 17 00:00:00 2001 From: Jens True Date: Thu, 1 Feb 2024 10:50:18 +0000 Subject: [PATCH] Cleanup abstractions of "TestCase" class in unittest --- .woodpecker.yml | 8 +++---- tests/FactorGraphs/ScheduleStepTest.php | 17 ++++++++++++++ tests/FactorGraphs/VariableTest.php | 22 +++++++++++++++++++ tests/GuardTest.php | 12 +++++++++- tests/Numerics/BasicMathTest.php | 2 +- tests/Numerics/GaussianDistributionTest.php | 2 +- tests/Numerics/MatrixTest.php | 2 +- tests/Numerics/RangeTest.php | 2 +- tests/RankSorterTest.php | 1 + tests/RatingTest.php | 1 + tests/TestCase.php | 10 --------- tests/TrueSkill/DrawMarginTest.php | 2 +- ...FactorGraphTeamTrueSkillCalculatorTest.php | 9 +++++++- .../FactorGraphTrueSkillCalculatorTest.php | 2 +- tests/TrueSkill/TrueSkillCalculatorTests.php | 2 +- .../TwoPlayerTrueSkillCalculatorTest.php | 2 +- .../TwoTeamTrueSkillCalculatorTest.php | 2 +- 17 files changed, 73 insertions(+), 25 deletions(-) create mode 100644 tests/FactorGraphs/ScheduleStepTest.php create mode 100644 tests/FactorGraphs/VariableTest.php delete mode 100644 tests/TestCase.php diff --git a/.woodpecker.yml b/.woodpecker.yml index 8847043..66325f0 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -17,7 +17,7 @@ pipeline: image: php:cli-bookworm commands: - vendor/bin/phpunit tests - document: - image: phpdoc/phpdoc - commands: - - phpdoc run \ No newline at end of file +# document: +# image: phpdoc/phpdoc +# commands: +# - phpdoc \ No newline at end of file diff --git a/tests/FactorGraphs/ScheduleStepTest.php b/tests/FactorGraphs/ScheduleStepTest.php new file mode 100644 index 0000000..b99b5f0 --- /dev/null +++ b/tests/FactorGraphs/ScheduleStepTest.php @@ -0,0 +1,17 @@ +createStub(Factor::class); + $ss = new ScheduleStep('dummy', $stub, 0); + $this->assertEquals('dummy', (string)$ss); + } +} diff --git a/tests/FactorGraphs/VariableTest.php b/tests/FactorGraphs/VariableTest.php new file mode 100644 index 0000000..3a2de37 --- /dev/null +++ b/tests/FactorGraphs/VariableTest.php @@ -0,0 +1,22 @@ +assertEquals($gd_prior, $var->getValue()); + $gd_new = new GaussianDistribution(); + $this->assertEquals($gd_new, $var->getValue()); + $var->resetToPrior(); + $this->assertEquals($gd_prior, $var->getValue()); + $this->assertEquals('Variable[dummy]', (string)$var); + } +} diff --git a/tests/GuardTest.php b/tests/GuardTest.php index 7c3fbcf..44213ef 100644 --- a/tests/GuardTest.php +++ b/tests/GuardTest.php @@ -4,25 +4,35 @@ namespace DNW\Skills\Tests; use DNW\Skills\Guard; use Exception; +use PHPUnit\Framework\TestCase; class GuardTest extends TestCase { public function testArgumentNotNull(): void { $this->expectException(Exception::class); + $this->expectExceptionMessage('dummy can not be null'); Guard::argumentNotNull(null, "dummy"); } public function testargumentIsValidIndex(): void { $this->expectException(Exception::class); - Guard::argumentIsValidIndex(25, 10, "dummy"); + $this->expectExceptionMessage('dummy is an invalid index'); + Guard::argumentIsValidIndex(10, 10, "dummy"); } + public function testargumentIsValidIndex2(): void + { + $this->expectException(Exception::class); + $this->expectExceptionMessage('dummy is an invalid index'); + Guard::argumentIsValidIndex(-1, 10, "dummy"); + } public function testargumentInRangeInclusive(): void { $this->expectException(Exception::class); + $this->expectExceptionMessage('dummy is not in the valid range [0, 100]'); Guard::argumentInRangeInclusive(101, 0, 100, "dummy"); } } diff --git a/tests/Numerics/BasicMathTest.php b/tests/Numerics/BasicMathTest.php index 606a130..6574a73 100644 --- a/tests/Numerics/BasicMathTest.php +++ b/tests/Numerics/BasicMathTest.php @@ -3,7 +3,7 @@ namespace DNW\Skills\Tests\Numerics; use DNW\Skills\Numerics\BasicMath; -use DNW\Skills\Tests\TestCase; +use PHPUnit\Framework\TestCase; class BasicMathTest extends TestCase { diff --git a/tests/Numerics/GaussianDistributionTest.php b/tests/Numerics/GaussianDistributionTest.php index 65ec0c1..4d3829f 100644 --- a/tests/Numerics/GaussianDistributionTest.php +++ b/tests/Numerics/GaussianDistributionTest.php @@ -4,7 +4,7 @@ namespace DNW\Skills\Tests\Numerics; use DNW\Skills\Numerics\BasicMath; use DNW\Skills\Numerics\GaussianDistribution; -use DNW\Skills\Tests\TestCase; +use PHPUnit\Framework\TestCase; class GaussianDistributionTest extends TestCase { diff --git a/tests/Numerics/MatrixTest.php b/tests/Numerics/MatrixTest.php index 030715a..ce1b651 100644 --- a/tests/Numerics/MatrixTest.php +++ b/tests/Numerics/MatrixTest.php @@ -5,7 +5,7 @@ namespace DNW\Skills\Tests\Numerics; use DNW\Skills\Numerics\IdentityMatrix; use DNW\Skills\Numerics\Matrix; use DNW\Skills\Numerics\SquareMatrix; -use DNW\Skills\Tests\TestCase; +use PHPUnit\Framework\TestCase; use Exception; // phpcs:disable PSR2.Methods.FunctionCallSignature,Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma diff --git a/tests/Numerics/RangeTest.php b/tests/Numerics/RangeTest.php index ef40f66..7b44bb8 100644 --- a/tests/Numerics/RangeTest.php +++ b/tests/Numerics/RangeTest.php @@ -3,7 +3,7 @@ namespace DNW\Skills\Tests\Numerics; use DNW\Skills\Numerics\Range; -use DNW\Skills\Tests\TestCase; +use PHPUnit\Framework\TestCase; use Exception; class RangeTest extends TestCase diff --git a/tests/RankSorterTest.php b/tests/RankSorterTest.php index 07776f1..2974d01 100644 --- a/tests/RankSorterTest.php +++ b/tests/RankSorterTest.php @@ -3,6 +3,7 @@ namespace DNW\Skills\Tests; use DNW\Skills\RankSorter; +use PHPUnit\Framework\TestCase; class RankSorterTest extends TestCase { diff --git a/tests/RatingTest.php b/tests/RatingTest.php index df14472..7680939 100644 --- a/tests/RatingTest.php +++ b/tests/RatingTest.php @@ -3,6 +3,7 @@ namespace DNW\Skills\Tests; use DNW\Skills\Rating; +use PHPUnit\Framework\TestCase; class RatingTest extends TestCase { diff --git a/tests/TestCase.php b/tests/TestCase.php deleted file mode 100644 index 0df8d07..0000000 --- a/tests/TestCase.php +++ /dev/null @@ -1,10 +0,0 @@ -assertEquals(true, $calculator->isSupported(SkillCalculatorSupportedOptions::PARTIAL_PLAY)); + } } diff --git a/tests/TrueSkill/FactorGraphTrueSkillCalculatorTest.php b/tests/TrueSkill/FactorGraphTrueSkillCalculatorTest.php index 093dbcb..70c9d9d 100644 --- a/tests/TrueSkill/FactorGraphTrueSkillCalculatorTest.php +++ b/tests/TrueSkill/FactorGraphTrueSkillCalculatorTest.php @@ -2,11 +2,11 @@ namespace DNW\Skills\Tests\TrueSkill; -use DNW\Skills\Tests\TestCase; use DNW\Skills\GameInfo; use DNW\Skills\Player; use DNW\Skills\Team; use DNW\Skills\TrueSkill\FactorGraphTrueSkillCalculator; +use PHPUnit\Framework\TestCase; class FactorGraphTrueSkillCalculatorTest extends TestCase { diff --git a/tests/TrueSkill/TrueSkillCalculatorTests.php b/tests/TrueSkill/TrueSkillCalculatorTests.php index 9d39573..d606b9c 100644 --- a/tests/TrueSkill/TrueSkillCalculatorTests.php +++ b/tests/TrueSkill/TrueSkillCalculatorTests.php @@ -8,7 +8,7 @@ use DNW\Skills\Rating; use DNW\Skills\SkillCalculator; use DNW\Skills\Team; use DNW\Skills\Teams; -use DNW\Skills\Tests\TestCase; +use PHPUnit\Framework\TestCase; class TrueSkillCalculatorTests { diff --git a/tests/TrueSkill/TwoPlayerTrueSkillCalculatorTest.php b/tests/TrueSkill/TwoPlayerTrueSkillCalculatorTest.php index 4e1a962..e99243f 100644 --- a/tests/TrueSkill/TwoPlayerTrueSkillCalculatorTest.php +++ b/tests/TrueSkill/TwoPlayerTrueSkillCalculatorTest.php @@ -2,8 +2,8 @@ namespace DNW\Skills\Tests\TrueSkill; -use DNW\Skills\Tests\TestCase; use DNW\Skills\TrueSkill\TwoPlayerTrueSkillCalculator; +use PHPUnit\Framework\TestCase; class TwoPlayerTrueSkillCalculatorTest extends TestCase { diff --git a/tests/TrueSkill/TwoTeamTrueSkillCalculatorTest.php b/tests/TrueSkill/TwoTeamTrueSkillCalculatorTest.php index b731cd4..533c238 100644 --- a/tests/TrueSkill/TwoTeamTrueSkillCalculatorTest.php +++ b/tests/TrueSkill/TwoTeamTrueSkillCalculatorTest.php @@ -2,8 +2,8 @@ namespace DNW\Skills\Tests\TrueSkill; -use DNW\Skills\Tests\TestCase; use DNW\Skills\TrueSkill\TwoTeamTrueSkillCalculator; +use PHPUnit\Framework\TestCase; class TwoTeamTrueSkillCalculatorTest extends TestCase {