1
0
Fork 0

Add types to `Question` tests (#10219)

pull/10224/head
Martin Herndl 2021-10-26 21:17:28 +02:00 committed by GitHub
parent f19d01ef92
commit 3d5a100018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 1 deletions

View File

@ -26,6 +26,11 @@ use Symfony\Component\Console\Output\StreamOutput;
*/ */
class StrictConfirmationQuestionTest extends TestCase class StrictConfirmationQuestionTest extends TestCase
{ {
/**
* @return string[][]
*
* @phpstan-return list<array{non-empty-string}>
*/
public function getAskConfirmationBadData() public function getAskConfirmationBadData()
{ {
return array( return array(
@ -37,7 +42,9 @@ class StrictConfirmationQuestionTest extends TestCase
} }
/** /**
* @dataProvider getAskConfirmationBadData * @dataProvider getAskConfirmationBadData
*
* @param string $answer
*/ */
public function testAskConfirmationBadAnswer($answer) public function testAskConfirmationBadAnswer($answer)
{ {
@ -52,6 +59,10 @@ class StrictConfirmationQuestionTest extends TestCase
/** /**
* @dataProvider getAskConfirmationData * @dataProvider getAskConfirmationData
*
* @param string $question
* @param bool $expected
* @param bool $default
*/ */
public function testAskConfirmation($question, $expected, $default = true) public function testAskConfirmation($question, $expected, $default = true)
{ {
@ -61,6 +72,11 @@ class StrictConfirmationQuestionTest extends TestCase
$this->assertEquals($expected, $dialog->ask($input, $this->createOutputInterface(), $question), 'confirmation question should '.($expected ? 'pass' : 'cancel')); $this->assertEquals($expected, $dialog->ask($input, $this->createOutputInterface(), $question), 'confirmation question should '.($expected ? 'pass' : 'cancel'));
} }
/**
* @return mixed[][]
*
* @phpstan-return list<array{string, bool}>|list<array{string, bool, bool}>
*/
public function getAskConfirmationData() public function getAskConfirmationData()
{ {
return array( return array(
@ -84,20 +100,37 @@ class StrictConfirmationQuestionTest extends TestCase
$this->assertFalse($dialog->ask($input, $this->createOutputInterface(), $question)); $this->assertFalse($dialog->ask($input, $this->createOutputInterface(), $question));
} }
/**
* @param string $input
*
* @return resource
*/
protected function getInputStream($input) protected function getInputStream($input)
{ {
$stream = fopen('php://memory', 'r+', false); $stream = fopen('php://memory', 'r+', false);
$this->assertNotFalse($stream);
fwrite($stream, $input); fwrite($stream, $input);
rewind($stream); rewind($stream);
return $stream; return $stream;
} }
/**
* @return StreamOutput
*/
protected function createOutputInterface() protected function createOutputInterface()
{ {
return new StreamOutput(fopen('php://memory', 'r+', false)); return new StreamOutput(fopen('php://memory', 'r+', false));
} }
/**
* @param string $entry
*
* @return object[]
*
* @phpstan-return array{ArrayInput, QuestionHelper}
*/
protected function createInput($entry) protected function createInput($entry)
{ {
$stream = $this->getInputStream($entry); $stream = $this->getInputStream($entry);