Skip to content

Commit 2b0f0c8

Browse files
committed
テスト用出力フォルダの作成 & ビルド前にテスト実施
1 parent 2f47aa3 commit 2b0f0c8

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: build api files
3030
env:
3131
TZ: 'Asia/Tokyo'
32-
run: composer build
32+
run: composer test && composer build
3333

3434
- name: commit and push
3535
run: |

.github/workflows/touch.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: touch
2828
env:
2929
TZ: 'Asia/Tokyo'
30-
run: composer touch
30+
run: composer test && composer touch
3131

3232
- name: commit and push
3333
run: |

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/tests/tmp/*
12
/vendor/
23
.idea/
34
.*.cache

app/holidaysJP.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212
class holidaysJP
1313
{
1414
protected $ical_url;
15-
const DIST = __DIR__ . '/../docs/v1';
15+
protected $dist;
1616

1717
/**
1818
* holidaysJP constructor.
1919
* @param $url
2020
*/
21-
public function __construct($url = null)
21+
public function __construct($url = null, $dist = null)
2222
{
2323
date_default_timezone_set('Asia/Tokyo');
2424

2525
$this->ical_url = $url ?: 'https://calendar.google.com/calendar/ical/ja.japanese%23holiday%40group.v.calendar.google.com/public/basic.ics';
26+
$this->dist = $dist ?: dirname(__DIR__) . '/docs/v1';
2627
}
2728

2829
/**
@@ -162,7 +163,7 @@ public function filter_for_3years(Collection $holidays): Collection
162163
function generate_api_file(Collection $data, string $year = '')
163164
{
164165
// 出力先フォルダがなければ作成
165-
$dist_dir = (!empty($year)) ? self::DIST . '/' . $year : self::DIST;
166+
$dist_dir = (!empty($year)) ? "{$this->dist}/{$year}" : $this->dist;
166167
if (!is_dir($dist_dir)) {
167168
mkdir($dist_dir);
168169
}

tests/holidaysJPTest.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*/
1111
class holidaysJPTest extends TestCase
1212
{
13+
private $dist = __DIR__ . '/tmp';
14+
1315
/**
1416
* ical解析関連のテスト
1517
*/
@@ -35,7 +37,7 @@ public function testGenerator()
3537
{
3638
// 実際のデータの生成
3739
$url = 'https://calendar.google.com/calendar/ical/japanese__ja@holiday.calendar.google.com/public/full.ics';
38-
$holidays = new holidaysJP($url);
40+
$holidays = new holidaysJP($url, $this->dist);
3941
$holidays->generate();
4042

4143
// 一覧データのチェック
@@ -60,11 +62,11 @@ public function testGenerator()
6062

6163
// 2024/2025 ファイル一致チェック
6264
$file1 = file_get_contents(__DIR__ . '/data/2024.json');
63-
$file2 = file_get_contents(dirname(__DIR__) . '/docs/v1/2024/date.json');
65+
$file2 = file_get_contents("{$this->dist}/2024/date.json");
6466
$this->assertEquals($file1, $file2);
6567

6668
$file1 = file_get_contents(__DIR__ . '/data/2025.json');
67-
$file2 = file_get_contents(dirname(__DIR__) . '/docs/v1/2025/date.json');
69+
$file2 = file_get_contents("{$this->dist}/2025/date.json");
6870
$this->assertEquals($file1, $file2);
6971
}
7072

@@ -79,7 +81,7 @@ private function checkApiFile($filename, $year, bool $is_datetime = false)
7981
$data = array();
8082

8183
// ファイルの存在チェック
82-
$filename = dirname(__DIR__) . "/docs/v1/{$filename}";
84+
$filename = "{$this->dist}/{$filename}";
8385

8486
$this->assertFileExists($filename);
8587

tests/tmp/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)