console-test
console-test copied to clipboard
more documentation for interactive commands
In this case, is 'kbond' what is typed in on the CLI when create:user is run? As opposed to being the arguments?
$this->executeConsoleCommand('create:user', ['kbond'])
->assertSuccessful()
->assertOutputContains('Creating regular user "kbond"')
;
I'm not sure how adding the --no-interaction works.
// advanced testing interactive commands
$this->consoleCommand(CreateUserCommand::class)
->addInput('kbond')
->addOption('--no-interaction') // commands are run interactively if input is provided, use this option to disable
->execute()
->assertSuccessful()
->assertOutputContains('Creating regular user "kbond"')
;
I guess I'm looking for a way to test interactive loops, like a command that asks for an email and role, throwing a message if the email already exists.
bin/console add:users
enter email>
[email protected]
new email! enter role>
ROLE_USER
@abc@def added with ROLE_USER
enter email>
[email protected]
new email! enter role>
ROLE_ADMIN
@xyz@def added with ROLE_ADMIN
enter email>
[email protected]
abc@def exists. enter role>
ROLE_ADMIN
abc@def updated to ROLE_ADMIN
enter email>
Success.
Agreed, this could be improved - I never write interactive commands so didn't fully think this part out.