10000 [DependencyInjection] Single typed argument can be applied on multiple parameters by sroze · Pull Request #24991 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DependencyInjection] Single typed argument can be applied on multiple parameters #24991

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
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Prove that change is working with tests
  • Loading branch information
sroze committed Nov 16, 2017
commit bf7eeef3fb3e2cd41df6cb4d2b0765cecfbeda36
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
use Symfony\Component\DependencyInjection\Tests\Fixtures\SimilarArgumentsDummy;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
Expand Down Expand Up @@ -125,6 E025 +126,32 @@ public function testTypedArgument()

$this->assertEquals(array(new Reference('foo'), '123'), $definition->getArguments());
}

public function testResolvesMultipleArgumentsOfTheSameType()
{
$container = new ContainerBuilder();

$definition = $container->register(SimilarArgumentsDummy::class, SimilarArgumentsDummy::class);
$definition->setArguments(array(CaseSensitiveClass::class => new Reference('foo'), '$token' => 'qwerty'));

$pass = new ResolveNamedArgumentsPass();
$pass->process($container);

$this->assertEquals(array(new Reference('foo'), 'qwerty', new Reference('foo')), $definition->getArguments());
}

public function testResolvePrioritizeNamedOverType()
{
$container = new ContainerBuilder();

$definition = $container->register(SimilarArgumentsDummy::class, SimilarArgumentsDummy::class);
$definition->setArguments(array(CaseSensitiveClass::class => new Reference('foo'), '$token' => 'qwerty', '$class1' => new Reference('bar')));

$pass = new ResolveNamedArgumentsPass();
$pass->process($container);

$this->assertEquals(array(new Reference('bar'), 'qwerty', new Reference('foo')), $definition->getArguments());
}
}

class NoConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Tests\Fixtures;

class SimilarArgumentsDummy
{
public function __construct(CaseSensitiveClass $class1, string $token, CaseSensitiveClass $class2)
{
}
}
0