1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-10 00:53:06 +00:00
This commit is contained in:
Jordi Boggiano 2022-08-17 15:20:07 +03:00 committed by GitHub
parent 6e205a0c84
commit 131da999ac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
357 changed files with 5943 additions and 9174 deletions

View file

@ -32,22 +32,20 @@ class StrictConfirmationQuestionTest extends TestCase
*/
public function getAskConfirmationBadData(): array
{
return array(
array('not correct'),
array('no more'),
array('yes please'),
array('yellow'),
);
return [
['not correct'],
['no more'],
['yes please'],
['yellow'],
];
}
/**
* @dataProvider getAskConfirmationBadData
*
* @param string $answer
*/
public function testAskConfirmationBadAnswer(string $answer): void
{
list($input, $dialog) = $this->createInput($answer."\n");
[$input, $dialog] = $this->createInput($answer."\n");
self::expectException('InvalidArgumentException');
self::expectExceptionMessage('Please answer yes, y, no, or n.');
@ -59,14 +57,10 @@ class StrictConfirmationQuestionTest extends TestCase
/**
* @dataProvider getAskConfirmationData
*
* @param string $question
* @param bool $expected
* @param bool $default
*/
public function testAskConfirmation(string $question, bool $expected, bool $default = true): void
{
list($input, $dialog) = $this->createInput($question."\n");
[$input, $dialog] = $this->createInput($question."\n");
$question = new StrictConfirmationQuestion('Do you like French fries?', $default);
$this->assertEquals($expected, $dialog->ask($input, $this->createOutputInterface(), $question), 'confirmation question should '.($expected ? 'pass' : 'cancel'));
@ -79,30 +73,28 @@ class StrictConfirmationQuestionTest extends TestCase
*/
public function getAskConfirmationData(): array
{
return array(
array('', true),
array('', false, false),
array('y', true),
array('yes', true),
array('n', false),
array('no', false),
);
return [
['', true],
['', false, false],
['y', true],
['yes', true],
['n', false],
['no', false],
];
}
public function testAskConfirmationWithCustomTrueAndFalseAnswer(): void
{
$question = new StrictConfirmationQuestion('Do you like French fries?', false, '/^ja$/i', '/^nein$/i');
list($input, $dialog) = $this->createInput("ja\n");
[$input, $dialog] = $this->createInput("ja\n");
$this->assertTrue($dialog->ask($input, $this->createOutputInterface(), $question));
list($input, $dialog) = $this->createInput("nein\n");
[$input, $dialog] = $this->createInput("nein\n");
$this->assertFalse($dialog->ask($input, $this->createOutputInterface(), $question));
}
/**
* @param string $input
*
* @return resource
*/
protected function getInputStream(string $input)
@ -116,28 +108,23 @@ class StrictConfirmationQuestionTest extends TestCase
return $stream;
}
/**
* @return StreamOutput
*/
protected function createOutputInterface(): StreamOutput
{
return new StreamOutput(fopen('php://memory', 'r+', false));
}
/**
* @param string $entry
*
* @return object[]
*
* @phpstan-return array{ArrayInput, QuestionHelper}
*/
protected function createInput(string $entry): array
{
$input = new ArrayInput(array('--no-interaction'));
$input = new ArrayInput(['--no-interaction']);
$input->setStream($this->getInputStream($entry));
$dialog = new QuestionHelper();
return array($input, $dialog);
return [$input, $dialog];
}
}