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

Remove calls to getMockForAbstractClass() #54745

Open
wants to merge 1 commit into
base: 5.4
Choose a base branch
from

Conversation

alexandre-daubois
Copy link
Contributor

@alexandre-daubois alexandre-daubois commented Apr 26, 2024

Q A
Branch? 5.4
Bug fix? no
New feature? no
Deprecations? no
Issues -
License MIT

This method is deprecated (see sebastianbergmann/phpunit#5241), and must be replaced where used.

@carsonbot carsonbot added this to the 5.4 milestone Apr 26, 2024
@alexandre-daubois alexandre-daubois changed the title [Config] Remove calls to getMockForAbstractClass() Remove calls to getMockForAbstractClass() Apr 26, 2024
@alexandre-daubois alexandre-daubois force-pushed the phpunit-deprecs branch 2 times, most recently from cab3b78 to 418acf7 Compare April 26, 2024 09:58
@alexandre-daubois alexandre-daubois force-pushed the phpunit-deprecs branch 6 times, most recently from 7e24f2d to 0aee22d Compare April 26, 2024 13:02
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

Thanks. Just one failure on deps=low.

@alexandre-daubois alexandre-daubois force-pushed the phpunit-deprecs branch 2 times, most recently from 86796a8 to 11a767b Compare April 30, 2024 14:28
$bundle = $this
->getMockBuilder(BundleInterface::class)
->getMockBuilder(\get_class($bundle))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
->getMockBuilder(\get_class($bundle))
->getMockBuilder($className ?? \get_class($bundle))

Can't we use this and remove the if below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it throws:

Capture d’écran 2024-04-30 à 16 41 48

However, I pushed a simpler way of creating the mock. Don't know why I didn't think about it before, but it's better now as we avoid creating 2 mocks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also I never played with setMockClassName, but it seems that using ?? would change the semantic and the mock wouldn't implement BundleInterface anymore. We need to implement BundleInterface, which is done with getMockBuilder. Then setMockClassName would rename the mock but keep BundleInterface as the mock parent.

Not sure I'm super clear here 😄

@carsonbot carsonbot changed the title Remove calls to getMockForAbstractClass() [Config] Remove calls to getMockForAbstractClass() May 2, 2024
@xabbuh
Copy link
Member

xabbuh commented May 2, 2024

@alexandre-daubois Can you rebase please?

Comment on lines 44 to 57
protected function normalizeValue($value)
{
}

protected function mergeValues($leftSide, $rightSide)
{
}

protected function finalizeValue($value)
{
}
Copy link
Member

Choose a reason for hiding this comment

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

Those methods need to return something. Otherwise we won't be able to ad a return type after merging up.

Suggested change
protected function normalizeValue($value)
{
}
protected function mergeValues($leftSide, $rightSide)
{
}
protected function finalizeValue($value)
{
}
protected function normalizeValue($value)
{
return null;
}
protected function mergeValues($leftSide, $rightSide)
{
return null;
}
protected function finalizeValue($value)
{
return null;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given that they return mixed, I think it would still work at up-merge without the return statement? I added return statement anyway, better be safe than sorry 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should also add return types to other anonymous classes, I'm on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Better now 👍

Copy link
Member

Choose a reason for hiding this comment

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

Given that they return mixed, I think it would still work at up-merge without the return statement?

Yes, but whoever does the merge-up will have to think less when doing so. 😅 Also, the diff is smaller.

@alexandre-daubois alexandre-daubois force-pushed the phpunit-deprecs branch 2 times, most recently from 237c3e9 to 2acf005 Compare May 2, 2024 12:12
@alexandre-daubois alexandre-daubois changed the title [Config] Remove calls to getMockForAbstractClass() [Remove calls to getMockForAbstractClass() May 2, 2024
@alexandre-daubois alexandre-daubois changed the title [Remove calls to getMockForAbstractClass() Remove calls to getMockForAbstractClass() May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants