Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Console] Use assertSame for input tests #58455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions src/Symfony/Component/Console/Tests/Input/ArgvInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ public function testConstructor()
$r = new \ReflectionObject($input);
$p = $r->getProperty('tokens');

$this->assertEquals(['foo'], $p->getValue($input), '__construct() automatically get its input from the argv server variable');
$this->assertSame(['foo'], $p->getValue($input), '__construct() automatically get its input from the argv server variable');
}

public function testParseArguments()
{
$input = new ArgvInput(['cli.php', 'foo']);
$input->bind(new InputDefinition([new InputArgument('name')]));
$this->assertEquals(['name' => 'foo'], $input->getArguments(), '->parse() parses required arguments');
$this->assertSame(['name' => 'foo'], $input->getArguments(), '->parse() parses required arguments');

$input->bind(new InputDefinition([new InputArgument('name')]));
$this->assertEquals(['name' => 'foo'], $input->getArguments(), '->parse() is stateless');
$this->assertSame(['name' => 'foo'], $input->getArguments(), '->parse() is stateless');
}

/**
Expand All @@ -57,7 +57,7 @@ public function testParseOptionsNegatable($input, $options, $expectedOptions, $m
{
$input = new ArgvInput($input);
$input->bind(new InputDefinition($options));
$this->assertEquals($expectedOptions, $input->getOptions(), $message);
$this->assertSame($expectedOptions, $input->getOptions(), $message);
}

public static function provideOptions()
Expand Down Expand Up @@ -363,19 +363,19 @@ public function testParseArrayArgument()
$input = new ArgvInput(['cli.php', 'foo', 'bar', 'baz', 'bat']);
$input->bind(new InputDefinition([new InputArgument('name', InputArgument::IS_ARRAY)]));

$this->assertEquals(['name' => ['foo', 'bar', 'baz', 'bat']], $input->getArguments(), '->parse() parses array arguments');
$this->assertSame(['name' => ['foo', 'bar', 'baz', 'bat']], $input->getArguments(), '->parse() parses array arguments');
}

public function testParseArrayOption()
{
$input = new ArgvInput(['cli.php', '--name=foo', '--name=bar', '--name=baz']);
$input->bind(new InputDefinition([new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY)]));

$this->assertEquals(['name' => ['foo', 'bar', 'baz']], $input->getOptions(), '->parse() parses array options ("--option=value" syntax)');
$this->assertSame(['name' => ['foo', 'bar', 'baz']], $input->getOptions(), '->parse() parses array options ("--option=value" syntax)');

$input = new ArgvInput(['cli.php', '--name', 'foo', '--name', 'bar', '--name', 'baz']);
$input->bind(new InputDefinition([new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY)]));
$this->assertEquals(['name' => ['foo', 'bar', 'baz']], $input->getOptions(), '->parse() parses array options ("--option value" syntax)');
$this->assertSame(['name' => ['foo', 'bar', 'baz']], $input->getOptions(), '->parse() parses array options ("--option value" syntax)');

$input = new ArgvInput(['cli.php', '--name=foo', '--name=bar', '--name=']);
$input->bind(new InputDefinition([new InputOption('name', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY)]));
Expand All @@ -393,20 +393,20 @@ public function testParseNegativeNumberAfterDoubleDash()
{
$input = new ArgvInput(['cli.php', '--', '-1']);
$input->bind(new InputDefinition([new InputArgument('number')]));
$this->assertEquals(['number' => '-1'], $input->getArguments(), '->parse() parses arguments with leading dashes as arguments after having encountered a double-dash sequence');
$this->assertSame(['number' => '-1'], $input->getArguments(), '->parse() parses arguments with leading dashes as arguments after having encountered a double-dash sequence');

$input = new ArgvInput(['cli.php', '-f', 'bar', '--', '-1']);
$input->bind(new InputDefinition([new InputArgument('number'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)]));
$this->assertEquals(['foo' => 'bar'], $input->getOptions(), '->parse() parses arguments with leading dashes as options before having encountered a double-dash sequence');
$this->assertEquals(['number' => '-1'], $input->getArguments(), '->parse() parses arguments with leading dashes as arguments after having encountered a double-dash sequence');
$this->assertSame(['foo' => 'bar'], $input->getOptions(), '->parse() parses arguments with leading dashes as options before having encountered a double-dash sequence');
$this->assertSame(['number' => '-1'], $input->getArguments(), '->parse() parses arguments with leading dashes as arguments after having encountered a double-dash sequence');
}

public function testParseEmptyStringArgument()
{
$input = new ArgvInput(['cli.php', '-f', 'bar', '']);
$input->bind(new InputDefinition([new InputArgument('empty'), new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL)]));

$this->assertEquals(['empty' => ''], $input->getArguments(), '->parse() parses empty string arguments');
$this->assertSame(['empty' => ''], $input->getArguments(), '->parse() parses empty string arguments');
}

public function testGetFirstArgument()
Expand All @@ -415,7 +415,7 @@ public function testGetFirstArgument()
$this->assertNull($input->getFirstArgument(), '->getFirstArgument() returns null when there is no arguments');

$input = new ArgvInput(['cli.php', '-fbbar', 'foo']);
$this->assertEquals('foo', $input->getFirstArgument(), '->getFirstArgument() returns the first argument from the raw input');
$this->assertSame('foo', $input->getFirstArgument(), '->getFirstArgument() returns the first argument from the raw input');

$input = new ArgvInput(['cli.php', '--foo', 'fooval', 'bar']);
$input->bind(new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('arg')]));
Expand Down Expand Up @@ -495,18 +495,18 @@ public function testNoWarningOnInvalidParameterOption()
// No warning thrown
$this->assertFalse($input->hasParameterOption(['-m', '']));

$this->assertEquals('dev', $input->getParameterOption(['-e', '']));
$this->assertSame('dev', $input->getParameterOption(['-e', '']));
// No warning thrown
$this->assertFalse($input->getParameterOption(['-m', '']));
}

public function testToString()
{
$input = new ArgvInput(['cli.php', '-f', 'foo']);
$this->assertEquals('-f foo', (string) $input);
$this->assertSame('-f foo', (string) $input);

$input = new ArgvInput(['cli.php', '-f', '--bar=foo', 'a b c d', "A\nB'C"]);
$this->assertEquals('-f --bar=foo '.escapeshellarg('a b c d').' '.escapeshellarg("A\nB'C"), (string) $input);
$this->assertSame('-f --bar=foo '.escapeshellarg('a b c d').' '.escapeshellarg("A\nB'C"), (string) $input);
}

/**
Expand All @@ -515,7 +515,7 @@ public function testToString()
public function testGetParameterOptionEqualSign($argv, $key, $default, $onlyParams, $expected)
{
$input = new ArgvInput($argv);
$this->assertEquals($expected, $input->getParameterOption($key, $default, $onlyParams), '->getParameterOption() returns the expected value');
$this->assertSame($expected, $input->getParameterOption($key, $default, $onlyParams), '->getParameterOption() returns the expected value');
}

public static function provideGetParameterOptionValues()
Expand All @@ -539,33 +539,33 @@ public function testParseSingleDashAsArgument()
{
$input = new ArgvInput(['cli.php', '-']);
$input->bind(new InputDefinition([new InputArgument('file')]));
$this->assertEquals(['file' => '-'], $input->getArguments(), '->parse() parses single dash as an argument');
$this->assertSame(['file' => '-'], $input->getArguments(), '->parse() parses single dash as an argument');
}

public function testParseOptionWithValueOptionalGivenEmptyAndRequiredArgument()
{
$input = new ArgvInput(['cli.php', '--foo=', 'bar']);
$input->bind(new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::REQUIRED)]));
$this->assertEquals(['foo' => null], $input->getOptions(), '->parse() parses optional options with empty value as null');
$this->assertEquals(['name' => 'bar'], $input->getArguments(), '->parse() parses required arguments');
$this->assertSame(['foo' => ''], $input->getOptions(), '->parse() parses optional options with empty value as null');
$this->assertSame(['name' => 'bar'], $input->getArguments(), '->parse() parses required arguments');

$input = new ArgvInput(['cli.php', '--foo=0', 'bar']);
$input->bind(new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::REQUIRED)]));
$this->assertEquals(['foo' => '0'], $input->getOptions(), '->parse() parses optional options with empty value as null');
$this->assertEquals(['name' => 'bar'], $input->getArguments(), '->parse() parses required arguments');
$this->assertSame(['foo' => '0'], $input->getOptions(), '->parse() parses optional options with empty value as null');
$this->assertSame(['name' => 'bar'], $input->getArguments(), '->parse() parses required arguments');
}

public function testParseOptionWithValueOptionalGivenEmptyAndOptionalArgument()
{
$input = new ArgvInput(['cli.php', '--foo=', 'bar']);
$input->bind(new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::OPTIONAL)]));
$this->assertEquals(['foo' => null], $input->getOptions(), '->parse() parses optional options with empty value as null');
$this->assertEquals(['name' => 'bar'], $input->getArguments(), '->parse() parses optional arguments');
$this->assertSame(['foo' => ''], $input->getOptions(), '->parse() parses optional options with empty value as null');
$this->assertSame(['name' => 'bar'], $input->getArguments(), '->parse() parses optional arguments');

$input = new ArgvInput(['cli.php', '--foo=0', 'bar']);
$input->bind(new InputDefinition([new InputOption('foo', 'f', InputOption::VALUE_OPTIONAL), new InputArgument('name', InputArgument::OPTIONAL)]));
$this->assertEquals(['foo' => '0'], $input->getOptions(), '->parse() parses optional options with empty value as null');
$this->assertEquals(['name' => 'bar'], $input->getArguments(), '->parse() parses optional arguments');
$this->assertSame(['foo' => '0'], $input->getOptions(), '->parse() parses optional options with empty value as null');
$this->assertSame(['name' => 'bar'], $input->getArguments(), '->parse() parses optional arguments');
}

public function testGetRawTokensFalse()
Expand Down
20 changes: 10 additions & 10 deletions src/Symfony/Component/Console/Tests/Input/ArrayInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function testGetFirstArgument()
$input = new ArrayInput([]);
$this->assertNull($input->getFirstArgument(), '->getFirstArgument() returns null if no argument were passed');
$input = new ArrayInput(['name' => 'Fabien']);
$this->assertEquals('Fabien', $input->getFirstArgument(), '->getFirstArgument() returns the first passed argument');
$this->assertSame('Fabien', $input->getFirstArgument(), '->getFirstArgument() returns the first passed argument');
$input = new ArrayInput(['--foo' => 'bar', 'name' => 'Fabien']);
$this->assertEquals('Fabien', $input->getFirstArgument(), '->getFirstArgument() returns the first passed argument');
$this->assertSame('Fabien', $input->getFirstArgument(), '->getFirstArgument() returns the first passed argument');
}

public function testHasParameterOption()
Expand All @@ -46,22 +46,22 @@ public function testHasParameterOption()
public function testGetParameterOption()
{
$input = new ArrayInput(['name' => 'Fabien', '--foo' => 'bar']);
$this->assertEquals('bar', $input->getParameterOption('--foo'), '->getParameterOption() returns the option of specified name');
$this->assertEquals('default', $input->getParameterOption('--bar', 'default'), '->getParameterOption() returns the default value if an option is not present in the passed parameters');
$this->assertSame('bar', $input->getParameterOption('--foo'), '->getParameterOption() returns the option of specified name');
$this->assertSame('default', $input->getParameterOption('--bar', 'default'), '->getParameterOption() returns the default value if an option is not present in the passed parameters');

$input = new ArrayInput(['Fabien', '--foo' => 'bar']);
$this->assertEquals('bar', $input->getParameterOption('--foo'), '->getParameterOption() returns the option of specified name');
$this->assertSame('bar', $input->getParameterOption('--foo'), '->getParameterOption() returns the option of specified name');

$input = new ArrayInput(['--foo', '--', '--bar' => 'woop']);
$this->assertEquals('woop', $input->getParameterOption('--bar'), '->getParameterOption() returns the correct value if an option is present in the passed parameters');
$this->assertEquals('default', $input->getParameterOption('--bar', 'default', true), '->getParameterOption() returns the default value if an option is present in the passed parameters after an end of options signal');
$this->assertSame('woop', $input->getParameterOption('--bar'), '->getParameterOption() returns the correct value if an option is present in the passed parameters');
$this->assertSame('default', $input->getParameterOption('--bar', 'default', true), '->getParameterOption() returns the default value if an option is present in the passed parameters after an end of options signal');
}

public function testParseArguments()
{
$input = new ArrayInput(['name' => 'foo'], new InputDefinition([new InputArgument('name')]));

$this->assertEquals(['name' => 'foo'], $input->getArguments(), '->parse() parses required arguments');
$this->assertSame(['name' => 'foo'], $input->getArguments(), '->parse() parses required arguments');
}

/**
Expand All @@ -71,7 +71,7 @@ public function testParseOptions($input, $options, $expectedOptions, $message)
{
$input = new ArrayInput($input, new InputDefinition($options));

$this->assertEquals($expectedOptions, $input->getOptions(), $message);
$this->assertSame($expectedOptions, $input->getOptions(), $message);
}

public static function provideOptions(): array
Expand Down Expand Up @@ -162,7 +162,7 @@ public static function provideInvalidInput(): array
public function testToString()
{
$input = new ArrayInput(['-f' => null, '-b' => 'bar', '--foo' => 'b a z', '--lala' => null, 'test' => 'Foo', 'test2' => "A\nB'C"]);
$this->assertEquals('-f -b bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input);
$this->assertSame('-f -b bar --foo='.escapeshellarg('b a z').' --lala Foo '.escapeshellarg("A\nB'C"), (string) $input);

$input = new ArrayInput(['-b' => ['bval_1', 'bval_2'], '--f' => ['fval_1', 'fval_2']]);
$this->assertSame('-b bval_1 -b bval_2 --f=fval_1 --f=fval_2', (string) $input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class InputArgumentTest extends TestCase
public function testConstructor()
{
$argument = new InputArgument('foo');
$this->assertEquals('foo', $argument->getName(), '__construct() takes a name as its first argument');
$this->assertSame('foo', $argument->getName(), '__construct() takes a name as its first argument');
}

public function testModes()
Expand Down Expand Up @@ -62,13 +62,13 @@ public function testIsArray()
public function testGetDescription()
{
$argument = new InputArgument('foo', null, 'Some description');
$this->assertEquals('Some description', $argument->getDescription(), '->getDescription() return the message description');
$this->assertSame('Some description', $argument->getDescription(), '->getDescription() return the message description');
}

public function testGetDefault()
{
$argument = new InputArgument('foo', InputArgument::OPTIONAL, '', 'default');
$this->assertEquals('default', $argument->getDefault(), '->getDefault() return the default value');
$this->assertSame('default', $argument->getDefault(), '->getDefault() return the default value');
}

public function testSetDefault()
Expand All @@ -77,11 +77,11 @@ public function testSetDefault()
$argument->setDefault(null);
$this->assertNull($argument->getDefault(), '->setDefault() can reset the default value by passing null');
$argument->setDefault('another');
$this->assertEquals('another', $argument->getDefault(), '->setDefault() changes the default value');
$this->assertSame('another', $argument->getDefault(), '->setDefault() changes the default value');

$argument = new InputArgument('foo', InputArgument::OPTIONAL | InputArgument::IS_ARRAY);
$argument->setDefault([1, 2]);
$this->assertEquals([1, 2], $argument->getDefault(), '->setDefault() changes the default value');
$this->assertSame([1, 2], $argument->getDefault(), '->setDefault() changes the default value');
}

public function testSetDefaultWithRequiredArgument()
Expand Down
Loading