Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new env and config change support #139

Merged
merged 5 commits into from
Feb 22, 2025
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
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

All notable changes to `breezejp` will be documented in this file.

## v2.1.0 - 2025-02-21

### What's Changed

#### Laravel 11の急な環境設定方法の変更に対応

https://github.com/laravel/laravel/pull/6536 による変更で`.env`に記載していた`APP_TIMEZONE`を廃止し、旧式の`config/app.php`の`'timezone'`に変更となった

* Fix for Laravel 11 Breaking Change by @askdkc in https://github.com/askdkc/breezejp/pull/137

### メジャーバージョンならいざ知らず、マイナーバージョンでこうした変更入れるの勘弁して〜😵

**Full Changelog**: https://github.com/askdkc/breezejp/compare/v2.0.0...v2.1.0

## v2.0.0 - 2025-02-18

### What's Changed
Expand Down Expand Up @@ -131,6 +145,7 @@ php artisan breezejp --langswitch




```
##### 細かい変更点一覧

Expand Down
24 changes: 16 additions & 8 deletions src/Commands/BreezejpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,26 @@ public function handle(): int

}

// For Laravel 11 and above
$this->info('.envのAPP_LOCALEやAPP_TIMEZONEを日本にします');
// Message switch before Laravel 11.6.2 and after
strpos($envfile, 'APP_TIMEZONE=UTC') ? $this->info('.envのAPP_LOCALEやAPP_TIMEZONEを日本にします') : $this->info('.envのAPP_LOCALEやAPP_FAKER_LOCALEを日本語にします');

// Read the contents of the file into a string
$configfile = file_get_contents(base_path('.env'));

// Modify the contents of the string
$configfile = str_replace('APP_LOCALE=en', 'APP_LOCALE=ja', $configfile);
$configfile = str_replace('APP_FAKER_LOCALE=en_US', 'APP_FAKER_LOCALE=ja_JP', $configfile);
$configfile = str_replace('APP_TIMEZONE=UTC', 'APP_TIMEZONE=Asia/Tokyo', $configfile);

$envfile = str_replace('APP_LOCALE=en', 'APP_LOCALE=ja', $envfile);
$envfile = str_replace('APP_FAKER_LOCALE=en_US', 'APP_FAKER_LOCALE=ja_JP', $envfile);
$envfile = str_replace('APP_TIMEZONE=UTC', 'APP_TIMEZONE=Asia/Tokyo', $envfile);
// Save the modified contents back to the file
file_put_contents(base_path('.env'), $configfile);
file_put_contents(base_path('.env'), $envfile);

$configfile = file_get_contents(base_path('config/app.php'));
if (strpos($configfile, "'timezone' => 'UTC'")) {
$this->info('config/app.phpのtimezoneをAsia/Tokyoにします');
// Modify the contents of the string
$configfile = str_replace("'timezone' => 'UTC'", "'timezone' => 'Asia/Tokyo'", $configfile);
// Save the modified contents back to the file
file_put_contents(base_path('config/app.php'), $configfile);
}

if ($this->confirm('GitHubリポジトリにスターの御協力をお願いします🙏', true)) {
$repoUrl = 'https://github.com/askdkc/breezejp';
Expand Down
31 changes: 23 additions & 8 deletions tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$this->assertFileExists(base_path('lang/ja/validation.php'));
});

test('breezejp command successfully update config/app.php locale to ja', function () {
test('breezejp command successfully update env or config/app.php locale to ja', function () {
$this->artisan('breezejp')
->expectsOutput('Laravel Breeze用に日本語翻訳ファイルを準備します')
->expectsConfirmation('GitHubリポジトリにスターの御協力をお願いします🙏', 'no')
Expand All @@ -31,14 +31,23 @@
$this->assertStringContainsString("'faker_locale' => 'ja_JP'", $configfile);
$this->assertStringContainsString("'timezone' => 'Asia/Tokyo'", $configfile);
} else { // For Laravel 11 and above
$configfile = file_get_contents(base_path('.env'));
$this->assertStringContainsString('APP_LOCALE=ja', $configfile);
$this->assertStringContainsString('APP_FAKER_LOCALE=ja_JP', $configfile);
$this->assertStringContainsString('APP_TIMEZONE=Asia/Tokyo', $configfile);
$envfile = file_get_contents(base_path('.env'));
// For Stupid Laravel 11 Breaking Changes
$configfile = file_get_contents(base_path('config/app.php'));
if (! strpos($configfile, "'timezone' => env")) {
$this->assertStringContainsString('APP_LOCALE=ja', $envfile);
$this->assertStringContainsString('APP_FAKER_LOCALE=ja_JP', $envfile);
$this->assertStringContainsString("'timezone' => 'Asia/Tokyo'", $configfile);
} else {
$this->assertStringContainsString('APP_LOCALE=ja', $envfile);
$this->assertStringContainsString('APP_FAKER_LOCALE=ja_JP', $envfile);
$this->assertStringContainsString('APP_TIMEZONE=Asia/Tokyo', $envfile);
}

}
});

test('breezejp command successfully update config/app.php timezone to Asia/Tokyo', function () {
test('breezejp command successfully update env or config/app.php timezone to Asia/Tokyo', function () {
$this->artisan('breezejp')
->expectsOutput('Laravel Breeze用に日本語翻訳ファイルを準備します')
->expectsConfirmation('GitHubリポジトリにスターの御協力をお願いします🙏', 'no')
Expand All @@ -49,7 +58,13 @@
$configfile = file_get_contents(base_path('config/app.php'));
$this->assertStringContainsString("'timezone' => 'Asia/Tokyo'", $configfile);
} else { // For Laravel 11 and above
$configfile = file_get_contents(base_path('.env'));
$this->assertStringContainsString('APP_TIMEZONE=Asia/Tokyo', $configfile);
$configfile = file_get_contents(base_path('config/app.php'));
// For Stupid Laravel 11 Breaking Changes
if (! strpos($configfile, "'timezone' => env")) {
$this->assertStringContainsString("'timezone' => 'Asia/Tokyo'", $configfile);
} else {
$envfile = file_get_contents(base_path('.env'));
$this->assertStringContainsString('APP_TIMEZONE=Asia/Tokyo', $envfile);
}
}
});
Loading