Skip to content

Commit 0760c5f

Browse files
authored
Merge pull request #64 from BoatraceOpenAPI/refactor/test-scrape
test: improve scrape tests
2 parents 640419d + 2979ebf commit 0760c5f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

tests/ProgramScraperTest.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
use PHPUnit\Framework\TestCase;
1111

1212
/**
13-
* @psalm-import-type ScrapedStadiumRaces from ScraperInterface
13+
* @psalm-import-type ScrapedRaces from ScraperInterface
1414
*
1515
* @author shimomo
1616
*/
17-
final class ProgramScraperTest extends Testcase
17+
final class ProgramScraperTest extends TestCase
1818
{
1919
/**
2020
* @psalm-return void
@@ -25,23 +25,29 @@ public function testScrape(): void
2525
{
2626
$mockScraper = $this->createMock(ScraperInterface::class);
2727
$mockScraper->method('scrapePrograms')
28-
->with(Carbon::create(2025, 7, 15))
28+
->with(Carbon::create(2025, 7, 15, 0, 0, 0, 'Asia/Tokyo'))
2929
->willReturn([
30-
$this->testScrapeData(1),
30+
1 => $this->testScrapeData(1, 5),
31+
2 => $this->testScrapeData(2, 6),
3132
]);
3233
$scraper = new ProgramScraper($mockScraper);
33-
$programs = $scraper->scrape(Carbon::create(2025, 7, 15));
34-
$this->assertSame($this->testScrapeData(0), $programs);
34+
$programs = $scraper->scrape(Carbon::create(2025, 7, 15, 0, 0, 0, 'Asia/Tokyo'));
35+
$this->assertSame(array_merge(
36+
$this->testScrapeData(0, 0),
37+
$this->testScrapeData(1, 0)
38+
), $programs);
3539
}
3640

3741
/**
3842
* @psalm-param int $keyIndex
39-
* @psalm-return ScrapedStadiumRaces
43+
* @psalm-param int $boatKeyIndex
44+
* @psalm-return ScrapedRaces
4045
*
4146
* @param int $keyIndex
47+
* @param int $boatKeyIndex
4248
* @return array
4349
*/
44-
private function testScrapeData(int $keyIndex): array
50+
private function testScrapeData(int $keyIndex, int $boatKeyIndex): array
4551
{
4652
return [
4753
$keyIndex => [
@@ -54,7 +60,7 @@ private function testScrapeData(int $keyIndex): array
5460
'race_subtitle' => '予選',
5561
'race_distance' => 1800,
5662
'boats' => [
57-
$keyIndex => [
63+
$boatKeyIndex => [
5864
'racer_boat_number' => 1,
5965
'racer_name' => '松本 浩貴',
6066
'racer_number' => 3860,

0 commit comments

Comments
 (0)