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

Bug: system/Config/BaseService.php getSharedInstance() will not return mocks with non-lowercase key #2534

Closed
bivanbi opened this issue Feb 9, 2020 · 0 comments · Fixed by #2569
Assignees
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@bivanbi
Copy link
Contributor

bivanbi commented Feb 9, 2020

Direction
We use github issues to track bugs, not for support.
If you have a support question, or a feature request, raise these as threads on our
forum.

Describe the bug
system/Config/BaseService.php injectMock() method converts argument $name to lowercase,
but getSharedInstance() does not, which leads to BaseService not returning mocks with name containing uppercase letter.

CodeIgniter 4 version
4.0.0-rc.3,
Develop [checkout @ 2020.02.09 09:05]

Affected module(s)
CodeIgniter\Config\BaseService

Expected behavior, and steps to reproduce if appropriate
Steps to reproduce:

  1. create a pair of classes, e.g MyClass and MockMyClass

  2. add method to Config\Services, e.g.:

     public static function myClass(bool $getShared = true) {
         if ($getShared){ 
             return static::getSharedInstance('myClass')
         }
         return new MyClass();
     }
    
  3. Create a test case that injects MockMyClass

    class TestClass extends CIUnitTestCase {
         $mock = MockMyClass();
         Services::injectMock('myClass', $mock);
         $testObject = Services::myClass();
         $this-assertEquals(spl_object_id($mock), spl_object_id($testObject));
    }
    

Expected behaviour: Services should return instance of MockMyClass
Actual behaviour: Services returns new (shared) instance of MyClass

@bivanbi bivanbi added the bug Verified issues on the current code behavior or pull requests that will fix them label Feb 9, 2020
@MGatner MGatner self-assigned this Feb 16, 2020
MGatner added a commit to MGatner/CodeIgniter4 that referenced this issue Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants