diff --git a/app/helpers.php b/app/helpers.php index b315364..da7cd5d 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -2,37 +2,41 @@ declare(strict_types=1); -function ensureNumeric(int|float|string $value): int|float -{ - if (is_int($value) || is_float($value)) { - return $value; +if (! function_exists('ensureNumeric')) { + function ensureNumeric(int|float|string $value): int|float + { + if (is_int($value) || is_float($value)) { + return $value; + } + + if (! is_numeric($value)) { + throw new InvalidArgumentException('Value must be a numeric type.'); + } + + if (filter_var($value, \FILTER_VALIDATE_FLOAT) !== false) { + return floatval($value); + } + + return intval($value); } - - if (! is_numeric($value)) { - throw new InvalidArgumentException('Value must be a numeric type.'); - } - - if (filter_var($value, \FILTER_VALIDATE_FLOAT) !== false) { - return floatval($value); - } - - return intval($value); } -function percent(int|float|string $value, int|float|string $max, int $precision = 2, bool $formatted = false): float|string|null -{ - $value = ensureNumeric($value); - $max = ensureNumeric($max); +if (! function_exists('percent')) { + function percent(int|float|string $value, int|float|string $max, int $precision = 2, bool $formatted = false): float|string|null + { + $value = ensureNumeric($value); + $max = ensureNumeric($max); - if ($max == 0) { - return null; - } + if ($max == 0) { + return null; + } - $percent = (float) number_format(min(100, max(0, $value / $max * 100)), $precision); + $percent = (float) number_format(min(100, max(0, $value / $max * 100)), $precision); - if ($formatted) { - $percent = sprintf('%s%%', $percent); - } + if ($formatted) { + $percent = sprintf('%s%%', $percent); + } - return $percent; + return $percent; + } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index f606cb6..651912e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -30,8 +30,6 @@ - - diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index d26e6c9..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,21 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } -} diff --git a/tests/Feature/Livewire/Pages/ElectionTurnoutsTest.php b/tests/Feature/Livewire/Pages/ElectionTurnoutsTest.php index 41677da..f682062 100644 --- a/tests/Feature/Livewire/Pages/ElectionTurnoutsTest.php +++ b/tests/Feature/Livewire/Pages/ElectionTurnoutsTest.php @@ -16,9 +16,12 @@ class ElectionTurnoutsTest extends TestCase public function renders_successfully() { $election = Election::factory() + ->withLocalTurnout() ->create(); - Livewire::test(ElectionTurnouts::class) + Livewire::test(ElectionTurnouts::class, [ + 'election' => $election, + ]) ->assertOk(); } }