From 2b0f0c867f09e49a93fae19ed90d3fd5bfdba7a5 Mon Sep 17 00:00:00 2001 From: matsuoshi Date: Mon, 9 Sep 2024 17:25:21 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E7=94=A8=E5=87=BA?= =?UTF-8?q?=E5=8A=9B=E3=83=95=E3=82=A9=E3=83=AB=E3=83=80=E3=81=AE=E4=BD=9C?= =?UTF-8?q?=E6=88=90=20&=20=E3=83=93=E3=83=AB=E3=83=89=E5=89=8D=E3=81=AB?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E5=AE=9F=E6=96=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 2 +- .github/workflows/touch.yml | 2 +- .gitignore | 1 + app/holidaysJP.php | 7 ++++--- tests/holidaysJPTest.php | 10 ++++++---- tests/tmp/.gitkeep | 0 6 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 tests/tmp/.gitkeep diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7a257e3..5d4b9cf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,7 +29,7 @@ jobs: - name: build api files env: TZ: 'Asia/Tokyo' - run: composer build + run: composer test && composer build - name: commit and push run: | diff --git a/.github/workflows/touch.yml b/.github/workflows/touch.yml index 9f80891..3bac8a6 100644 --- a/.github/workflows/touch.yml +++ b/.github/workflows/touch.yml @@ -27,7 +27,7 @@ jobs: - name: touch env: TZ: 'Asia/Tokyo' - run: composer touch + run: composer test && composer touch - name: commit and push run: | diff --git a/.gitignore b/.gitignore index c1522c9..6d9c388 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/tests/tmp/* /vendor/ .idea/ .*.cache diff --git a/app/holidaysJP.php b/app/holidaysJP.php index 8b6268e..0d23021 100644 --- a/app/holidaysJP.php +++ b/app/holidaysJP.php @@ -12,17 +12,18 @@ class holidaysJP { protected $ical_url; - const DIST = __DIR__ . '/../docs/v1'; + protected $dist; /** * holidaysJP constructor. * @param $url */ - public function __construct($url = null) + public function __construct($url = null, $dist = null) { date_default_timezone_set('Asia/Tokyo'); $this->ical_url = $url ?: 'https://calendar.google.com/calendar/ical/ja.japanese%23holiday%40group.v.calendar.google.com/public/basic.ics'; + $this->dist = $dist ?: dirname(__DIR__) . '/docs/v1'; } /** @@ -162,7 +163,7 @@ public function filter_for_3years(Collection $holidays): Collection function generate_api_file(Collection $data, string $year = '') { // 出力先フォルダがなければ作成 - $dist_dir = (!empty($year)) ? self::DIST . '/' . $year : self::DIST; + $dist_dir = (!empty($year)) ? "{$this->dist}/{$year}" : $this->dist; if (!is_dir($dist_dir)) { mkdir($dist_dir); } diff --git a/tests/holidaysJPTest.php b/tests/holidaysJPTest.php index 86be087..896ca31 100644 --- a/tests/holidaysJPTest.php +++ b/tests/holidaysJPTest.php @@ -10,6 +10,8 @@ */ class holidaysJPTest extends TestCase { + private $dist = __DIR__ . '/tmp'; + /** * ical解析関連のテスト */ @@ -35,7 +37,7 @@ public function testGenerator() { // 実際のデータの生成 $url = 'https://calendar.google.com/calendar/ical/japanese__ja@holiday.calendar.google.com/public/full.ics'; - $holidays = new holidaysJP($url); + $holidays = new holidaysJP($url, $this->dist); $holidays->generate(); // 一覧データのチェック @@ -60,11 +62,11 @@ public function testGenerator() // 2024/2025 ファイル一致チェック $file1 = file_get_contents(__DIR__ . '/data/2024.json'); - $file2 = file_get_contents(dirname(__DIR__) . '/docs/v1/2024/date.json'); + $file2 = file_get_contents("{$this->dist}/2024/date.json"); $this->assertEquals($file1, $file2); $file1 = file_get_contents(__DIR__ . '/data/2025.json'); - $file2 = file_get_contents(dirname(__DIR__) . '/docs/v1/2025/date.json'); + $file2 = file_get_contents("{$this->dist}/2025/date.json"); $this->assertEquals($file1, $file2); } @@ -79,7 +81,7 @@ private function checkApiFile($filename, $year, bool $is_datetime = false) $data = array(); // ファイルの存在チェック - $filename = dirname(__DIR__) . "/docs/v1/{$filename}"; + $filename = "{$this->dist}/{$filename}"; $this->assertFileExists($filename); diff --git a/tests/tmp/.gitkeep b/tests/tmp/.gitkeep new file mode 100644 index 0000000..e69de29