Skip to content

Commit

Permalink
add ability to reset cancel using + reset when using it in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joetannenbaum committed Mar 6, 2024
1 parent 4d8a63d commit 1a7a8c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Prompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ abstract class Prompt
/**
* The cancellation callback.
*/
protected static Closure $cancelUsing;
protected static ?Closure $cancelUsing;

/**
* Indicates if the prompt has been validated.
Expand Down Expand Up @@ -136,7 +136,7 @@ public function prompt(): mixed
/**
* Register a callback to be invoked when a user cancels a prompt.
*/
public static function cancelUsing(Closure $callback): void
public static function cancelUsing(?Closure $callback): void
{
static::$cancelUsing = $callback;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Feature/TextPromptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

use function Laravel\Prompts\text;

afterEach(function () {
Prompt::cancelUsing(null);
});

it('returns the input', function () {
Prompt::fake(['J', 'e', 's', 's', Key::ENTER]);

Expand Down

0 comments on commit 1a7a8c6

Please sign in to comment.