-
-
Notifications
You must be signed in to change notification settings - Fork 208
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
Fix build #1480
Fix build #1480
Conversation
/** | ||
* @testdox It is returning a block list. | ||
*/ | ||
public function testLoadPageBlocks(): void | ||
{ | ||
//Mock | ||
$managerRegistryMock = $this->createMock(ManagerRegistry::class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you pass just a mock instead of the service? It should be just a unit test 👀 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we should not try to mock the orm. There are plenty of test doing it, and it is not a good practice.
There are some reasons for it:
- Mocking the orm just ensure you are calling a bunch of functions, and not if the queries / all the logic works and returns expected results.
- You are forced to mock some internals of the ORM due to final classes. I do not want to mock internal logic of classes because that is very fragile and it will break as soon as the internal class changes without BC break (and again it goes to the point 1 too).
- You should avoid to mock what you don't own, there are a lot of articles about that.
- The test is more complex to read with that mocking.
About doing a kernel test case on the Entity Folder, I do not see any problem about that, we usually don't split test by unit or integration folders. What we do is add a Functional folder for those test that do full application requests and check the generated html.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I got it! :)
Had to rewrite a test to use KernelTestCase...
We have a lot of test that mock too much things, we will need to take a look at that at some point (other priorities first).