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

[1.3] Fix auto-generated return values with union types #1143

Merged
merged 1 commit into from Sep 13, 2021
Merged

[1.3] Fix auto-generated return values with union types #1143

merged 1 commit into from Sep 13, 2021

Conversation

GrahamCampbell
Copy link
Contributor

The logic is now:

  • if nullable or no return type, return null
  • otherwise, return a primitive if possible
  • otherwise, mock the first class in the type and return that

So, int|false will auto-return 0 and Foo|false will auto-return false. The old logic was very similar, but broken because it looked at the string int|false, decided it was not primitive, and then tried to mock it.


Before fix:

PHPUnit 9.5.9 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.0RC1
Configuration: /data/phpunit.xml.dist
Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

....................R...................W......................  63 / 615 ( 10%)
...................S....R.............R......................S. 126 / 615 ( 20%)
.........R...R....S....S.....................S................. 189 / 615 ( 30%)
............................................................... 252 / 615 ( 40%)
............................................................... 315 / 615 ( 51%)
............................................................... 378 / 615 ( 61%)
...................................................S........... 441 / 615 ( 71%)
.............................................................SS 504 / 615 ( 81%)
SSSS........................................................... 567 / 615 ( 92%)
.............................................PHP Fatal error:  Cannot use 'int' as class name as it is reserved in /tmp/Mockery6UM2gx on line 1

After fix:

PHPUnit 9.5.9 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.0RC1
Configuration: /data/phpunit.xml.dist
Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

....................R...................W......................  63 / 615 ( 10%)
...................S....R.............R......................S. 126 / 615 ( 20%)
.........R...R....S....S.....................S................. 189 / 615 ( 30%)
............................................................... 252 / 615 ( 40%)
............................................................... 315 / 615 ( 51%)
............................................................... 378 / 615 ( 61%)
...................................................S........... 441 / 615 ( 71%)
.............................................................SS 504 / 615 ( 81%)
SSSS........................................................... 567 / 615 ( 92%)
................................................                615 / 615 (100%)

Time: 00:01.497, Memory: 46.00 MB

Blocks laravel/framework#38404. cc @davedevelopment, @driesvints.

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 this pull request may close these issues.

None yet

2 participants