Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Relax some mocks #22394

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 12, 2017
Merged

Relax some mocks #22394

merged 1 commit into from
Apr 12, 2017

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 3.2
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

We should not use mocks when it's not required - they too often run assertions on internal behavior.
These changes will unlock #22388

@@ -33,7 +33,6 @@ public function testThatCacheWarmersAreProcessedInPriorityOrder()
->will($this->returnValue($services));
$container->expects($this->atLeastOnce())
->method('getDefinition')
->with('cache_warmer')
Copy link
Member

Choose a reason for hiding this comment

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

this removal does not look right to me. We don't want to return the same Definition mock for unrelated services

Copy link
Member Author

Choose a reason for hiding this comment

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

does this losen the assertion of the test to you?
imho it's a "we shouldn't care" internal detail - dealing with it is not related to the business of this test case (same for other changes)

Copy link
Contributor

@jakzal jakzal Apr 12, 2017

Choose a reason for hiding this comment

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

Not sure what's your goal here Nicolas, but I'd rather replace ->expects($this->atLeastOnce()) with ->expects($this->any()) (use a stub instead of a mock). Removing the with() call seems wrong, as the test really should expect this particular service definition to be fetched from the container (as opposed to any definiton).

@@ -31,12 +32,16 @@ public function testServicesAreOrderedAccordingToPriority()
new Reference('n3'),
);

$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds'))->getMock();
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getDefinition'))->getMock();
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to mock the ContainerBuilder class in the first place? IMO, most of the times we can simply use a "real" ContainerBuilder object when writing tests for compiler passes.

Copy link
Member

@chalasr chalasr Apr 12, 2017

Choose a reason for hiding this comment

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

We don't, these tests use reflection to check that the private findAndSortTaggedServices is called, they could just register some services with the good tag in a concrete builder and check the services arguments/method calls after processing, which is the right thing to assert IMO as these passes just set arguments/calls on the collected services.

@nicolas-grekas
Copy link
Member Author

PR ready

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

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

👍 Be careful when merging this one, most of the tests updated here are legacy on 3.3 as passes have been moved to their components.

@fabpot
Copy link
Member

fabpot commented Apr 12, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 61be733 into symfony:3.2 Apr 12, 2017
fabpot added a commit that referenced this pull request Apr 12, 2017
This PR was merged into the 3.2 branch.

Discussion
----------

Relax some mocks

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

We should not use mocks when it's not required - they too often run assertions on internal behavior.
These changes will unlock #22388

Commits
-------

61be733 Relax some mocks
@nicolas-grekas nicolas-grekas deleted the fix-tests32 branch April 12, 2017 20:31
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.

7 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.