Skip to content

Commit 3efb76b

Browse files
authored
Allow some install failures (#66)
1 parent 6ff670a commit 3efb76b

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/CommandTasks.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,12 @@ public function setOutput(OutputStyle $output): self
4848
* @param callable $task
4949
* @return self
5050
*/
51-
public function addTask(string $name, callable $task): self
51+
public function addTask(string $name, callable $task, bool $throwOnFail = false): self
5252
{
53-
$this->tasks[$name] = $task;
53+
$this->tasks[$name] = [
54+
'task' => $task,
55+
'throw_on_fail' => $throwOnFail,
56+
];
5457

5558
return $this;
5659
}
@@ -65,7 +68,7 @@ public function addTask(string $name, callable $task): self
6568
public function runTasks(): void
6669
{
6770
Collection::make($this->tasks)->each(function ($task, $description) {
68-
$result = $task();
71+
$result = $task['task']();
6972

7073
if ($this->output) {
7174
$this->output->writeLn(vsprintf('%s: %s', [
@@ -76,7 +79,7 @@ public function runTasks(): void
7679

7780
$this->results[$description] = $result;
7881

79-
if (! $result && $this->throwOnError) {
82+
if (! $result && $task['throw_on_fail'] && $this->throwOnError) {
8083
throw new TaskFailed(sprintf('%s failed, please review output and try again.', $description));
8184
}
8285
});

src/Commands/HoneybadgerInstallCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ private function sendTest(): array
123123
'Send test exception to Honeybadger',
124124
function () use ($result) {
125125
return ! empty($result);
126-
}
126+
},
127+
true
127128
);
128129

129130
return $result;

tests/CommandTasksTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function outputs_unsuccessful_tasks()
4444
$commandTasks->setOutput($output);
4545
$commandTasks->addTask('Example Task', function () {
4646
return false;
47-
});
47+
}, true);
4848

4949
$commandTasks->runTasks();
5050

@@ -73,7 +73,7 @@ public function outputs_multiple_tasks()
7373
});
7474
$commandTasks->addTask('Example failed task', function () {
7575
return false;
76-
});
76+
}, true);
7777

7878
$commandTasks->runTasks();
7979

@@ -94,7 +94,7 @@ public function whether_any_tasks_have_failed()
9494
});
9595
$commandTasks->addTask('Example failed task', function () {
9696
return false;
97-
});
97+
}, true);
9898

9999
$commandTasks->runTasks();
100100

tests/Commands/HoneybadgerInstallCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public function outputs_retry_text_if_any_tasks_fail()
256256

257257
$command->expects($this->once())
258258
->method('error')
259-
->with('Write HONEYBADGER_API_KEY to .env failed, please review output and try again.');
259+
->with('Send test exception to Honeybadger failed, please review output and try again.');
260260

261261
$this->app[Kernel::class]->registerCommand($command);
262262

0 commit comments

Comments
 (0)