コード例 #1
0
ファイル: ClassProviderTest.php プロジェクト: sysvyz/brunt
 public function testProviders()
 {
     // Arrange
     $injector = new Injector(null);
     $injector->providers([Controller::class => ClassProvider::init(ControllerA::class), '%BASE_URL%' => ValueFactoryProvider::init(function () {
         return 'http://sysvyz.org/';
     })]);
     /** @var ControllerA $ctrl */
     $ctrl = $injector->get(Controller::class);
     $this->assertInstanceOf(ControllerA::class, $ctrl);
     $this->assertSame($ctrl->requestService, $ctrl->serviceZ->requestService);
     $this->assertNotSame($ctrl->requestService, $ctrl->serviceZ->serviceY->requestService);
     $this->assertNotEquals($ctrl->requestService->url, $ctrl->serviceZ->serviceY->requestService->url);
 }
コード例 #2
0
 public function testProvidersSingletonLazy()
 {
     $injector = new Injector(null);
     $injector->providers(['tire' => ValueFactoryProvider::init(function () {
         return new Tire();
     })->lazy()->singleton()]);
     $this->assertEquals($injector->{'tire'}->type, 'Tire');
     $injector->{'tire'}->a = "a";
     $this->assertEquals($injector->{'tire'}->a, 'a');
     $this->assertNotSame($injector->{'tire'}, $injector->{'tire'});
     $this->assertNotInstanceOf(Tire::class, $injector->{'tire'});
     $this->assertInstanceOf(LazyProxyObject::class, $injector->{'tire'});
     $this->assertInstanceOf(Tire::class, $injector->{'tire'}->getInstance());
     $this->assertSame($injector->{'tire'}->getInstance(), $injector->{'tire'}->getInstance());
 }
コード例 #3
0
ファイル: ProxyTest.php プロジェクト: sysvyz/brunt
 public function testProxy()
 {
     $injector = new Injector(null);
     $provider = ValueFactoryProvider::init(function () {
         return new MethodReflectionTestObject();
     })->lazy();
     /** @var MethodReflectionTestObject $proxy */
     $proxy = $provider->get($injector);
     $testFunction = function (LazyProxyObject $a) {
         $this->assertInstanceOf(LazyProxyObject::class, $a);
         return true;
     };
     $this->assertEquals($proxy->getPri(), 409);
     $this->assertEquals($proxy->privateMethod(), "__call:privateMethod");
     //private cant be called, calls -> __call instead
     $this->assertEquals($proxy->publicMethod(), 'publicMethod');
     $this->assertEquals($proxy->publicMethodWithoutModifier(), 'publicMethodWithoutModifier');
     $this->assertEquals($proxy . "", '_TO_STRING_');
     $this->assertEquals($proxy->getProvider(), 'PROVIDER');
     $this->assertTrue($testFunction($proxy));
 }
コード例 #4
0
ファイル: Car.php プロジェクト: sysvyz/brunt
 public static function _DI_PROVIDERS()
 {
     return [Tire::class => ClassProvider::init(SmallTire::class, false), '%CAR_NAME%' => ValueFactoryProvider::init(function () {
         return 'CAR';
     })];
 }