Example #1
0
 /**
  * @covers Phossa\Di\Container::setScope
  */
 public function testSetScope()
 {
     $this->object->add('AA')->setScope('@WOW@');
     $aa1 = $this->object->get('AA');
     $aa2 = $this->object->get('AA', [], 'AntherScope');
     $this->assertFalse($aa1 === $aa2);
     $aa3 = $this->object->get('AA', [], '@WOW@');
     $this->assertTrue($aa1 === $aa3);
 }
Example #2
0
 /**
  * test load services
  *
  * @covers Phossa\Di\Container::load
  */
 public function testLoadServices()
 {
     $this->object->setResolver(new Parameter($this->data));
     $call = function ($a) {
         return $a;
     };
     // id => [ callable(), arguments[] ]
     $service = ['services' => ['test' => [$call, ['${test1}']]]];
     $this->object->load($service);
     $this->assertTrue('x2' == $this->object->get('test'));
 }
Example #3
0
 /**
  * Resolve dependencies thru delegator
  *
  * @covers Phossa\Di\Extension\Delegate\Delegator::get
  * @covers Phossa\Di\Extension\Delegate\Delegator::has
  */
 public function testGet2()
 {
     include_once __DIR__ . '/testData1.php';
     include_once __DIR__ . '/testData2.php';
     include_once __DIR__ . '/testData3.php';
     $ct1 = new Container();
     $aa = $ct1->get('AA');
     // autowiring
     $ct1->setDelegate($this->object);
     $ct2 = new Container();
     $xaa = $ct2->get('XAA');
     // autowiring
     $ct2->setDelegate($this->object);
     $ct3 = new Container();
     $ct3->setDelegate($this->object);
     $ct3->add('YAA', 'YAA');
     $ct3->add('YBB', 'YBB');
     // ct1 at first place
     $this->assertTrue($aa === $this->object->get('AA'));
     // ct2
     $this->assertTrue($xaa === $this->object->get('XAA'));
     // ct3
     $xcc = $this->object->get('YAA')->getC();
     $this->assertTrue($xcc === $this->object->get('XCC'));
 }