How to functionally test the console command input validator
I want to functionally test Symfony command
I am building. I am using a helper class Question
by linking a personal validator
:
$helper = $this->getHelper('question');
$question = new Question('Enter a valid IP: ');
$question->setValidator($domainValidator);
$question->setMaxAttempts(2);
those tests I am running are functional, so to mock the interoperability I added something like the following to my PHPUnit test class. Here's an excerpt:
public function testBadIpRaisesError()
{
$question = $this->createMock('Symfony\Component\Console\Helper\QuestionHelper');
$question
->method('ask')
->will($this->onConsecutiveCalls(
'<IP>',
true
));
...
}
protected function createMock($originalClassName)
{
return $this->getMockBuilder($originalClassName)
->disableOriginalConstructor()
->disableOriginalClone()
->disableArgumentCloning()
->disallowMockingUnknownTypes()
->getMock();
}
Of course, this mock is more than okay when I'm testing something that is outside the scope of the helper Question
, but in this case what I would like to do is test everything to make sure the validator is well written.
What's the best option in this case? Unit testing my validator is ok, but I would like to functionally test it as a black box from a user perspective
source to share
No one has answered this question yet
Check out similar questions: