Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Nov 8, 2024
1 parent 8024371 commit fa46cac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 50 deletions.
56 changes: 30 additions & 26 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
2 changes: 0 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
<env name="APP_MAINTENANCE_DRIVER" value="file"/>
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_STORE" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
<env name="MAIL_MAILER" value="array"/>
<env name="PULSE_ENABLED" value="false"/>
<env name="QUEUE_CONNECTION" value="sync"/>
Expand Down
21 changes: 0 additions & 21 deletions tests/Feature/ExampleTest.php

This file was deleted.

5 changes: 4 additions & 1 deletion tests/Feature/Livewire/Pages/ElectionTurnoutsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

0 comments on commit fa46cac

Please sign in to comment.