8000 [Messenger] Added check if json_encode succeeded by toooni · Pull Request #35137 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] Added check if json_encode succeeded #35137

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 9 commits into from
Jan 7, 2020
Merged
Prev Previous commit
Next Next commit
[DependencyInjection] Handle ServiceClosureArgument for callable in c…
…ontainer linting
  • Loading branch information
Douglas Greenshields authored and nicolas-grekas committed Jan 7, 2020
commit e48829e9b66dd80cd80d625cf9a9f91710133cce
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
Expand Down Expand Up @@ -219,6 +220,10 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
return;
}

if (\in_array($type, ['callable', 'Closure'], true) && $value instanceof ServiceClosureArgument) {
return;
}

if ('iterable' === $type && (\is_array($value) || $value instanceof \Traversable || $value instanceof IteratorArgument)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -697,4 +698,28 @@ public function testProcessHandleClosureForCallable()

$this->addToAssertionCount(1);
}

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

$container->register('bar', BarMethodCall::class)
->addMethodCall('setCallable', [new ServiceClosureArgument(new Reference('foo'))]);

(new CheckTypeDeclarationsPass(true))->process($container);

$this->addToAssertionCount(1);
}

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

$container->register('bar', BarMethodCall::class)
->addMethodCall('setClosure', [new ServiceClosureArgument(new Reference('foo'))]);

(new CheckTypeDeclarationsPass(true))->process($container);

$this->addToAssertionCount(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ public function setIterable(iterable $iterable)
public function setCallable(callable $callable): void
{
}

public function setClosure(\Closure $closure): void
{
}
}
0