delete(); $exitCode = Artisan::call('version:set', ['version' => '2.3.4']); expect($exitCode)->toBe(0); $setting = Setting::where('key', 'version')->value('value'); expect($setting)->toBe('2.3.4'); $data = json_decode((string) file_get_contents($path), true); expect($data['version'] ?? null)->toBe('2.3.4'); }); }); it('updates version when current exists', function (): void { withComposerBackupForSet(function (): void { Setting::updateOrCreate(['key' => 'version'], ['value' => '1.0.0']); $exitCode = Artisan::call('version:set', ['version' => '1.0.1']); expect($exitCode)->toBe(0); $setting = Setting::where('key', 'version')->value('value'); expect($setting)->toBe('1.0.1'); }); }); it('fails when composer.json cannot be read', function (): void { withComposerBackupForSet(function (string $path): void { chmod($path, 0000); $exitCode = Artisan::call('version:set', ['version' => '2.0.0']); expect($exitCode)->toBe(1); chmod($path, 0644); }); }); it('fails when composer.json cannot be decoded', function (): void { withComposerBackupForSet(function (string $path): void { file_put_contents($path, 'not-json'); $exitCode = Artisan::call('version:set', ['version' => '2.0.0']); expect($exitCode)->toBe(1); }); }); it('fails when file_get_contents returns false', function (): void { withComposerBackupForSet(function (): void { $GLOBALS['version_set_file_get_contents_false'] = true; $exitCode = Artisan::call('version:set', ['version' => '2.0.0']); expect($exitCode)->toBe(1); }); }); it('fails when json_encode returns false', function (): void { withComposerBackupForSet(function (): void { $GLOBALS['version_set_json_encode_false'] = true; $exitCode = Artisan::call('version:set', ['version' => '2.0.0']); expect($exitCode)->toBe(1); }); }); }