Skip to content

Commit

Permalink
[test] Add test for default call in console karnel (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
SonyPradana authored Oct 30, 2023
1 parent 66f07b3 commit 2e81d05
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/Integrate/Console/KarnelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ public function itCanCallCommandUsingPatternCommand()
$hasContent = Str::contains($out, 'command has founded');
$this->assertTrue($hasContent);
}

/** @test */
public function itCanCallCommandWithDefaultOption()
{
$karnel = new NormalCommand($this->app);
ob_start();
$exit = $karnel->handle(['cli', 'use:default_option', '--default="test"']);
$out = ob_get_clean();

$this->assertEquals(0, $exit);
$hasContent = Str::contains($out, 'test');
$this->assertTrue($hasContent);
}
}

class NormalCommand extends Karnel
Expand Down Expand Up @@ -172,6 +185,10 @@ protected function commands()
'pattern' => 'use:pattern',
'fn' => [FoundedCommand::class, 'main'],
]),
new CommandMap([
'pattern' => 'use:default_option',
'fn' => [FoundedCommand::class, 'default'],
]),
];
}
}
Expand All @@ -184,4 +201,11 @@ public function main(): int

return 0;
}

public function default(): int
{
style($this->default)->out(false);

return 0;
}
}

0 comments on commit 2e81d05

Please sign in to comment.