fedi-feed-router/tests/Unit/Dashboard/Stats/SeriesResultTest.php

104 lines
2.8 KiB
PHP
Raw Normal View History

<?php
namespace Tests\Unit\Dashboard\Stats;
use App\Dashboard\Stats\Series;
use App\Dashboard\Stats\SeriesResult;
use InvalidArgumentException;
use Tests\TestCase;
class SeriesResultTest extends TestCase
{
public function test_a_series_result_aligns_every_series_to_the_shared_label_axis(): void
{
$this->expectException(InvalidArgumentException::class);
new SeriesResult(
['2026-07-01', '2026-07-02', '2026-07-03'],
[new Series('Approved', [1, 2])],
);
}
public function test_a_series_result_accepts_multiple_series_that_all_align(): void
{
$result = new SeriesResult(
['2026-07-01', '2026-07-02'],
[
new Series('Approved', [1, 2]),
new Series('Rejected', [0, 1]),
],
);
$this->assertSame(['2026-07-01', '2026-07-02'], $result->labels);
$this->assertCount(2, $result->series);
}
public function test_a_too_wide_result_reports_itself_as_too_wide(): void
{
$result = SeriesResult::tooWide();
$this->assertTrue($result->isTooWide());
}
public function test_a_too_wide_result_is_not_reported_as_merely_empty(): void
{
$result = SeriesResult::tooWide();
$this->assertFalse($result->isEmpty());
}
public function test_an_empty_but_valid_result_is_not_reported_as_too_wide(): void
{
$result = new SeriesResult([], []);
$this->assertFalse($result->isTooWide());
}
public function test_an_empty_but_valid_result_reports_itself_as_empty(): void
{
$result = new SeriesResult([], []);
$this->assertTrue($result->isEmpty());
}
public function test_a_result_whose_series_are_all_zero_has_no_data(): void
{
$result = new SeriesResult(
['2026-07-01', '2026-07-02'],
[new Series('Fetched', [0, 0]), new Series('Published', [0, 0])],
);
$this->assertTrue($result->hasNoData());
}
public function test_a_result_with_any_non_zero_value_has_data(): void
{
$result = new SeriesResult(
['2026-07-01', '2026-07-02'],
[new Series('Fetched', [0, 0]), new Series('Published', [0, 1])],
);
$this->assertFalse($result->hasNoData());
}
public function test_a_result_of_only_nulls_has_no_data(): void
{
$result = new SeriesResult(
['2026-07-01', '2026-07-02'],
[new Series('Approval Rate', [null, null])],
);
$this->assertTrue($result->hasNoData());
}
public function test_zero_values_are_indistinguishable_from_absent_ones(): void
{
$result = new SeriesResult(
['2026-07-01', '2026-07-02'],
[new Series('Approval Rate', [null, 0.0])],
);
$this->assertTrue($result->hasNoData());
}
}