-
Notifications
You must be signed in to change notification settings - Fork 0
test: extract mock fixtures #28
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5ce8275
test: extract MockFilesystem and MockSSHService to fixtures
loadinglucian efe5a02
feat(prompter): extract prompter service for better testability
loadinglucian d36f881
test: improve MockFilesystem path matching
loadinglucian b559c61
style: remove trailing newline in PrompterService.php
loadinglucian 1eca423
refactor(test): extract directory dynamically from mock path
loadinglucian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,246 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Bigpixelrocket\DeployerPHP\Services; | ||
|
|
||
| use Closure; | ||
|
|
||
| use function Laravel\Prompts\confirm; | ||
| use function Laravel\Prompts\multiselect; | ||
| use function Laravel\Prompts\password; | ||
| use function Laravel\Prompts\pause; | ||
| use function Laravel\Prompts\search; | ||
| use function Laravel\Prompts\select; | ||
| use function Laravel\Prompts\spin; | ||
| use function Laravel\Prompts\suggest; | ||
| use function Laravel\Prompts\text; | ||
|
|
||
| /** | ||
| * User input prompting service. | ||
| * | ||
| * Wraps Laravel Prompts functions for dependency injection and testability. | ||
| */ | ||
| class PrompterService | ||
| { | ||
| // | ||
| // Prompt Methods | ||
| // ------------------------------------------------------------------------------- | ||
|
|
||
| /** | ||
| * Prompt for text input. | ||
| */ | ||
| public function text( | ||
| string $label, | ||
| string $placeholder = '', | ||
| string $default = '', | ||
| bool $required = true, | ||
| mixed $validate = null, | ||
| string $hint = '' | ||
| ): string { | ||
| $this->suppressPromptSpacing(); | ||
|
|
||
| return text( | ||
| label: $label, | ||
| placeholder: $placeholder, | ||
| default: $default, | ||
| required: $required, | ||
| validate: $validate, | ||
| hint: $hint | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Prompt for password input. | ||
| */ | ||
| public function password( | ||
| string $label, | ||
| string $placeholder = '', | ||
| bool $required = true, | ||
| mixed $validate = null, | ||
| string $hint = '' | ||
| ): string { | ||
| $this->suppressPromptSpacing(); | ||
|
|
||
| return password( | ||
| label: $label, | ||
| placeholder: $placeholder, | ||
| required: $required, | ||
| validate: $validate, | ||
| hint: $hint | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Prompt for yes/no confirmation. | ||
| */ | ||
| public function confirm( | ||
| string $label, | ||
| bool $default = true, | ||
| string $yes = 'Yes', | ||
| string $no = 'No', | ||
| string $hint = '' | ||
| ): bool { | ||
| $this->suppressPromptSpacing(); | ||
|
|
||
| return confirm( | ||
| label: $label, | ||
| default: $default, | ||
| yes: $yes, | ||
| no: $no, | ||
| hint: $hint | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Display a message and wait for user to press Enter. | ||
| */ | ||
| public function pause(string $message = 'Press enter to continue...'): bool | ||
| { | ||
| $this->suppressPromptSpacing(); | ||
|
|
||
| return pause($message); | ||
| } | ||
|
|
||
| /** | ||
| * Prompt for single selection from options. | ||
| * | ||
| * @param array<int|string, string> $options | ||
| */ | ||
| public function select( | ||
| string $label, | ||
| array $options, | ||
| int|string|null $default = null, | ||
| int $scroll = 5, | ||
| mixed $validate = null, | ||
| string $hint = '' | ||
| ): int|string { | ||
| $this->suppressPromptSpacing(); | ||
|
|
||
| return select( | ||
| label: $label, | ||
| options: $options, | ||
| default: $default, | ||
| scroll: $scroll, | ||
| validate: $validate, | ||
| hint: $hint | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Prompt for multiple selections from options. | ||
| * | ||
| * @param array<int|string, string> $options | ||
| * @param array<int|string> $default | ||
| * | ||
| * @return array<int|string> | ||
| */ | ||
| public function multiselect( | ||
| string $label, | ||
| array $options, | ||
| array $default = [], | ||
| int $scroll = 5, | ||
| bool $required = false, | ||
| mixed $validate = null, | ||
| string $hint = '' | ||
| ): array { | ||
| $this->suppressPromptSpacing(); | ||
|
|
||
| return multiselect( | ||
| label: $label, | ||
| options: $options, | ||
| default: $default, | ||
| scroll: $scroll, | ||
| required: $required, | ||
| validate: $validate, | ||
| hint: $hint | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Prompt with autocomplete suggestions. | ||
| * | ||
| * @param array<string>|Closure $options | ||
| */ | ||
| public function suggest( | ||
| string $label, | ||
| array|Closure $options, | ||
| string $placeholder = '', | ||
| string $default = '', | ||
| int $scroll = 5, | ||
| bool $required = true, | ||
| mixed $validate = null, | ||
| string $hint = '' | ||
| ): string { | ||
| $this->suppressPromptSpacing(); | ||
|
|
||
| return suggest( | ||
| label: $label, | ||
| options: $options, | ||
| placeholder: $placeholder, | ||
| default: $default, | ||
| scroll: $scroll, | ||
| required: $required, | ||
| validate: $validate, | ||
| hint: $hint | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Prompt with searchable options. | ||
| */ | ||
| public function search( | ||
| string $label, | ||
| Closure $options, | ||
| string $placeholder = '', | ||
| int $scroll = 5, | ||
| mixed $validate = null, | ||
| string $hint = '' | ||
| ): int|string { | ||
| $this->suppressPromptSpacing(); | ||
|
|
||
| return search( | ||
| label: $label, | ||
| options: $options, | ||
| placeholder: $placeholder, | ||
| scroll: $scroll, | ||
| validate: $validate, | ||
| hint: $hint | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Display a loading spinner during long operations. | ||
| * | ||
| * @template T | ||
| * | ||
| * @param Closure(): T $callback | ||
| * | ||
| * @return T | ||
| */ | ||
| public function spin( | ||
| Closure $callback, | ||
| string $message = 'Loading...' | ||
| ): mixed { | ||
| return spin( | ||
| callback: $callback, | ||
| message: $message | ||
| ); | ||
| } | ||
|
|
||
| // | ||
| // Private Helpers | ||
| // ------------------------------------------------------------------------------- | ||
|
|
||
| /** | ||
| * Remove the annoying newline that Laravel Prompts adds before each prompt. | ||
| * | ||
| * Uses ANSI escape sequence to move cursor up one line and clear it. | ||
| */ | ||
| private function suppressPromptSpacing(): void | ||
| { | ||
| // Move cursor up one line and clear it | ||
| // This compensates for the newline Laravel Prompts adds | ||
| echo "\033[1A\033[2K"; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.