diff --git a/tests/DriversTestCase.php b/tests/DriversTestCase.php index ea691c18..188316d3 100644 --- a/tests/DriversTestCase.php +++ b/tests/DriversTestCase.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\Attributes\RequiresPhpExtension; #[RequiresPhpExtension('pdo_sqlite')] -class DriversTestCase extends CondorcetTestCase +abstract class DriversTestCase extends CondorcetTestCase { protected function hashVotesList(Election $elec): string { diff --git a/tests/src/Console/Commands/ConverterCommandTest.php b/tests/src/Console/Commands/ConverterCommandTest.php index f5bb62d9..41ca156e 100644 --- a/tests/src/Console/Commands/ConverterCommandTest.php +++ b/tests/src/Console/Commands/ConverterCommandTest.php @@ -8,21 +8,24 @@ use Symfony\Component\Console\Tester\CommandTester; use Tests\src\Console\ConsoleTestCase; -beforeEach(function () { +beforeEach(function (): void { CondorcetApplication::create(); $this->converterCommand = new CommandTester(CondorcetApplication::$SymfonyConsoleApplication->find('convert')); }); -afterEach(function () { + +afterEach(function (): void { file_exists(self::OUTPUT_FILE) && unlink(self::OUTPUT_FILE); }); + dataset('conversionsProvider', function () { return [ 'fromDebianToCondorcet' => ['--from-debian-format', '--to-condorcet-election-format', ConsoleTestCase::DEBIAN_INPUT_FILE, __DIR__ . '/files/fromDebianExpectedFile.cvotes'], 'fromDavidHillToCondorcet' => ['--from-david-hill-format', '--to-condorcet-election-format', ConsoleTestCase::DAVIDHILL_INPUT_FILE, __DIR__ . '/files/fromDavidHillExpectedFile.cvotes'], ]; }); -test('successfull conversions', function (string $from, string $to, string $input, string $comparaison) { + +test('successfull conversions', function (string $from, string $to, string $input, string $comparaison): void { $this->converterCommand->execute( [ $from => true, @@ -42,7 +45,8 @@ expect(file_get_contents(self::OUTPUT_FILE))->toBe(file_get_contents($comparaison)); })->with('conversionsProvider'); -test('lacks an option', function () { + +test('lacks an option', function (): void { $this->expectException(ConsoleInputException::class); $this->expectExceptionMessageMatches('/output/'); @@ -58,7 +62,8 @@ ] ); }); -test('lacks an argument', function () { + +test('lacks an argument', function (): void { $this->expectException(ConsoleInputException::class); $this->expectExceptionMessageMatches('/output/'); @@ -74,7 +79,8 @@ ] ); }); -test('wrong input', function () { + +test('wrong input', function (): void { $this->expectException(CondorcetInternalException::class); $this->expectExceptionMessage('The input file does not exist'); diff --git a/tests/src/Console/ConsoleTestCase.php b/tests/src/Console/ConsoleTestCase.php index bdeca4d7..0f59a99e 100644 --- a/tests/src/Console/ConsoleTestCase.php +++ b/tests/src/Console/ConsoleTestCase.php @@ -6,7 +6,7 @@ use Tests\CondorcetTestCase; -class ConsoleTestCase extends CondorcetTestCase +abstract class ConsoleTestCase extends CondorcetTestCase { public const DEBIAN_INPUT_FILE = __DIR__ . '/../Tools/Converters/DebianData/leader2020_tally.txt'; public const DAVIDHILL_INPUT_FILE = __DIR__ . '/../Tools/Converters/TidemanData/A77.HIL'; diff --git a/tests/src/ElectionTest.php b/tests/src/ElectionTest.php index e7bd9948..58eb2602 100644 --- a/tests/src/ElectionTest.php +++ b/tests/src/ElectionTest.php @@ -610,7 +610,7 @@ ); unserialize( - file_get_contents(__DIR__.'/ElectionData/serialized_election_v3.2.0.txt') + file_get_contents(__DIR__ . '/ElectionData/serialized_election_v3.2.0.txt') ); }); diff --git a/tests/src/Tools/Randomizers/ArrayRandomizerTest.php b/tests/src/Tools/Randomizers/ArrayRandomizerTest.php index 8f6949a1..a8fdd1b5 100644 --- a/tests/src/Tools/Randomizers/ArrayRandomizerTest.php +++ b/tests/src/Tools/Randomizers/ArrayRandomizerTest.php @@ -4,7 +4,7 @@ use CondorcetPHP\Condorcet\Tools\Randomizers\ArrayRandomizer; -test('default random votes', function () { +test('default random votes', function (): void { $votesRandomizer = new ArrayRandomizer(self::CANDIDATE_SET_1, self::SEED); for ($i = 0; $i < 10; $i++) { @@ -14,7 +14,8 @@ expect($nv)->toHaveCount(\count(self::CANDIDATE_SET_1)); } }); -test('max candidates ranked', function () { + +test('max candidates ranked', function (): void { $votesRandomizer = new ArrayRandomizer(self::CANDIDATE_SET_1, self::SEED); $votesRandomizer->maxCandidatesRanked = 3; @@ -27,7 +28,8 @@ expect($nv)->toHaveCount($votesRandomizer->maxCandidatesRanked); } }); -test('min candidates ranked', function () { + +test('min candidates ranked', function (): void { $votesRandomizer = new ArrayRandomizer(self::CANDIDATE_SET_1, self::SEED); $votesRandomizer->minCandidatesRanked = 3; @@ -47,7 +49,8 @@ $variationsCount = \count(array_unique($variations)); expect($variationsCount)->toBe(\count(self::CANDIDATE_SET_1) - $votesRandomizer->minCandidatesRanked + 1); }); -test('min and max candidates ranked', function () { + +test('min and max candidates ranked', function (): void { $votesRandomizer = new ArrayRandomizer(self::CANDIDATE_SET_1, self::SEED); $votesRandomizer->minCandidatesRanked = 3; $votesRandomizer->maxCandidatesRanked = 6; @@ -67,7 +70,8 @@ $variationsCount = \count(array_unique($variations)); expect($variationsCount)->toBe($votesRandomizer->maxCandidatesRanked - $votesRandomizer->minCandidatesRanked + 1); }); -test('added ties', function () { + +test('added ties', function (): void { $votesRandomizer = new ArrayRandomizer(self::CANDIDATE_SET_2, self::SEED); $votesRandomizer->tiesProbability = 100; @@ -91,7 +95,8 @@ expect($nv)->toHaveCount(1); expect($nv[0])->toHaveCount(3); }); -test('added ties with array1', function () { + +test('added ties with array1', function (): void { $votesRandomizer = new ArrayRandomizer(self::CANDIDATE_SET_3, self::SEED); $votesRandomizer->tiesProbability = 100; @@ -100,7 +105,8 @@ expect($nv)->toHaveCount(3); expect($nv[2])->toHaveCount(2); }); -test('added ties with array2', function () { + +test('added ties with array2', function (): void { $votesRandomizer = new ArrayRandomizer(self::CANDIDATE_SET_1, self::SEED); $votesRandomizer->tiesProbability = 500; @@ -109,7 +115,8 @@ expect($nv)->toHaveCount(4); expect($nv[2])->toHaveCount(6); }); -test('seeds', function () { + +test('seeds', function (): void { // Test low seed $votesRandomizer = new ArrayRandomizer(self::CANDIDATE_SET_1, '42'); expect($votesRandomizer->shuffle()[0])->toBe(self::CANDIDATE_SET_1[5]); @@ -121,7 +128,7 @@ expect($votesRandomizer->shuffle()[0])->toBe(self::CANDIDATE_SET_1[6]); // Test custom Randomizer - $r = new \Random\Randomizer(new \Random\Engine\PcgOneseq128XslRr64('abcdefghijklmnop')); + $r = new Random\Randomizer(new Random\Engine\PcgOneseq128XslRr64('abcdefghijklmnop')); $votesRandomizer = new ArrayRandomizer(self::CANDIDATE_SET_1, $r); expect($votesRandomizer->shuffle()[0])->toBe(self::CANDIDATE_SET_1[4]); diff --git a/tests/src/Tools/Randomizers/RandomizerTestCase.php b/tests/src/Tools/Randomizers/RandomizerTestCase.php index f51a3276..14b027f1 100644 --- a/tests/src/Tools/Randomizers/RandomizerTestCase.php +++ b/tests/src/Tools/Randomizers/RandomizerTestCase.php @@ -6,7 +6,7 @@ use Tests\CondorcetTestCase; -class RandomizerTestCase extends CondorcetTestCase +abstract class RandomizerTestCase extends CondorcetTestCase { public const SEED = 'CondorcetSeed';