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
 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);
 }