Skip to content

Commit

Permalink
dev: Improve signature of CommandTestsHelper::executeCommand
Browse files Browse the repository at this point in the history
We need more often to pass arguments than passing direct inputs, so I
switched the order of both arguments (and I fixed type hinting).

I've also set "interactive" mode to false when the inputs are not given
to avoid warning in commands that support the `--no-interaction` option
(passing it as argument doesn't work).
  • Loading branch information
marien-probesys committed Sep 1, 2023
1 parent aa6b0d5 commit 81816de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions tests/Command/Users/CreateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function testExecuteCreatesAUser(): void

$this->assertSame(0, UserFactory::count());

$tester = self::executeCommand('app:users:create', [
$tester = self::executeCommand('app:users:create', [], [
$email,
$password,
]);
Expand Down Expand Up @@ -60,7 +60,7 @@ public function testExecuteWorksWhenPassingOptions(): void

$this->assertSame(0, UserFactory::count());

$tester = self::executeCommand('app:users:create', [], [
$tester = self::executeCommand('app:users:create', [
'--email' => $email,
'--password' => $password,
]);
Expand All @@ -87,7 +87,7 @@ public function testExecuteFailsIfEmailIsInvalid(): void

$this->assertSame(0, UserFactory::count());

$tester = self::executeCommand('app:users:create', [], [
$tester = self::executeCommand('app:users:create', [
'--email' => $email,
'--password' => $password,
]);
Expand All @@ -106,7 +106,7 @@ public function testExecuteFailsIfEmailIsEmpty(): void

$this->assertSame(0, UserFactory::count());

$tester = self::executeCommand('app:users:create', [], [
$tester = self::executeCommand('app:users:create', [
'--email' => $email,
'--password' => $password,
]);
Expand All @@ -131,7 +131,7 @@ public function testExecuteFailsIfEmailExists(): void

$this->assertSame(1, UserFactory::count());

$tester = self::executeCommand('app:users:create', [], [
$tester = self::executeCommand('app:users:create', [
'--email' => $email,
'--password' => $password,
]);
Expand Down
6 changes: 3 additions & 3 deletions tests/CommandTestsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ public static function setUpConsoleTestsHelper(): void
}

/**
* @param string $command
* @param array<string, mixed> $args
* @param array<string> $inputs
* @param array<string> $args
*/
protected static function executeCommand(
string $command,
array $inputs = [],
array $args = [],
array $inputs = [],
): CommandTester {
$command = self::$application->find($command);
$commandTester = new CommandTester($command);
$commandTester->setInputs($inputs);
$commandTester->execute($args, [
'interactive' => !empty($inputs),
'capture_stderr_separately' => true,
]);
return $commandTester;
Expand Down

0 comments on commit 81816de

Please sign in to comment.