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