Esempio n. 1
0
 public function testBinding()
 {
     $injector = new Injector(null);
     $injector->bind([Binding::init(HeavyEngine::class)->lazy(), bind("AAA")->toAlias(HeavyEngine::class)]);
     $engine = $injector->get('AAA');
     $this->assertInstanceOf(Engine::class, $engine);
 }
Esempio n. 2
0
 /**
  * Injector constructor.
  * @param $injector
  */
 public function __construct(Injector $injector = null)
 {
     $this->injector = $injector;
     if (!$injector) {
         $this->bind(Binding::init(LazyProxyBuilder::class)->toValue(LazyProxyBuilder::init()), bind(ProxyCache::class)->toValue(ProxyCache::init()));
     }
 }
Esempio n. 3
0
 public function testBindingFuunfctionProvider()
 {
     $injector = new Injector(null);
     $injector(bind(HeavyTire::class));
     $entity = $injector->{HeavyTire::class};
     $this->assertInstanceOf(Tire::class, $entity);
     $this->assertInstanceOf(HeavyTire::class, $entity);
 }
Esempio n. 4
0
 public function testBindings()
 {
     // Arrange
     $injector = new Injector(null);
     $injector->bind(bind(Car::class)->toClass(FastCar::class), bind(Engine::class)->toClass(Engine::class)->singleton());
     /** @var Car $car */
     $car = $injector->get(Car::class);
     /** @var Engine $engine */
     $engine = $injector->get(Engine::class);
     $this->assertSame($car->engine, $engine);
     $this->assertNotSame($car->tire0, $car->tire1);
     $this->assertNotSame($car->tire0, $car->tire2);
     $this->assertNotSame($car->tire0, $car->tire3);
     $this->assertNotSame($car->tire1, $car->tire2);
     $this->assertNotSame($car->tire1, $car->tire3);
     $this->assertNotSame($car->tire2, $car->tire3);
     $this->assertInstanceOf(SmallTire::class, $car->tire0);
     $this->assertInstanceOf(SmallTire::class, $car->tire1);
     $this->assertInstanceOf(HeavyTire::class, $car->tire2);
     $this->assertInstanceOf(HeavyTire::class, $car->tire3);
 }