Skip to content

Commit 0b1a65e

Browse files
committed
test: add unit tests for ProgramScraper
1 parent ec8e634 commit 0b1a65e

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed

tests/ProgramScraperTest.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BOA\Previews\Tests;
6+
7+
use BOA\Programs\ProgramScraper;
8+
use BOA\Programs\ScraperInterface;
9+
use Carbon\CarbonImmutable as Carbon;
10+
use PHPUnit\Framework\TestCase;
11+
12+
/**
13+
* @author shimomo
14+
*/
15+
final class ProgramScraperTest extends Testcase
16+
{
17+
/**
18+
* @param \Carbon\CarbonInterface|string $date
19+
* @return void
20+
*/
21+
public function testScrape(): void
22+
{
23+
$mockScraper = $this->createMock(ScraperInterface::class);
24+
$mockScraper->method('scrapePrograms')
25+
->with(Carbon::create(2025, 7, 15))
26+
->willReturn([
27+
$this->testScrapeData(1),
28+
]);
29+
$scraper = new ProgramScraper($mockScraper);
30+
$programs = $scraper->scrape(Carbon::create(2025, 7, 15));
31+
$this->assertSame($this->testScrapeData(0), $programs);
32+
}
33+
34+
/**
35+
* @psalm-type NormalizedBoat array{
36+
* racer_boat_number: int,
37+
* racer_name: string,
38+
* racer_number: int,
39+
* racer_class_number: int,
40+
* racer_branch_number: int,
41+
* racer_birthplace_number: int,
42+
* racer_age: int,
43+
* racer_weight: int|float,
44+
* racer_flying_count: int,
45+
* racer_late_count: int,
46+
* racer_average_start_timing: float,
47+
* racer_national_top_1_percent: float,
48+
* racer_national_top_2_percent: float,
49+
* racer_national_top_3_percent: float,
50+
* racer_local_top_1_percent: float,
51+
* racer_local_top_2_percent: float,
52+
* racer_local_top_3_percent: float,
53+
* racer_assigned_motor_number: int,
54+
* racer_assigned_motor_top_2_percent: float,
55+
* racer_assigned_motor_top_3_percent: float,
56+
* racer_assigned_boat_number: int,
57+
* racer_assigned_boat_top_2_percent: float,
58+
* racer_assigned_boat_top_3_percent: float
59+
* }
60+
*
61+
* @psalm-type NormalizedRace array{
62+
* race_date: string,
63+
* race_stadium_number: int,
64+
* race_number: int,
65+
* race_closed_at: string,
66+
* race_grade_number: int,
67+
* race_title: string,
68+
* race_subtitle: string,
69+
* race_distance: int,
70+
* boats: array<int, NormalizedBoat>
71+
* }
72+
*
73+
* @psalm-type NormalizedRaces array<int, NormalizedRace>
74+
*
75+
* @param int $keyIndex
76+
* @return NormalizedRaces
77+
*/
78+
private function testScrapeData(int $keyIndex): array
79+
{
80+
return [
81+
$keyIndex => [
82+
'race_date' => '2025-07-15',
83+
'race_stadium_number' => 1,
84+
'race_number' => 1,
85+
'race_closed_at' => '2025-07-15 15:17:00',
86+
'race_grade_number' => 5,
87+
'race_title' => 'にっぽん未来プロジェクト競走in桐生',
88+
'race_subtitle' => '予選',
89+
'race_distance' => 1800,
90+
'boats' => [
91+
$keyIndex => [
92+
'racer_boat_number' => 1,
93+
'racer_name' => '松本 浩貴',
94+
'racer_number' => 3860,
95+
'racer_class_number' => 3,
96+
'racer_branch_number' => 11,
97+
'racer_birthplace_number' => 11,
98+
'racer_age' => 52,
99+
'racer_weight' => 52,
100+
'racer_flying_count' => 0,
101+
'racer_late_count' => 0,
102+
'racer_average_start_timing' => 0.19,
103+
'racer_national_top_1_percent' => 4.09,
104+
'racer_national_top_2_percent' => 18.48,
105+
'racer_national_top_3_percent' => 39.13,
106+
'racer_local_top_1_percent' => 4.85,
107+
'racer_local_top_2_percent' => 33.33,
108+
'racer_local_top_3_percent' => 40.74,
109+
'racer_assigned_motor_number' => 24,
110+
'racer_assigned_motor_top_2_percent' => 28,
111+
'racer_assigned_motor_top_3_percent' => 42.67,
112+
'racer_assigned_boat_number' => 23,
113+
'racer_assigned_boat_top_2_percent' => 30.47,
114+
'racer_assigned_boat_top_3_percent' => 51.56,
115+
],
116+
],
117+
],
118+
];
119+
}
120+
}

0 commit comments

Comments
 (0)