Ejemplo n.º 1
0
 function testSingleton()
 {
     $container = new Container();
     $container->share(Hoge::class, function () {
         return new Hoge("default value");
     });
     /* @var $hoge Hoge */
     $hoge = $container->make(Hoge::class);
     $hoge->value = "書き換えました";
     //singletonパターンで副作用のある動作ってのはちょっとアレだけど
     $hoge2 = $container->make(Hoge::class);
     $this->assertEquals("書き換えました", $hoge2->value);
     $this->assertEquals($hoge, $hoge2);
     //destoryで作り直しが出来ます
     $container->destory();
     $hoge3 = $container->make(Hoge::class);
     $this->assertNotEquals($hoge2, $hoge3);
     $this->assertEquals("default value", $hoge3->value);
 }