Skip to content

Commit 1eb603a

Browse files
authored
Merge pull request #3 from farzai:add-error-message
Add error message if leave target empty
2 parents 2aa675f + 2dcd9fe commit 1eb603a

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/Commands/CreateQrCode.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
3333
$input,
3434
$output
3535
);
36+
37+
if (! $target) {
38+
$output->writeln('Please enter receiver target., e.g. 0899999999');
39+
40+
return Command::FAILURE;
41+
}
3642
}
3743

3844
$lines = [

tests/CommandTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,25 @@
7070
EOF
7171
);
7272
});
73+
74+
it('should error when target is null after answer target with empty', function () {
75+
$application = new Application();
76+
$application->add(
77+
$command = new CreateQrCode()
78+
);
79+
$application->setAutoExit(false);
80+
81+
$tester = new ApplicationTester($application);
82+
83+
$tester->setInputs(['']);
84+
85+
$tester->run([
86+
'command' => $command->getName(),
87+
]);
88+
89+
expect($tester->getDisplay())->toContain(
90+
<<<'EOF'
91+
Please enter receiver target., e.g. 0899999999
92+
EOF
93+
);
94+
});

0 commit comments

Comments
 (0)