예제 #1
0
 function testComponensRegisteredWithClassKeyTakePrecedenceOverOthersWhenThereAreMultipleImplementations()
 {
     $pico = new DefaultPicoContainer();
     $pico->regComponentImpl('AlternativeTouchable');
     $pico->regComponentImpl('Touchable', 'SimpleTouchable');
     $this->assertNotNull($pico->getComponentInstanceOfType('Touchable'));
 }
 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');
 }
예제 #3
0
 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 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();
     }
 }
 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');
 }
예제 #6
0
 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();
     }
 }
예제 #7
0
 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 testNonObjectRegisterInstance()
 {
     $pico = new DefaultPicoContainer();
     $pass = false;
     try {
         $pico->regComponentInstance('string');
     } catch (PicoRegistrationException $e) {
         $pass = true;
     }
     $this->assertTrue($pass, 'Caught exception');
 }
 function testGetAdapterWithTypeWhereTypeIsSubclass()
 {
     $pico = new DefaultPicoContainer();
     $pico->registerComponentImplementation('DerivedTouchable');
     $pico->registerComponentImplementation('DependsOnSimpleTouchable');
     $this->assertNotNull($pico->getComponentInstance('DependsOnSimpleTouchable'));
 }