Skip to content

Commit 8054b61

Browse files
committed
test: add multiselect test as I believe something changed between versions which would make multiselect and the install command fail on Laravel 10 projects and I don't want it to
1 parent 385ed16 commit 8054b61

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Feature\Console;
6+
7+
use Laravel\Prompts\Key;
8+
use Laravel\Prompts\Prompt;
9+
use Tests\TestCase;
10+
11+
class InstallCommandMultiselectTest extends TestCase
12+
{
13+
/**
14+
* Test that multiselect returns keys when given an associative array.
15+
*/
16+
public function test_multiselect_returns_keys_for_associative_array(): void
17+
{
18+
// Mock the prompt to simulate user selecting options
19+
// Note: mcp_server is already selected by default, so we don't toggle it
20+
Prompt::fake([
21+
Key::DOWN, // Move to second option (ai_guidelines)
22+
Key::SPACE, // Select second option
23+
Key::ENTER, // Submit
24+
]);
25+
26+
$result = \Laravel\Prompts\multiselect(
27+
label: 'What shall we install?',
28+
options: [
29+
'mcp_server' => 'Boost MCP Server',
30+
'ai_guidelines' => 'Package AI Guidelines',
31+
'style_guidelines' => 'Laravel Style AI Guidelines',
32+
],
33+
default: ['mcp_server']
34+
);
35+
36+
// Assert that we get the keys, not the values
37+
$this->assertIsArray($result);
38+
$this->assertCount(2, $result, 'Should have 2 items selected');
39+
$this->assertContains('mcp_server', $result);
40+
$this->assertContains('ai_guidelines', $result);
41+
$this->assertNotContains('Boost MCP Server', $result);
42+
$this->assertNotContains('Package AI Guidelines', $result);
43+
}
44+
45+
/**
46+
* Test multiselect with numeric indexed array returns values.
47+
*/
48+
public function test_multiselect_returns_values_for_indexed_array(): void
49+
{
50+
Prompt::fake([
51+
Key::SPACE, // Select first option
52+
Key::DOWN, // Move to second option
53+
Key::SPACE, // Select second option
54+
Key::ENTER, // Submit
55+
]);
56+
57+
$result = \Laravel\Prompts\multiselect(
58+
label: 'Select options',
59+
options: ['Option 1', 'Option 2', 'Option 3'],
60+
default: []
61+
);
62+
63+
// For indexed arrays, it returns the actual values
64+
$this->assertIsArray($result);
65+
$this->assertContains('Option 1', $result);
66+
$this->assertContains('Option 2', $result);
67+
}
68+
69+
/**
70+
* Test that demonstrates multiselect behavior is consistent with InstallCommand expectations.
71+
* This ensures Laravel 10/11 compatibility.
72+
*/
73+
public function test_multiselect_behavior_matches_install_command_expectations(): void
74+
{
75+
// Test the exact same structure used in InstallCommand::boostToInstall()
76+
// Note: mcp_server and ai_guidelines are already selected by default
77+
Prompt::fake([
78+
Key::DOWN, // Move to ai_guidelines (already selected)
79+
Key::DOWN, // Move to style_guidelines
80+
Key::SPACE, // Select style_guidelines
81+
Key::ENTER, // Submit
82+
]);
83+
84+
$toInstallOptions = [
85+
'mcp_server' => 'Boost MCP Server',
86+
'ai_guidelines' => 'Package AI Guidelines (i.e. Framework, Inertia, Pest)',
87+
'style_guidelines' => 'Laravel Style AI Guidelines',
88+
];
89+
90+
$result = \Laravel\Prompts\multiselect(
91+
label: 'What shall we install?',
92+
options: $toInstallOptions,
93+
default: ['mcp_server', 'ai_guidelines'],
94+
required: true,
95+
hint: 'Style guidelines are best for new projects',
96+
);
97+
98+
// Verify we get keys that can be used with in_array checks
99+
$this->assertIsArray($result);
100+
$this->assertCount(3, $result); // All 3 selected (2 default + 1 added)
101+
102+
// These are the exact checks used in InstallCommand
103+
$this->assertTrue(in_array('mcp_server', $result, true));
104+
$this->assertTrue(in_array('ai_guidelines', $result, true));
105+
$this->assertTrue(in_array('style_guidelines', $result, true));
106+
107+
// Verify it doesn't contain the display values
108+
$this->assertFalse(in_array('Boost MCP Server', $result, true));
109+
$this->assertFalse(in_array('Package AI Guidelines (i.e. Framework, Inertia, Pest)', $result, true));
110+
}
111+
}

0 commit comments

Comments
 (0)