Skip to content

Commit fcd31a6

Browse files
[12.x] Fixed a bug in using illuminate/console in external apps (#55430)
* Fixed a bug in using `illuminate/console` in external apps * Update TaskResult.php * move file --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent f503618 commit fcd31a6

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/Illuminate/Console/View/Components/Task.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Illuminate\Console\View\Components;
44

5-
use Illuminate\Database\Migrations\MigrationResult;
5+
use Illuminate\Console\View\TaskResult;
66
use Illuminate\Support\InteractsWithTime;
77
use Symfony\Component\Console\Output\OutputInterface;
88
use Throwable;
@@ -35,10 +35,10 @@ public function render($description, $task = null, $verbosity = OutputInterface:
3535

3636
$startTime = microtime(true);
3737

38-
$result = MigrationResult::Failure;
38+
$result = TaskResult::Failure->value;
3939

4040
try {
41-
$result = ($task ?: fn () => MigrationResult::Success)();
41+
$result = ($task ?: fn () => TaskResult::Success->value)();
4242
} catch (Throwable $e) {
4343
throw $e;
4444
} finally {
@@ -55,8 +55,8 @@ public function render($description, $task = null, $verbosity = OutputInterface:
5555

5656
$this->output->writeln(
5757
match ($result) {
58-
MigrationResult::Failure => ' <fg=red;options=bold>FAIL</>',
59-
MigrationResult::Skipped => ' <fg=yellow;options=bold>SKIPPED</>',
58+
TaskResult::Failure->value => ' <fg=red;options=bold>FAIL</>',
59+
TaskResult::Skipped->value => ' <fg=yellow;options=bold>SKIPPED</>',
6060
default => ' <fg=green;options=bold>DONE</>'
6161
},
6262
$verbosity,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Illuminate\Console\View;
4+
5+
enum TaskResult: int
6+
{
7+
case Success = 1;
8+
case Failure = 2;
9+
case Skipped = 3;
10+
}

src/Illuminate/Database/Migrations/Migrator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ protected function runUp($file, $batch, $pretend)
245245
: true;
246246

247247
if (! $shouldRunMigration) {
248-
$this->write(Task::class, $name, fn () => MigrationResult::Skipped);
248+
$this->write(Task::class, $name, fn () => MigrationResult::Skipped->value);
249249
} else {
250250
$this->write(Task::class, $name, fn () => $this->runMigration($migration, 'up'));
251251

tests/Console/View/ComponentsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,17 @@ public function testTask()
109109
{
110110
$output = new BufferedOutput();
111111

112-
with(new Components\Task($output))->render('My task', fn () => MigrationResult::Success);
112+
with(new Components\Task($output))->render('My task', fn () => MigrationResult::Success->value);
113113
$result = $output->fetch();
114114
$this->assertStringContainsString('My task', $result);
115115
$this->assertStringContainsString('DONE', $result);
116116

117-
with(new Components\Task($output))->render('My task', fn () => MigrationResult::Failure);
117+
with(new Components\Task($output))->render('My task', fn () => MigrationResult::Failure->value);
118118
$result = $output->fetch();
119119
$this->assertStringContainsString('My task', $result);
120120
$this->assertStringContainsString('FAIL', $result);
121121

122-
with(new Components\Task($output))->render('My task', fn () => MigrationResult::Skipped);
122+
with(new Components\Task($output))->render('My task', fn () => MigrationResult::Skipped->value);
123123
$result = $output->fetch();
124124
$this->assertStringContainsString('My task', $result);
125125
$this->assertStringContainsString('SKIPPED', $result);

0 commit comments

Comments
 (0)