Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
APP_KEY=
# DEV_PHP_VERSION=8.5-dev-macos
DEV_PHP_VERSION=8.5-dev
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,6 @@ docker-test: docker-build

docker-shell: docker-build
docker run --rm -it -v "$$(pwd)":/workspace --entrypoint sh $(DOCKER_IMAGE)


include Makefile.dev.mk
17 changes: 17 additions & 0 deletions Makefile.dev.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
up:
docker compose up -d

down:
docker compose down

restart: down up

bash:
docker compose exec php bash

test:
docker compose exec php bash -c 'XDEBUG_MODE=coverage composer test'

check:
docker compose exec php bash -c 'composer lint && composer test:types'

12 changes: 12 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
php:
image: "wodby/php:8.5-dev-macos"
environment:
PHP_EXTENSIONS_DISABLE: 'xhprof,spx'
healthcheck:
test: ["CMD", "php", "-v"]
interval: 10s
timeout: 5s
retries: 3
volumes:
- .:/var/www/html
39 changes: 17 additions & 22 deletions tests/Feature/Commands/InitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,40 +232,35 @@

it('returns an IO error when a new .env cannot be written', function (): void {
// No APP_KEY anywhere -> the command tries to create a fresh .env.
// Making the disk root read-only forces Storage::put() to fail, which
// bubbles up as a RuntimeException and is reported as an IO error.
// Forcing Storage::put() to return false (as it would on a failed write)
// bubbles up as a RuntimeException and is reported as an IO error. We mock
// rather than chmod because chmod is a no-op under root (e.g. in Docker).
putenv('APP_KEY');
unset($_ENV['APP_KEY'], $_SERVER['APP_KEY']);

$root = Storage::path('');
chmod($root, 0500);
Storage::shouldReceive('exists')->with('.env')->andReturn(false);
Storage::shouldReceive('put')->with('.env', Mockery::type('string'))->andReturn(false);

try {
$this->artisan('init')
->expectsOutputToContain('permission denied')
->assertExitCode(ExitCode::IoError->value);
} finally {
chmod($root, 0755);
}
$this->artisan('init')
->expectsOutputToContain('permission denied')
->assertExitCode(ExitCode::IoError->value);
});

it('returns an IO error when an existing .env cannot be overwritten', function (): void {
// An existing .env without an APP_KEY would normally be appended to, but
// making the file itself read-only forces the write to fail.
// forcing Storage::put() to return false makes the rewrite fail. We mock
// rather than chmod because chmod is a no-op under root (e.g. in Docker).
putenv('APP_KEY');
unset($_ENV['APP_KEY'], $_SERVER['APP_KEY']);

Storage::put('.env', "DB_HOST=localhost\n");
$path = Storage::path('.env');
chmod($path, 0400);
Storage::shouldReceive('exists')->with('.env')->andReturn(true);
Storage::shouldReceive('get')->with('.env')->andReturn("DB_HOST=localhost\n");
Storage::shouldReceive('path')->with('.env')->andReturn('/tmp/clonio-readonly.env');
Storage::shouldReceive('put')->with('.env', Mockery::type('string'))->andReturn(false);

try {
$this->artisan('init')
->expectsOutputToContain('permission denied')
->assertExitCode(ExitCode::IoError->value);
} finally {
chmod($path, 0644);
}
$this->artisan('init')
->expectsOutputToContain('permission denied')
->assertExitCode(ExitCode::IoError->value);
});

it('returns an IO error when an existing .env cannot be read', function (): void {
Expand Down