Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2cc0647

Browse filesBrowse files
committed
fix bug when checking builtin type matches class name
1 parent 3405b24 commit 2cc0647
Copy full SHA for 2cc0647

File tree

Expand file treeCollapse file tree

2 files changed

+33
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+33
-1
lines changed

‎src/Symfony/Component/DependencyInjection/Compiler/CheckTypeHintsPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/CheckTypeHintsPass.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,14 @@ private function checkTypeHint($configurationArgument, \ReflectionParameter $par
129129
if (!\is_a($class, $parameter->getType()->getName(), true)) {
130130
throw new InvalidParameterTypeHintException($this->currentId, $class, $parameter);
131131
}
132-
} else {
132+
} elseif ($parameter->getType()->isBuiltin()) {
133133
$checkFunction = 'is_'.$parameter->getType()->getName();
134134

135135
if (!$checkFunction($configurationArgument)) {
136136
throw new InvalidParameterTypeHintException($this->currentId, gettype($configurationArgument), $parameter);
137137
}
138+
} else {
139+
throw new InvalidParameterTypeHintException($this->currentId, gettype($configurationArgument), $parameter);
138140
}
139141
}
140142

‎src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeHintsPassTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/CheckTypeHintsPassTest.php
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,36 @@ public function testProcessSuccessScalarType()
199199
$this->assertInstanceOf(BarMethodCall::class, $container->get('bar'));
200200
}
201201

202+
/**
203+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
204+
* @expectedExceptionMessage In service declaration "bar". Trying to inject a "integer" as argument 0 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeHintsPass\Bar::__construct", but the type hint expects a "stdClass"
205+
*/
206+
public function testProcessFailsOnPassingScalarTypeToConstructorTypeHintedWithClass()
207+
{
208+
$container = new ContainerBuilder();
209+
210+
$container->register('bar', Bar::class)
211+
->addArgument(1);
212+
213+
(new CheckTypeHintsPass(true))->process($container);
214+
}
215+
216+
/**
217+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
218+
* @expectedExceptionMessage In service declaration "bar". Trying to inject a "string" as argument 0 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeHintsPass\BarMethodCall::setFoo", but the type hint expects a "stdClass"
219+
*/
220+
public function testProcessFailsOnPassingScalarTypeToMethodTypeHintedWithClass()
221+
{
222+
$container = new ContainerBuilder();
223+
224+
$container->register('bar', BarMethodCall::class)
225+
->addMethodCall('setFoo', array(
226+
'builtin type instead of class',
227+
));
228+
229+
(new CheckTypeHintsPass(true))->process($container);
230+
}
231+
202232
/**
203233
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
204234
* @expectedExceptionMessage In service declaration "bar". Trying to inject a "string" as argument 0 of "Symfony\Component\DependencyInjection\Tests\Fixtures\CheckTypeHintsPass\BarMethodCall::setScalars", but the type hint expects a "int"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.