public function testLazyNotification() { // register main types as singletons $this->container->define('WeakPunch'); $this->container->define('PunchListener'); // create lazy callable $this->object->attach('event', array('lazy', 'PunchListener', 'handle')); // WeakPunch is singleton, requires instantiation through container, // which returns the same instance in LazyEventEmitter::getListeners('event') // as here: $punchable = $this->container->getInstanceOf('WeakPunch'); $this->assertFalse($punchable->wasPunched); // let the wheel spinning $this->object->notify(new Event($this, 'event')); $this->assertTrue($punchable->wasPunched); }
public function testMerge() { $this->object->define('MediumPunch'); $punch = $this->object->getInstanceOf('MediumPunch'); $this->assertThat($punch, $this->isInstanceOf('MediumPunch')); $container = new DependencyInjectionContainer(); $container->define('MediumPunch')->setClass('StrongPunch'); $punch = $container->getInstanceOf('MediumPunch'); $this->assertThat($punch, $this->isInstanceOf('StrongPunch')); $this->object->merge($container); $punch = $this->object->getInstanceOf('MediumPunch'); $this->assertThat($punch, $this->isInstanceOf('StrongPunch')); }
public function testCyclicInstantiation() { $this->setExpectedException('CyclicInstantiationException'); $this->container->define('Cyclic'); $instance = $this->container->getInstanceOf('Cyclic'); }