Skip to content
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

Allow build with no additional services #19

Merged
merged 3 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions resources/scripts/php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ docker run --rm \

cd {{ name }}

./vendor/bin/sail pull {{ services }}
./vendor/bin/sail build
# Allow build with no additional services
if [ "{{ services }}" == "none" ]; then
./vendor/bin/sail build
else
./vendor/bin/sail pull {{ services }}
./vendor/bin/sail build
fi

CYAN='\033[0;36m'
LIGHT_CYAN='\033[1;36m'
Expand Down
10 changes: 7 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@
'name' => 'string|alpha_dash',
'php' => ['string', Rule::in(['74', '80', '81', '82'])],
'with' => 'array',
'with.*' => ['required', 'string', Rule::in($availableServices)],
'with.*' => [
'required',
'string',
count($with) === 1 && in_array('none', $with) ? Rule::in(['none']) : Rule::in($availableServices)
],
]
);
} catch (ValidationException $e) {
$errors = Arr::undot($e->errors());

if (array_key_exists('name', $errors)) {
return response('Invalid site name. Please only use alpha-numeric characters, dashes, and underscores.', 400);
}
Expand All @@ -53,7 +57,7 @@
}

if (array_key_exists('with', $errors)) {
return response('Invalid service name. Please provide one or more of the supported services ('.implode(', ', $availableServices).').', 400);
return response('Invalid service name. Please provide one or more of the supported services ('.implode(', ', $availableServices).') or "none".', 400);
}
}

Expand Down
20 changes: 18 additions & 2 deletions tests/Feature/SailServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public function test_different_services_can_be_picked()
$response->assertSee('php ./artisan sail:install --with=pgsql,redis,selenium');
}

public function test_no_services_can_be_picked()
{
$response = $this->get('/example-app?with=none');

$response->assertStatus(200);
$response->assertSee('php ./artisan sail:install --with=none');
}

public function test_it_removes_duplicated_valid_services()
{
$response = $this->get('/example-app?with=redis,redis');
Expand Down Expand Up @@ -81,14 +89,22 @@ public function test_it_does_not_accept_empty_with_query_when_present()
$response = $this->get('/example-app?with');

$response->assertStatus(400);
$response->assertSee('Invalid service name. Please provide one or more of the supported services (mysql, pgsql, mariadb, redis, memcached, meilisearch, minio, mailpit, selenium, soketi).');
$response->assertSee('Invalid service name. Please provide one or more of the supported services (mysql, pgsql, mariadb, redis, memcached, meilisearch, minio, mailpit, selenium, soketi) or "none".', false);
}

public function test_it_does_not_accept_invalid_services()
{
$response = $this->get('/example-app?with=redis,invalid_service_name');

$response->assertStatus(400);
$response->assertSee('Invalid service name. Please provide one or more of the supported services (mysql, pgsql, mariadb, redis, memcached, meilisearch, minio, mailpit, selenium, soketi).');
$response->assertSee('Invalid service name. Please provide one or more of the supported services (mysql, pgsql, mariadb, redis, memcached, meilisearch, minio, mailpit, selenium, soketi) or "none".', false);
}

public function test_it_does_not_accept_none_with_other_services()
{
$response = $this->get('/example-app?with=none,redis');

$response->assertStatus(400);
$response->assertSee('Invalid service name. Please provide one or more of the supported services (mysql, pgsql, mariadb, redis, memcached, meilisearch, minio, mailpit, selenium, soketi) or "none".', false);
}
}