function testComponensRegisteredWithClassKeyTakePrecedenceOverOthersWhenThereAreMultipleImplementations()
 {
     $pico = new DefaultPicoContainer();
     $pico->regComponentImpl('AlternativeTouchable');
     $pico->regComponentImpl('Touchable', 'SimpleTouchable');
     $this->assertNotNull($pico->getComponentInstanceOfType('Touchable'));
 }
 public function testCollectiveTypeParameter()
 {
     $container = new DefaultPicoContainer();
     $container->regComponentImpl('TestClassForCollectiveTypeParameter1');
     $container->regComponentImpl('TestClassForCollectiveTypeParameter2');
     $container->regComponentImpl('AcceptsCollectiveTypeParameter', 'AcceptsCollectiveTypeParameter', array('collectiveTypeParameter' => new CollectiveTypeParameter('TestInterfaceForCollectiveTypeParameter')));
     $obj = $container->getComponentInstance('AcceptsCollectiveTypeParameter');
     $this->assertEqual(2, $obj->countObjectsInArray());
 }
 function testFailWithAmbiguousComponentResolutionException()
 {
     $pico = new DefaultPicoContainer();
     $pico->regComponentImpl('SimpleTouchable');
     $pico->regComponentImpl('DerivedTouchable');
     $pico->regComponentImpl('DependsOnTouchable');
     try {
         $pico->getComponentInstance('DependsOnTouchable');
         $this->fail();
     } catch (AmbiguousComponentResolutionException $e) {
         $this->pass();
     }
 }
 public function testResolvesInGrandParent()
 {
     $grandparent = new DefaultPicoContainer();
     $grandparent->regComponentImpl('SimpleTouchableAnyKey', 'SimpleTouchable');
     $parent = new DefaultPicoContainer(null, $grandparent);
     $child = new DefaultPicoContainer(null, $parent);
     $this->assertIsA($child->getComponentInstanceOfType('Touchable'), 'SimpleTouchable');
 }
 function testLIWithincludedDependencies()
 {
     $pico = new DefaultPicoContainer();
     $pico->regComponent(new LazyIncludingComponentAdapter(new ConstructorInjectionComponentAdapter('LazyIncludeModel'), PICOCONTAINER_TEST_PATH . '/lazyincludemodel.inc.php'));
     $pico->regComponentImpl('SimpleTouchable');
     $this->assertFalse(class_exists('LazyIncludeModel'));
     $ci = $pico->getComponentInstance('LazyIncludeModel');
     $this->assertIsA($ci, 'LazyIncludeModel');
 }
 function testNotThrowingReflectionExceptionWhenIteratingThroughtAllTheCA()
 {
     $pico = new DefaultPicoContainer();
     $pico->regComponentImpl('NotDefinedClass');
     $pico->regComponentImpl('st', 'SimpleTouchable');
     $pico->regComponentImpl('DependsOnTouchable');
     $pico->regComponentImpl('DependsOnSimpleTouchable');
     $cObj1 = $pico->getComponentInstance('DependsOnTouchable');
     $cObj2 = $pico->getComponentInstance('DependsOnSimpleTouchable');
     $this->assertNotNull($cObj1);
     $this->assertNotNull($cObj2);
 }
 function testGetAdapterWithTypeWhereTypeIsSubclass()
 {
     $pico = new DefaultPicoContainer();
     $pico->regComponentImpl('DerivedTouchable');
     $pico->regComponentImpl('DependsOnSimpleTouchable');
     $this->assertNotNull($pico->getComponentInstance('DependsOnSimpleTouchable'));
 }