Skip to content

Commit

Permalink
テスト用出力フォルダの作成 & ビルド前にテスト実施
Browse files Browse the repository at this point in the history
  • Loading branch information
matsuoshi committed Sep 9, 2024
1 parent 2f47aa3 commit 2b0f0c8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/touch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: touch
env:
TZ: 'Asia/Tokyo'
run: composer touch
run: composer test && composer touch

- name: commit and push
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/tests/tmp/*
/vendor/
.idea/
.*.cache
7 changes: 4 additions & 3 deletions app/holidaysJP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 6 additions & 4 deletions tests/holidaysJPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
class holidaysJPTest extends TestCase
{
private $dist = __DIR__ . '/tmp';

/**
* ical解析関連のテスト
*/
Expand All @@ -35,7 +37,7 @@ public function testGenerator()
{
// 実際のデータの生成
$url = 'https://calendar.google.com/calendar/ical/[email protected]/public/full.ics';
$holidays = new holidaysJP($url);
$holidays = new holidaysJP($url, $this->dist);
$holidays->generate();

// 一覧データのチェック
Expand All @@ -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);
}

Expand All @@ -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);

Expand Down
Empty file added tests/tmp/.gitkeep
Empty file.

0 comments on commit 2b0f0c8

Please sign in to comment.