public function testAliasExtendPropagation() { $container = new Container(); // extend first,, $container->extend('xml.other.alias', function ($item) { $item->contents = 'alias contents'; return $item; }); $container->instance('xml', $renderer = new ExtendTestXmlRenderer()); $container->alias('xml.alias', 'xml'); $container->alias('xml.other.alias', 'xml.alias'); static::assertEquals('alias contents', $container['xml']->contents); // and equal :-) static::assertSame($renderer, $container['xml.other.alias']); }
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()); } }