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

Document PHPUnit mocks with intersection types #9318

Merged
merged 1 commit into from Jan 2, 2022

Conversation

derrabus
Copy link
Member

@derrabus derrabus commented Jan 2, 2022

PHPUnit's createMock() will return an object that extends the mocked type and implements MockObject at the same time. The accurate way to document this is an intersection type, but we often document a union type instead. This declaration is too wide because virtally any mock object would pass it.

This might look nit-picking now, but it will become more important later when we try to infer native types from the docblock types in an automated manner.

@derrabus derrabus added this to the 2.10.5 milestone Jan 2, 2022
}

protected function addMockFilterCollection(EntityManagerInterface $em): FilterCollection
/**
* @psalm-param EntityManagerInterface&MockObject $em
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: I'm using @psalm-param instead of @param because CodeSniffer will do strange this otherwise, see squizlabs/PHP_CodeSniffer#2887.

Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

I think it was done that way because of PHPStorm being unhappy with it at some point, but yes, let's use intersection types 👍

@derrabus derrabus merged commit c456157 into doctrine:2.10.x Jan 2, 2022
@derrabus derrabus deleted the types/mock-intersection branch January 2, 2022 17:00
derrabus added a commit to derrabus/orm that referenced this pull request Jan 2, 2022
* 2.10.x:
  Run static analysis with language level PHP 8.1 (doctrine#9314)
  Document PHPUnit mocks with intersection types (doctrine#9318)
derrabus added a commit to derrabus/orm that referenced this pull request Jan 2, 2022
* 2.10.x:
  Run static analysis with language level PHP 8.1 (doctrine#9314)
  Document PHPUnit mocks with intersection types (doctrine#9318)
derrabus added a commit to derrabus/orm that referenced this pull request Jan 2, 2022
* 2.11.x:
  Run static analysis with language level PHP 8.1 (doctrine#9314)
  Document LockMode enums (doctrine#9319)
  Document PHPUnit mocks with intersection types (doctrine#9318)
  Run PHP CodeSniffer on PHP 8.1 (doctrine#9317)
  Psalm 4.17.0 (doctrine#9315)
  Run static analysis on PHP 8.1 (doctrine#9310)
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

2 participants