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
8 changes: 4 additions & 4 deletions scraper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require __DIR__ . '/vendor/autoload.php';

use BOA\Programs\ProgramScraper;
use BOA\Programs\ProgramStorage;
use BOA\Programs\ProgramSaver;
use BOA\Programs\ScraperAdapter;
use BVP\Scraper\Scraper;
use Carbon\CarbonImmutable as Carbon;
Expand Down Expand Up @@ -34,6 +34,6 @@
// 出走表データを JSON ファイルとして保存
// 日付付きの JSON ファイルとして保存(例: docs/{version}/YYYY/YYYYMMDD.json)
// 最新データとして today.json にも保存
$storage = new ProgramStorage();
$storage->save($programs, "docs/{$version}/" . $date->format('Y') . '/' . $date->format('Ymd') . '.json');
$storage->save($programs, "docs/{$version}/today.json");
$saver = new ProgramSaver();
$saver->save($programs, "docs/{$version}/" . $date->format('Y') . '/' . $date->format('Ymd') . '.json');
$saver->save($programs, "docs/{$version}/today.json");
4 changes: 2 additions & 2 deletions src/ProgramStorage.php → src/ProgramSaver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @author shimomo
*/
final class ProgramStorage
final class ProgramSaver
{
/**
* @psalm-param ScrapedStadiumRaces $programs
Expand All @@ -29,7 +29,7 @@ public function save(array $programs, string $path): void
}

$dir = dirname($path);
if (!is_dir($dir) && !mkdir($dir, 0777, true) && !is_dir($dir)) {
if (!is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) {
throw new \RuntimeException("Failed to create directory: {$dir}");
}

Expand Down
14 changes: 8 additions & 6 deletions tests/ProgramStorageTest.php → tests/ProgramSaverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace BOA\Programs\Tests;

use BOA\Programs\ProgramStorage;
use BOA\Programs\ProgramSaver;
use PHPUnit\Framework\TestCase;

/**
* @author shimomo
*/
final class ProgramStorageTest extends TestCase
final class ProgramSaverTest extends TestCase
{
/**
* @psalm-var non-empty-string
Expand All @@ -27,8 +27,10 @@ final class ProgramStorageTest extends TestCase
protected function setUp(): void
{
parent::setUp();
$this->tempDir = sys_get_temp_dir() . '/program_storage_test_' . uniqid();
mkdir($this->tempDir, 0777, true);
$this->tempDir = sys_get_temp_dir() . '/program_saver_test_' . bin2hex(random_bytes(8));
if (!mkdir($this->tempDir, 0755, true) && !is_dir($this->tempDir)) {
$this->fail('Failed to create temp dir: ' . $this->tempDir);
}
}

/**
Expand Down Expand Up @@ -59,7 +61,7 @@ protected function tearDown(): void
*/
public function testSave(): void
{
$storage = new ProgramStorage();
$saver = new ProgramSaver();
$path = $this->tempDir . '/programs.json';

$programs = [
Expand Down Expand Up @@ -102,7 +104,7 @@ public function testSave(): void
],
];

$storage->save($programs, $path);
$saver->save($programs, $path);

$this->assertFileExists($path);

Expand Down