public function testFrozen() { $container = new Container(); $container->instance('instance', 'instance string'); $container->closure('closure', function () { return 'closure string'; }); $container->alias('alias', 'closure'); // all change $container->instance('instance', 'instance string changed'); $container->closure('closure', function () { return 'closure string changed'; }); $container->alias('alias', 'instance'); // call, then it freeze all values. $container->get('instance'); $container->get('closure'); $container->get('alias'); // now cannot change try { $container->instance('instance', 'instance string changed 2'); static::fail(); } catch (CannotChangeException $exception) { static::assertEquals('It cannot be changed; instance', $exception->getMessage()); } try { $container->closure('closure', function () { return 'closure string change 2'; }); static::fail(); } catch (CannotChangeException $exception) { static::assertEquals('It cannot be changed; closure', $exception->getMessage()); } try { $container->alias('alias', 'closure'); static::fail(); } catch (CannotChangeException $exception) { static::assertEquals('It cannot be changed; alias', $exception->getMessage()); } // also cannot remove try { $container->offsetUnset('instance'); static::fail(); } catch (CannotChangeException $exception) { static::assertEquals('It cannot be changed; instance', $exception->getMessage()); } try { $container->offsetUnset('closure'); static::fail(); } catch (CannotChangeException $exception) { static::assertEquals('It cannot be changed; closure', $exception->getMessage()); } try { $container->offsetUnset('alias'); static::fail(); } catch (CannotChangeException $exception) { static::assertEquals('It cannot be changed; alias', $exception->getMessage()); } }