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

Fix build #1480

Merged
merged 2 commits into from
Jul 22, 2022
Merged

Fix build #1480

merged 2 commits into from
Jul 22, 2022

Conversation

jordisala1991
Copy link
Member

@jordisala1991 jordisala1991 commented Jul 21, 2022

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).

@jordisala1991 jordisala1991 marked this pull request as ready for review July 22, 2022 06:07
/**
* @testdox It is returning a block list.
*/
public function testLoadPageBlocks(): void
{
//Mock
$managerRegistryMock = $this->createMock(ManagerRegistry::class);
Copy link
Contributor

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 👀 .

Copy link
Member Author

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:

  1. 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.
  2. 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).
  3. You should avoid to mock what you don't own, there are a lot of articles about that.
  4. 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok I got it! :)

@jordisala1991 jordisala1991 merged commit 9feccef into sonata-project:4.x Jul 22, 2022
@jordisala1991 jordisala1991 deleted the hotfix/fix-build branch July 22, 2022 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants