示例#1
0
 private function getInjector()
 {
     $c = new Container();
     $c->bind('Fixture\\Momonga', 'momonga', function ($c) {
         return new Fixture\Momonga();
     });
     return new Dispatcher($c);
 }
示例#2
0
 public function testGetByType()
 {
     $c = new Container();
     $this->assertNull($c->getByType('Fixture\\Momonga'));
     $c->bind('Fixture\\Momonga', 'momonga', function ($c) {
         return new Momonga();
     });
     $this->assertInstanceOf('Fixture\\Momonga', $c->getByType('Fixture\\Momonga'));
 }
示例#3
0
文件: FacedeTest.php 项目: ranyuen/di
 public function testBasicFacade()
 {
     $c = new Container();
     $c->bind('Fixture\\Lighter', 'lighter', function ($c) {
         return new Fixture\Lighter();
     });
     $c->facade('OilLighter', 'lighter');
     Container::setAsFacade($c);
     $goods = OilLighter::candle('Urushi', 'Sinjyu');
     $this->assertEquals('Sinjyu top of the Urushi', $goods);
 }
示例#4
0
文件: WrapTest.php 项目: ranyuen/di
 public function testWrapStatic()
 {
     $c = new Container();
     $c->wrap('Fixture\\Wrapped', ['psps'], function ($invocation, $args) {
         list($a) = $args;
         ++$a;
         return $invocation($a);
     });
     $wrapped = $c->newInstance('Fixture\\Wrapped');
     $this->assertEquals(42, $wrapped::psps(20));
 }
示例#5
0
 public function testControllerArgs()
 {
     $c = new Container(['test' => $this]);
     $c->bind('Fixture\\Momonga', 'momonga', function ($c) {
         return new Momonga();
     });
     $r = new Router($c);
     $r->get('/', 'Fixture\\MomongaController@argtest');
     $req = Request::create('/');
     $res = $r->run($req);
     $this->assertEquals(200, $res->getStatusCode());
     $this->assertEquals('Momonga argtest', $res->getContent());
 }
示例#6
0
 /**
  */
 public function testDiByType()
 {
     $test = $this;
     $c = new Container();
     $c->bind('Fixture\\Momonga', 'momonga', function ($c) {
         return new Momonga();
     });
     $r = new Router($c);
     $r->get('/', function (Momonga $m) use($test, $c) {
         $test->assertSame($c['momonga'], $m);
         return '';
     });
     $req = Request::create('/');
     $res = $r->run($req);
     $this->assertEquals(200, $res->getStatusCode());
 }
示例#7
0
文件: BindTest.php 项目: ranyuen/di
 public function testNotFrozen()
 {
     $c = new Container();
     $c['momonga'] = $c->factory(function ($c) {
         return new Momonga();
     });
     $c['momonga'];
     $c->bind('Fixture\\Momonga', 'momonga', function ($c) {
         return new Momonga();
     });
     $c = new Container();
     $c['momonga'] = 42;
     $c['momonga'];
     $c->bind('Fixture\\Momonga', 'momonga', function ($c) {
         return new Momonga();
     });
     $this->assertTrue(true);
 }
示例#8
0
 public function testInjectToNonObject()
 {
     $this->assertEquals(42, $this->container->inject(42));
 }