Skip to content

[Form] do not use mocks in tests when not necessary #46030

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

Merged
merged 1 commit into from
Apr 17, 2022

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Apr 13, 2022

Q A
Branch? 4.4
Bug fix? no
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

@xabbuh xabbuh added this to the 4.4 milestone Apr 13, 2022
@xabbuh xabbuh requested a review from yceruto as a code owner April 13, 2022 14:49
@carsonbot carsonbot changed the title [WIP][Form] do not use mocks in tests when not necessary [Form] [WIP] do not use mocks in tests when not necessary Apr 13, 2022
$this->assertSame($list, $this->factory->createListFromChoices([]));
$this->assertSame($list, $this->factory->createListFromChoices([]));
$this->assertEquals(new ArrayChoiceList([]), $this->factory->createListFromChoices([]));
$this->assertEquals(new ArrayChoiceList([]), $this->factory->createListFromChoices([]));
Copy link
Contributor

Choose a reason for hiding this comment

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

The caching factory should ensure the same instance of list is returned, this test does not assert the same thing anymore and allows regressions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would revert the changes in this test class.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have reworked the test to always check if the created lists are (not) the same explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Neat!

@HeahDude
Copy link
Contributor

This a great move, thanks ans good job!

@xabbuh xabbuh force-pushed the form-tests-mock branch 10 times, most recently from 9b0d1c4 to 07dd74b Compare April 16, 2022 09:40
@xabbuh xabbuh force-pushed the form-tests-mock branch 2 times, most recently from c3dadc8 to 0e4feb9 Compare April 16, 2022 10:09
@xabbuh xabbuh changed the title [Form] [WIP] do not use mocks in tests when not necessary [Form] do not use mocks in tests when not necessary Apr 16, 2022
@xabbuh
Copy link
Member Author

xabbuh commented Apr 16, 2022

I have finished the changes. The PR is ready to be reviewed.

Status: Needs Review

@xabbuh xabbuh force-pushed the form-tests-mock branch 2 times, most recently from 545ea5d to 0c75820 Compare April 16, 2022 11:22
Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

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

Except for some very minor comments/questions, looks very good 👍

$this->dataCollector->buildPreliminaryFormTree($form);
$this->dataCollector->collectSubmittedData($form);

$this->assertNotSame(
Copy link
Contributor

@HeahDude HeahDude Apr 17, 2022

Choose a reason for hiding this comment

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

Is there something we can expect here? assertNotSame with two arrays could mean anything and doesn't seem to bring any value.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just wanted to make sure, that there actually is any collected data so that calling reset() afterwards actually has an effect and that the following assertion isn't passing by luck.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, so what about something like assertGreaterThan(0, $this->dataCollector->getData()['forms'])?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm yeah, might make sense. I am going to send a follow-up PR later if you haven't done that in the meantime. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

see #46096

@xabbuh xabbuh merged commit aa54aff into symfony:4.4 Apr 17, 2022
@xabbuh xabbuh deleted the form-tests-mock branch April 17, 2022 10:32
chalasr added a commit that referenced this pull request Apr 18, 2022
…buh)

This PR was merged into the 5.4 branch.

Discussion
----------

[Form] do not use mocks in tests when not necessary

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

continuation of #46030 for 5.4+

Commits
-------

488a262 do not use mocks in tests when not necessary
xabbuh added a commit that referenced this pull request Apr 18, 2022
This PR was merged into the 4.4 branch.

Discussion
----------

[Form] improve an assertion

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | #46030 (comment)
| License       | MIT
| Doc PR        |

Commits
-------

a16b56d improve an assertion
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.

4 participants