-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Serializer] Save missing arguments class in MissingConstructorArgume…
…ntsException
- Loading branch information
Showing
6 changed files
with
110 additions
and
6 deletions.
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
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
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
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
60 changes: 60 additions & 0 deletions
60
...Symfony/Component/Serializer/Tests/Exception/MissingConstructorArgumentsExceptionTest.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,60 @@ | ||
<?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\Serializer\Tests\Exception; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; | ||
use Symfony\Component\Serializer\Exception\MissingConstructorArgumentsException; | ||
|
||
/** | ||
* @group legacy | ||
*/ | ||
class MissingConstructorArgumentsExceptionTest extends TestCase | ||
{ | ||
use ExpectDeprecationTrait; | ||
|
||
/** | ||
* @dataProvider provideValidArguments | ||
*/ | ||
public function testValidArguments( | ||
array|string|null $class, | ||
?string $missingArgument, | ||
?string $expectedClass, | ||
?string $expectedMissingArgument, | ||
array $expectedMissingConstructorArguments, | ||
) { | ||
if (\is_array($class)) { | ||
$this->expectDeprecation(sprintf('Since symfony/serializer 6.3: Passing an array of missing arguments as the fourth argument of the "%s" constructor is deprecated, pass the missing arguments class name instead and the missing arguments name as the fifth argument.', MissingConstructorArgumentsException::class)); | ||
} | ||
|
||
$exception = new MissingConstructorArgumentsException('', 0, null, $class, $missingArgument); | ||
|
||
self::assertSame($expectedClass, $exception->getClass()); | ||
self::assertSame($expectedMissingArgument, $exception->getMissingArgument()); | ||
self::assertSame($expectedMissingConstructorArguments, $exception->getMissingConstructorArguments()); | ||
} | ||
|
||
public static function provideValidArguments(): iterable | ||
{ | ||
yield 'Without class and missingArgument' => [null, null, null, null, []]; | ||
yield 'With class and missingArgument' => ['Foo', 'bar', 'Foo', 'bar', ['bar']]; | ||
yield 'With missingArguments' => [['foo', 'bar'], null, null, 'foo', ['foo', 'bar']]; | ||
} | ||
|
||
public function testInvalidFourthArgument() | ||
{ | ||
$this->expectException(\TypeError::class); | ||
$this->expectExceptionMessage(sprintf('Argument 4 passed to "%s::__construct()" must be a string or null, "bool" given.', MissingConstructorArgumentsException::class)); | ||
|
||
new MissingConstructorArgumentsException('', 0, null, true); | ||
} | ||
} |
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