Skip to content

DE-138979 Create DisallowMockeryShouldReceiveRule to disallow using MockInterface::shouldReceive() in favour of MockInterface::expects() - #107

Merged
dominikkaluza merged 4 commits into
masterfrom
DE-138979-mockery-expects-phpstan-rule
Aug 5, 2025
Merged

DE-138979 Create DisallowMockeryShouldReceiveRule to disallow using MockInterface::shouldReceive() in favour of MockInterface::expects()#107
dominikkaluza merged 4 commits into
masterfrom
DE-138979-mockery-expects-phpstan-rule

Conversation

@dominikkaluza

@dominikkaluza dominikkaluza commented Aug 5, 2025

Copy link
Copy Markdown
Collaborator

Create DisallowMockeryShouldReceiveRule to disallow using MockInterface::shouldReceive() in favour of MockInterface::expects(). shouldReceive doesn't enforce call count assertions, so then we find out we have tests like these in the codebase https://github.com/BrandEmbassy/channel-integrations/commit/b200ce77d07363c90ea83a67eeabab4796072cca. The expectations apply to only one of four test cases, but they were in setup because call count wasn't set up and everything was passing -> confusing.

We've agreed on this a long time ago here https://github.com/BrandEmbassy/developers-manifest/issues/631 but noone implemented the rule yet. This rule is just to forbid new occurrences. Next step could be to implement a Rector rule that transforms current usage.

There are also changes which fix phpunit runner. It's failing with the current configuration because of some constants conflicts.

Comment thread phpstan-extension.neon
Comment on lines +14 to +17
-
class: BrandEmbassyCodingStandard\PhpStan\Rules\Mockery\DisallowMockeryShouldReceiveRule
tags:
- phpstan.rules.rule

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I wasn't sure about enabling it by default, but it seems like the right call since we've accepted the devsync issue. Baseline should be regenerated and that's it.

@dominikkaluza
dominikkaluza force-pushed the DE-138979-mockery-expects-phpstan-rule branch from e529e49 to c83377f Compare August 5, 2025 08:45
@dominikkaluza

Copy link
Copy Markdown
Collaborator Author

@dominik-vasicek reviewed and approved but he's unable to do it through GitHub currently since he's locked out of his computer 😹

@dominikkaluza
dominikkaluza merged commit 67073ea into master Aug 5, 2025
9 checks passed
@dominikkaluza
dominikkaluza deleted the DE-138979-mockery-expects-phpstan-rule branch August 5, 2025 08:53
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.

2 participants