Skip to content

Commit 2814ea0

Browse files
committed
Update console output
1 parent 2995648 commit 2814ea0

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/Console/DeployCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(
4343
public function handle(): int
4444
{
4545
if (! $this->token) {
46-
$this->error('No NIGHTWATCH_TOKEN environment variable configured.');
46+
$this->components->error('Please configure the [NIGHTWATCH_TOKEN] environment variable.');
4747

4848
return 1;
4949
}
@@ -66,17 +66,17 @@ public function handle(): int
6666
])
6767
->throw();
6868

69-
$this->info('Deployment successful');
69+
$this->components->info('Deployment sent to Nightwatch successfully.');
7070

7171
return 0;
7272
} catch (RequestException $e) {
73-
$message = Str::limit($e->response->body(), 1000, '[...]');
73+
$message = Str::limit($e->response->json('message') ?? "[{$e->getCode()}] {$e->response->body()}", 1000, '[...]'); // @phpstan-ignore argument.type
7474

75-
$this->error("Deployment failed: {$e->getCode()} [{$message}]");
75+
$this->components->error("Deployment could not be sent to Nightwatch: {$message}");
7676

7777
return 1;
7878
} catch (Throwable $e) {
79-
$this->error("Deployment failed: [{$e->getMessage()}]");
79+
$this->components->error("Deployment could not be sent to Nightwatch: {$e->getMessage()}");
8080

8181
return 1;
8282
}

tests/Feature/Console/DeployCommandTest.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Tests\TestCase;
1111

1212
use function env;
13+
use function json_encode;
1314
use function now;
1415

1516
class DeployCommandTest extends TestCase
@@ -33,7 +34,7 @@ public function test_it_can_run_the_deploy_command(): void
3334
]);
3435

3536
$this->artisan('nightwatch:deploy')
36-
->expectsOutput('Deployment successful')
37+
->expectsOutputToContain('Deployment sent to Nightwatch successfully.')
3738
->assertExitCode(0);
3839
}
3940

@@ -55,7 +56,7 @@ public function test_it_can_run_the_deploy_command_without_a_version(): void
5556
]);
5657

5758
$this->artisan('nightwatch:deploy')
58-
->expectsOutput('Deployment successful')
59+
->expectsOutputToContain('Deployment sent to Nightwatch successfully.')
5960
->assertExitCode(0);
6061
}
6162

@@ -64,7 +65,19 @@ public function test_it_fails_when_the_deploy_command_is_run_without_a_token():
6465
$this->app->singleton(DeployCommand::class, fn () => new DeployCommand(token: null));
6566

6667
$this->artisan('nightwatch:deploy')
67-
->expectsOutput('No NIGHTWATCH_TOKEN environment variable configured.')
68+
->expectsOutputToContain('Please configure the [NIGHTWATCH_TOKEN] environment variable.')
69+
->assertExitCode(1);
70+
}
71+
72+
#[WithEnv('NIGHTWATCH_TOKEN', 'test-token')]
73+
public function test_it_handles_error_responses(): void
74+
{
75+
Http::fake([
76+
'*/api/deployments' => Http::response(json_encode(['message' => 'Invalid environment token.']), 403),
77+
]);
78+
79+
$this->artisan('nightwatch:deploy')
80+
->expectsOutputToContain('Deployment could not be sent to Nightwatch: Invalid environment token.')
6881
->assertExitCode(1);
6982
}
7083

@@ -76,7 +89,7 @@ public function test_it_handles_http_errors(): void
7689
]);
7790

7891
$this->artisan('nightwatch:deploy')
79-
->expectsOutput('Deployment failed: 500 [Whoops!]')
92+
->expectsOutputToContain('Deployment could not be sent to Nightwatch: [500] Whoops!')
8093
->assertExitCode(1);
8194
}
8295

@@ -88,7 +101,7 @@ public function test_it_handles_connection_errors(): void
88101
]);
89102

90103
$this->artisan('nightwatch:deploy')
91-
->expectsOutput('Deployment failed: [Whoops!]')
104+
->expectsOutputToContain('Deployment could not be sent to Nightwatch: Whoops!')
92105
->assertExitCode(1);
93106
}
94107
}

0 commit comments

Comments
 (0)