From cbdb9c4493e0008db6a03b7322a1385b1bf705fb Mon Sep 17 00:00:00 2001 From: Ruud Boon Date: Sat, 21 Sep 2019 20:07:56 +0200 Subject: [PATCH] Fixed remove() not removing service #14396 --- CHANGELOG-4.0.md | 1 + phalcon/Di.zep | 11 +++++++++-- tests/unit/Di/GetServicesCest.php | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG-4.0.md b/CHANGELOG-4.0.md index 252be960ffa..f0697ec7450 100644 --- a/CHANGELOG-4.0.md +++ b/CHANGELOG-4.0.md @@ -41,6 +41,7 @@ - Fixed `Phalcon/Db/Dialect/Mysql` Fixed missing schema in constraint for create table [#14378](https://github.com/phalcon/cphalcon/issues/14378) - Fixed `Phalcon\Mvc\Model::hasChanged()` and `getChangedFields()` returning false values when `castOnHydrate` option is on. [#14376](https://github.com/phalcon/cphalcon/issues/14376) - Fixed `Phalcon\Mvc\Model::create()` Using write connection to prevent replica lag [#14256](https://github.com/phalcon/cphalcon/issues/14256) +- Fixed `Phalcon\Di::remove()` Fixed remove() not removing service [#14396](https://github.com/phalcon/cphalcon/issues/14396) ## Removed - Removed `Phalcon\Plugin` - duplicate of `Phalcon\DI\Injectable` [#14359](https://github.com/phalcon/cphalcon/issues/14359) diff --git a/phalcon/Di.zep b/phalcon/Di.zep index 23b6ea14e84..ea197c9f434 100644 --- a/phalcon/Di.zep +++ b/phalcon/Di.zep @@ -512,8 +512,15 @@ class Di implements DiInterface */ public function remove(string! name) -> void { - unset this->services[name]; - unset this->sharedInstances[name]; + var services; + let services = this->services; + unset services[name]; + let this->services = services; + + var sharedInstances; + let sharedInstances = this->sharedInstances; + unset sharedInstances[name]; + let this->sharedInstances = sharedInstances; } /** diff --git a/tests/unit/Di/GetServicesCest.php b/tests/unit/Di/GetServicesCest.php index cf426d16736..e08d7d31f09 100644 --- a/tests/unit/Di/GetServicesCest.php +++ b/tests/unit/Di/GetServicesCest.php @@ -35,5 +35,12 @@ public function diGetServices(UnitTester $I) $di->set('escaper', Escaper::class); $I->assertCount(1, $di->getServices()); + + $di->remove('escaper'); + $I->assertFalse($di->has('escaper')); + $I->assertEquals([], $di->getServices()); + $I->assertEmpty($di->getServices()); + $I->assertTrue(is_array($di->getServices())); + $I->assertCount(0, $di->getServices()); } }