Skip to content
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

MagicCallPatch: prevent deprecation notice #628

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 12 additions & 3 deletions src/Prophecy/Doubler/ClassPatch/MagicCallPatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,18 @@ public function apply(ClassNode $node)

// only magic methods can have a contract that needs to be enforced
if (in_array($methodName, self::MAGIC_METHODS_WITH_ARGUMENTS)) {
foreach($tag->getArguments() as $argument) {
$argumentNode = new ArgumentNode($argument['name']);
$methodNode->addArgument($argumentNode);
if (method_exists($tag, 'getParameters')) {
// Reflection Docblock 5.4.0+.
foreach($tag->getParameters() as $argument) {
$argumentNode = new ArgumentNode($argument->getName());
$methodNode->addArgument($argumentNode);
}
} else {
// Reflection Docblock < 5.4.0.
foreach($tag->getArguments() as $argument) {
$argumentNode = new ArgumentNode($argument['name']);
$methodNode->addArgument($argumentNode);
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion tests/Doubler/ClassPatch/MagicCallPatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ public function it_supports_arguments_for_magic_methods()

$classNode = $this->applyPatchTo($class);

$this->assertEquals([new ArgumentNode('data')], $classNode->getMethod('__unserialize')->getArguments());
$method = $classNode->getMethod('__unserialize');
if (method_exists($method, 'getParameters')) {
// Reflection Docblock 5.4.0+.
$args = $method->getParameters();
} else {
// Reflection Docblock < 5.4.0.
$args = $method->getArguments();
}

$this->assertEquals([new ArgumentNode('data')], $args);
}

private function applyPatchTo(\ReflectionClass $class): ClassNode
Expand Down
Loading