Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
bug #39746 [DependencyInjection] Fix InvalidParameterTypeException fo…
…r function parameters (derrabus) This PR was merged into the 4.4 branch. Discussion ---------- [DependencyInjection] Fix InvalidParameterTypeException for function parameters | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #39737 | License | MIT | Doc PR | N/A Commits ------- 1854543 [DependencyInjection] Fix InvalidParameterTypeException for function parameters
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...mfony/Component/DependencyInjection/Tests/Exception/InvalidParameterTypeExceptionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?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\Exception; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\Exception\InvalidParameterTypeException; | ||
|
||
final class InvalidParameterTypeExceptionTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideReflectionParameters | ||
*/ | ||
public function testExceptionMessage(\ReflectionParameter $parameter, string $expectedMessage) | ||
{ | ||
$exception = new InvalidParameterTypeException('my_service', 'int', $parameter); | ||
|
||
self::assertSame($expectedMessage, $exception->getMessage()); | ||
} | ||
|
||
public function provideReflectionParameters(): iterable | ||
{ | ||
yield 'static method' => [ | ||
new \ReflectionParameter([MyClass::class, 'doSomething'], 0), | ||
'Invalid definition for service "my_service": argument 1 of "Symfony\Component\DependencyInjection\Tests\Exception\MyClass::doSomething()" accepts "array", "int" passed.', | ||
]; | ||
|
||
yield 'function' => [ | ||
new \ReflectionParameter(__NAMESPACE__.'\\myFunction', 0), | ||
'Invalid definition for service "my_service": argument 1 of "Symfony\Component\DependencyInjection\Tests\Exception\myFunction()" accepts "array", "int" passed.', | ||
]; | ||
} | ||
} | ||
|
||
class MyClass | ||
{ | ||
public static function doSomething(array $arguments): void | ||
{ | ||
} | ||
} | ||
|
||
function myFunction(array $arguments): void | ||
{ | ||
} |