Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/SparkLineEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public function __construct(

public function rebase(int $base, int $max): self
{
if($max === 0) {
return $this;
}

return new self(
count: (int) floor($this->count * ($base / $max)),
);
Expand Down
9 changes: 9 additions & 0 deletions tests/SparkLineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Brendt\SparkLine\SparkLine;
use Brendt\SparkLine\SparkLineEntry;
use DivisionByZeroError;
use PHPUnit\Framework\TestCase;

final class SparkLineTest extends TestCase
Expand Down Expand Up @@ -70,4 +71,12 @@ public function test_get_total(): void

$this->assertEquals(3, $sparkLine->getTotal());
}

/** @test */
public function test_entries_all_with_zero_values_doesnt_cause_error(): void
{
$sparkLine = (new SparkLine(0, 0, 0, 0))->make();

$this->assertStringContainsString('<svg', $sparkLine);
}
}