Exemplo n.º 1
0
 public function testDealer()
 {
     $c = new ContainerStorage(new Instantiator());
     $c->register(new ServiceDefinition('ro', RobotTest::class));
     $dealer = new Dealer($c);
     $dealer->put('q', ObjArg::class)->setArguments([1, 2]);
     $class = new RobotTest();
     $dealer->put('name', $class);
     $this->assertSame($class, $dealer->get('name'));
     $this->assertInstanceOf(RobotTest::class, $dealer->get('ro'));
     $this->assertInstanceOf(ObjArg::class, $dealer->get('q'));
 }
Exemplo n.º 2
0
 public function testInstantiateLinkArgument()
 {
     $inst = $this->createInstantiator();
     $d1 = $this->createDefinition('robo1', RobotTest::class);
     $d2 = $this->createDefinition('robo2', RobotTest::class);
     $this->container->register($d1);
     $this->container->register($d2);
     /** @var ObjArg $out */
     $out = $inst->instantiate($this->createDefinition('ob', ObjArg::class)->setArguments([new Link('robo1'), new Link('robo2')]));
     $this->assertSame($this->container->get('robo1'), $out->getArg1());
     $this->assertSame($this->container->get('robo2'), $out->getArg2());
     $arg1 = [new Link('robo1'), new Link('robo2')];
     $arg2 = [new Link('robo1'), ['text']];
     /** @var RobotTest $out */
     $out = $inst->instantiate($this->createDefinition('setArgs', RobotTest::class)->setArguments([$arg1, $arg2]));
     $this->assertSame($out->arg1[0], $this->container->get('robo1'));
     $this->assertSame($out->arg1[1], $this->container->get('robo2'));
     $this->assertSame($out->arg2[0], $this->container->get('robo1'));
     $this->assertEquals($out->arg2[1], $arg2[1]);
 }