Skip to content

Loading…

Add option to emit a warning when non-existant classes/interfaces/methods are stubbed/mocked #12

Open
sebastianbergmann opened this Issue · 6 comments

6 participants

@sebastianbergmann

No description provided.

@igorw

+1

@edorian
Collaborator

I'd like to do something about this for 3.8.

One option would be to have a new method that only mocks existing things and one to create new stuff and do proper error reporting there "deprecating" getMock.

My suggestion for the new one would be mock.

So you'd say

$this->mock('foo');

another option would be to slap another parameter on getMock and make a MockBuilderFunction allowCreationOfNonExistingClasss or something.

Maybe even have a release that only has a warning telling you

"You are mocking a non existing class. This might be not what you wanted. If this is in intentional behavior please use the $allowNonExisting flag."

Having a new function would allow for more cleanup but require a lot more work/docs/etc

@bartfeenstra

What does the documentation say for stubbing/mocking things that don't already exist? Does it say "don't do this"? Because if that's so, we should be able to make 3.8 throw exceptions when this happens. If this breaks BC for people 1) they did something wrong in the first place and we just never told them until 3.8 2) they're tests anyway.

@whatthejeff
Collaborator

@bartfeenstra I don't think the documentation says anything about stubbing/mocking classes/interfaces/methods that don't exist.

@fabpot fabpot added a commit to silexphp/Silex that referenced this issue
@fabpot fabpot minor #967 remove not needed logger tests (1emming)
This PR was merged into the 2.0.x-dev branch.

Discussion
----------

remove not needed logger tests

The `isset` checks on `$app['logger']` make no sense since `Application` always sets the logger (to `null`). Checks for `!empty` would be more safe/complete (altough `!empty && instance_of('LoggerInterface')` would be more ideal in some cases).
Updating the unit tests is more complicated because some code under test depends on classes outside of Silex.
Hacking the `class_exists` function or use `mocking` of classes that do not exists (@see sebastianbergmann/phpunit-mock-objects#12) would effect the whole test suit (as @stof pointed out).

Commits
-------

784a246 remove not needed logger tests
d728358
@whatthejeff whatthejeff referenced this issue in sebastianbergmann/phpunit
Closed

Using method(...) with non-existent methods #1429

@rr-
rr- commented

:+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.