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

Union type like "array|string|null" or "string|int|null" crashes Mockery #1105

Closed
LeSuisse opened this issue Dec 1, 2020 · 2 comments · Fixed by #1106
Closed

Union type like "array|string|null" or "string|int|null" crashes Mockery #1105

LeSuisse opened this issue Dec 1, 2020 · 2 comments · Fixed by #1106

Comments

@LeSuisse
Copy link
Contributor

LeSuisse commented Dec 1, 2020

The following code snippet crashes when the code generated by Mockery is evaluated.

class Foo {
    public function bar(array|string|null $v) {}
}

Mockery::mock(Foo::class);

In this situation, the generated code looks like this:

public function bar(array|string|null|null $v) {
    $argc = func_num_args();
    $argv = func_get_args();
    $ret = $this->_mockery_handleMethodCall(__FUNCTION__, $argv);
    return $ret;
}

I found this issue because of a mock of a class provided by a PHP extension, so I took a quick look at the other classes declared in my environment. At least the following classes are affected:

  • MultipleIterator::class
  • DOMXPath::class
  • IntlDateFormatter::class
  • Phar::class
  • PharData::class
  • SoapFault::class
  • SoapHeader::class
  • XSLTProcessor::class
  • ZipArchive::class

It seems the support introduced by #1088 needs to be improved a bit to manage this case. I will try to take a look later this week.

@GrahamCampbell
Copy link
Contributor

What version of mockery are you using?

@LeSuisse
Copy link
Contributor Author

LeSuisse commented Dec 1, 2020

1.4.2.
The issue can also be reproduced on the current main branch, see LeSuisse@d328ed6

@LeSuisse LeSuisse changed the title Union type like "array|string|null" or "" crashes Mockery Union type like "array|string|null" or "string|int|null" crashes Mockery Dec 1, 2020
LeSuisse added a commit to LeSuisse/mockery that referenced this issue Dec 6, 2020
This change prevents the generation of type hints with 2 "null".
For example, "string|array|null" should generate the code
"string|array|null" instead of "string|array|null|null" to avoid
a PHP fatal error "Duplicate type null is redundant".

Closes mockery#1105.
LeSuisse added a commit to LeSuisse/mockery that referenced this issue Dec 7, 2020
This change prevents the generation of type hints with 2 "null".
For example, "string|array|null" should generate the code
"string|array|null" instead of "string|array|null|null" to avoid
a PHP fatal error "Duplicate type null is redundant".

Closes mockery#1105.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants