Ejemplo n.º 1
0
 public function can_optionally_be_given_bindings()
 {
     $inject = new Injector($this->bindings, newinstance(Bindings::class, [], ['configure' => function ($inject) {
         $inject->bind(Currency::class, Currency::$EUR, 'EUR');
     }]));
     $this->assertInstanceOf(FileSystem::class, $inject->get(Storage::class));
     $this->assertEquals(Currency::$EUR, $inject->get(Currency::class, 'EUR'));
 }
Ejemplo n.º 2
0
 public function using_a_provider()
 {
     $inject = new Injector();
     $inject->bind(Value::class, newinstance(Named::class, [], ['provides' => function ($name) {
         return true;
     }, 'binding' => function ($name) {
         return new InstanceBinding(new Value($name));
     }]));
     $this->assertEquals(new Value('default'), $inject->get('inject.Provider<inject.unittest.fixture.Value>', 'default')->get());
 }
Ejemplo n.º 3
0
 public function instance_provider_get()
 {
     $inject = new Injector();
     $inject->bind(Storage::class, new FileSystem());
     $this->assertInstanceOf(FileSystem::class, $inject->get('inject.Provider<inject.unittest.fixture.Storage>')->get());
 }
Ejemplo n.º 4
0
 public function get_given_a_typeunion_searches_all_named_types_and_uses_first()
 {
     $path = '/usr';
     $inject = new Injector();
     $inject->bind('string', $path, 'path');
     $inject->bind(FileSystem::class, new FileSystem('/usr'));
     $this->assertEquals($path, $inject->get('string|inject.unittest.fixture.FileSystem', 'path'));
 }