Skip to content

Commit

Permalink
BaseService - Use lowercase key in resetSingle
Browse files Browse the repository at this point in the history
  • Loading branch information
najdanovicivan committed Jan 21, 2022
1 parent 812af1e commit 98b03ba
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/Config/BaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public static function reset(bool $initAutoloader = false)
*/
public static function resetSingle(string $name)
{
unset(static::$mocks[$name], static::$instances[$name]);
unset(static::$mocks[strtolower($name)], static::$instances[strtolower($name)]);
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/_support/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use CodeIgniter\HTTP\URI;
use Config\Services as BaseServices;
use RuntimeException;
use stdClass;

/**
* Services Class
Expand Down Expand Up @@ -43,4 +44,20 @@ public static function uri(?string $uri = null, bool $getShared = true)

return new URI($uri);
}

/**
* The URI class provides a way to model and manipulate URIs.
*
* @param mixed $getShared
*
* @return stdClass
*/
public static function someService($getShared = true)
{
if ($getShared) {
return static::getSharedInstance('someService');
}

return new stdClass();
}
}
11 changes: 11 additions & 0 deletions tests/system/Config/ServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,17 @@ public function testResetSingle()
$this->assertSame($security, $security2);
}

public function testResetSingleCaseInsensitive()
{
Services::injectMock('someService', new App());
$someService = service('someService');
$this->assertInstanceOf(App::class, $someService);

Services::resetSingle('someService');
$someService = service('someService');
$this->assertNotInstanceOf(App::class, $someService);
}

public function testFilters()
{
$result = Services::filters();
Expand Down

0 comments on commit 98b03ba

Please sign in to comment.