Add comprehensive test coverage and update notes
Some checks failed
CI/CD Pipeline / test (push) Successful in 3s
CI/CD Pipeline / deploy (push) Failing after 15s

This commit is contained in:
2026-02-08 19:04:12 +01:00
parent 160430e128
commit 88e4a70f88
43 changed files with 6114 additions and 520 deletions

View File

@@ -0,0 +1,122 @@
<?php
namespace App\Console\Commands {
if (!function_exists(__NAMESPACE__ . '\\file_get_contents')) {
function file_get_contents($path): string|false
{
if (!empty($GLOBALS['version_bump_file_get_contents_false']) && str_ends_with($path, 'composer.json')) {
return false;
}
if (!empty($GLOBALS['version_fetch_file_get_contents_false']) && str_ends_with($path, 'composer.json')) {
return false;
}
if (!empty($GLOBALS['version_set_file_get_contents_false']) && str_ends_with($path, 'composer.json')) {
return false;
}
if (!empty($GLOBALS['version_release_file_get_contents_false']) && str_ends_with($path, 'CHANGELOG.md')) {
return false;
}
return \file_get_contents($path);
}
}
if (!function_exists(__NAMESPACE__ . '\\json_encode')) {
function json_encode($value, int $flags = 0): string|false
{
if (!empty($GLOBALS['version_bump_json_encode_false'])) {
return false;
}
if (!empty($GLOBALS['version_fetch_json_encode_false']) && is_array($value) && array_key_exists('build', $value)) {
return false;
}
if (!empty($GLOBALS['version_set_json_encode_false'])) {
return false;
}
return \json_encode($value, $flags);
}
}
}
namespace {
use App\Models\Setting;
use Illuminate\Support\Facades\Artisan;
function withComposerBackup(callable $callback): void
{
$path = base_path('composer.json');
$original = file_get_contents($path);
try {
$callback($path, $original);
} finally {
if ($original !== false) {
file_put_contents($path, $original);
}
$GLOBALS['version_bump_file_get_contents_false'] = false;
$GLOBALS['version_bump_json_encode_false'] = false;
}
}
it('bumps patch version and syncs composer metadata', function (): void {
withComposerBackup(function (string $path): void {
Setting::updateOrCreate(['key' => 'version'], ['value' => '1.2.09-beta']);
$exitCode = Artisan::call('version:bump');
expect($exitCode)->toBe(0);
$setting = Setting::where('key', 'version')->value('value');
expect($setting)->toBe('1.2.10-beta');
$data = json_decode((string) file_get_contents($path), true);
expect($data['version'] ?? null)->toBe('1.2.10-beta');
});
});
it('fails when composer.json cannot be decoded', function (): void {
withComposerBackup(function (string $path): void {
file_put_contents($path, 'not-json');
Setting::updateOrCreate(['key' => 'version'], ['value' => '1.2.3']);
$exitCode = Artisan::call('version:bump');
expect($exitCode)->toBe(1);
});
});
it('fails when composer.json is not readable', function (): void {
withComposerBackup(function (string $path): void {
chmod($path, 0000);
Setting::updateOrCreate(['key' => 'version'], ['value' => '1.2.3']);
$exitCode = Artisan::call('version:bump');
expect($exitCode)->toBe(1);
chmod($path, 0644);
});
});
it('fails when file_get_contents returns false', function (): void {
withComposerBackup(function (): void {
$GLOBALS['version_bump_file_get_contents_false'] = true;
Setting::updateOrCreate(['key' => 'version'], ['value' => '1.2.3']);
$exitCode = Artisan::call('version:bump');
expect($exitCode)->toBe(1);
});
});
it('fails when json_encode returns false', function (): void {
withComposerBackup(function (): void {
$GLOBALS['version_bump_json_encode_false'] = true;
Setting::updateOrCreate(['key' => 'version'], ['value' => '1.2.3']);
$exitCode = Artisan::call('version:bump');
expect($exitCode)->toBe(1);
});
});
}