Files
weerscherm/tests/PressureHistoryTest.php
T

33 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Weerscherm\Tests;
use PHPUnit\Framework\TestCase;
use Weerscherm\PressureHistory;
final class PressureHistoryTest extends TestCase
{
public function testMapsAndSortsPoints(): void
{
$body = json_decode((string) file_get_contents(__DIR__ . '/fixtures/getmeasure-pressure.json'), true)['body'];
$shuffled = array_reverse($body, true);
$points = PressureHistory::map($shuffled, new \DateTimeZone('Europe/Berlin'));
self::assertCount(49, $points);
self::assertSame('2026-09-10T14:30:00+02:00', $points[0]['at']);
self::assertSame('2026-09-11T14:30:00+02:00', $points[48]['at']);
self::assertIsFloat($points[0]['hpa']);
self::assertSame(['at', 'hpa'], array_keys($points[0]));
}
public function testSkipsGarbage(): void
{
$points = PressureHistory::map(['abc' => [1000.0], '1789129800' => ['x'], '1789133400' => [1013.5]], new \DateTimeZone('UTC'));
self::assertSame([['at' => '2026-09-11T13:30:00+00:00', 'hpa' => 1013.5]], $points);
}
}