-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Bug: mock single_service #4515
Comments
Mocked services only apply to shared instances, whereas
I'm not saying this is the most desirable behavior but whoever created Services built it this way, it is not a bug. |
Ok, thanks for your answer. I was unsure whether to label this as a bug or a feature request. My confusion stems from the documentation under Testing / Getting Started / Mocking Services, my understanding was that mocking would apply to all Services. |
I agree that mocking being for "shared only" is unintuitive and I would support such a feature request. If you wish to pursue this please post it on the forums (you can link it here) to gather feedback. I am curious whether the team would consider this a breaking change given that some developers may be using mocking with the understanding that it won't affect their new instances? |
Link to forum: |
Describe the bug
Cannot mock
single_service()
CodeIgniter 4 version
CI 4.1.1
Affected module(s)
system/Common.php ->
single_service()
system/Config/BaseService.php ->
serviceExists()
Expected behavior, and steps to reproduce if appropriate
When getting a service like this (shared instance):
$example = service('example');
Afterwards you can a mock this when testing with:
Services::injectMock('example', $example);
When getting a service like this (new instance):
$example = single_service('example');
Creating a mock when testing is not possible with:
Services::injectMock('example', $example);
The text was updated successfully, but these errors were encountered: