function testCachingComponentAdapter()
 {
     $pico = new DefaultPicoContainer();
     $pico->registerComponent(new CachingComponentAdapter(new ConstructorInjectionComponentAdapter('Boy')));
     $boy1 = $pico->getComponentInstance('Boy');
     $boy2 = $pico->getComponentInstance('Boy');
     if ($boy1 !== $boy2) {
         $this->fail();
     } else {
         $this->pass();
     }
 }
 public function testResolvesInParentWhenNoComponentInTheActualContainer()
 {
     $parent = new DefaultPicoContainer();
     $parent->regComponentImpl('SimpleTouchable');
     $child = new DefaultPicoContainer(null, $parent);
     $this->assertIsA($child->getComponentInstance('SimpleTouchable'), 'SimpleTouchable');
 }
 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 testLIWithoutIncludedDependencies()
 {
     $pico = new DefaultPicoContainer();
     $pico->regComponent(new LazyIncludingComponentAdapter(new ConstructorInjectionComponentAdapter('LazyIncludeModelWithDpendencies'), PICOCONTAINER_TEST_PATH . '/lazyincludemodelwithdpendencies.inc.php'));
     $pico->regComponent(new LazyIncludingComponentAdapter(new ConstructorInjectionComponentAdapter('LazyIncludeModelDependend'), PICOCONTAINER_TEST_PATH . '/lazyincludemodeldependend.inc.php'));
     $this->assertFalse(class_exists('LazyIncludeModelWithDpendencies'));
     $this->assertFalse(class_exists('LazyIncludeModelDependend'));
     $ci = $pico->getComponentInstance('LazyIncludeModelWithDpendencies');
     $this->assertTrue(class_exists('LazyIncludeModelWithDpendencies'));
     $this->assertTrue(class_exists('LazyIncludeModelDependend'));
     $this->assertIsA($ci, 'LazyIncludeModelWithDpendencies');
 }
 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();
     }
 }
 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'));
 }