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

Fix mocking classes with new initializers in method and attribute params on PHP 8.1 #1301

Merged

Conversation

ghostwriter
Copy link
Member

@ghostwriter ghostwriter commented Jul 17, 2023

Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
@ghostwriter ghostwriter added Bug An error or unexpected behavior. Patch Backwards compatible bug fixes and improvements Fixed for bug fixes or error corrections labels Jul 17, 2023
@ghostwriter ghostwriter added this to the 1.6.3 milestone Jul 17, 2023
@ghostwriter ghostwriter self-assigned this Jul 17, 2023
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
@ghostwriter ghostwriter marked this pull request as ready for review July 17, 2023 23:24
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
@ghostwriter ghostwriter changed the title Fix mock classes with new in methods on PHP 8.1 Fix mocking classes with new initializers in method and attribute params on PHP 8.1 Jul 18, 2023
@ghostwriter ghostwriter merged commit 5a4410e into 1.6.x Jul 18, 2023
19 checks passed
@ghostwriter ghostwriter deleted the bugfix/1300-mock-classes-with-new-in-methods-on-php-81 branch July 18, 2023 00:02
@ghostwriter ghostwriter added the Changelog what's changed label Jul 18, 2023
@ghostwriter ghostwriter mentioned this pull request Jul 18, 2023
// "Parameter #1 [ <optional> F\Q\CN $a = new \F\Q\CN(param1, param2: 2) ]
preg_match(
'#<optional>\s.*?\s=\snew\s(.*?)\s]$#',
$param->__toString(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not intended to ever call __toString() directly. This should be a cast instead ((string)$param).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bilge I agree,

However the reason for using __toString() instead was because $param is actually an object that is proxying these calls via __call method to the ReflectionParameter which was giving an error because the __toString expects a string return type.

public function __call($method, array $args)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug An error or unexpected behavior. Changelog what's changed Fixed for bug fixes or error corrections Patch Backwards compatible bug fixes and improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mock classes with new in methods on PHP 8.1
2 participants