Skip to content
Luca Ubiali Web Developer

How to Contribute to Open Source - 7/13 - Prove Your Work Works

August 19th, 2024
Continuous Learning

Episode - https://laracasts.com/series/how-to-contribute-to-open-source/episodes/7


Was looking forward to this episode to see Pest in action.

Similarly to what Luke did at the beginning of the series for the application code, now is the time to code dive in the tests folder to get an idea what the new tests should look like.

Prompt class provides a fake method to pass in key presses and also a way to check the output of the terminal (besides the internal status of the prompt itself).

The happy path test looks like this:

1it('can run multiple steps', function () {
2 Prompt::fake([
3 'L', 'u', 'k', 'e', Key::ENTER,
4 Key::ENTER,
5 Key::ENTER,
6 ]);
7 
8 $responses = steps()
9 ->text('What is your name?')
10 ->select('What is your language?', ['PHP', 'JS'])
11 ->confirm('Are you sure?')
12 ->submit();
13 
14 expect($responses)->toBe([
15 'Luke',
16 'PHP',
17 true,
18 ]);
19});

Very clear and straightforward. It follows the structure:

  1. set up the world

  2. execute

  3. check

All the tests for steps used the above code as initial template and change slightly the list of steps and key presses to test reversibility, reversibility custom logic, access to steps data.

Even if I use tests often, every time I have to start from scratch tests for a new feature, the task seems more complex than it ends up to be. And here is the same. Looking at the test class it’s surprising how simple it is.