Beispiel #1
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());
 }
Beispiel #2
0
 public function add()
 {
     $inject = new Injector();
     $inject->add($this->bindings);
     $this->assertInstanceOf(FileSystem::class, $inject->get(Storage::class));
 }
Beispiel #3
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'));
 }
 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 overwriting_binding_from_defaults()
    {
        $prop = $this->loadProperties('
      inject.unittest.fixture.Storage=inject.unittest.fixture.FileSystem()

      [one]
      inject.unittest.fixture.Storage=inject.unittest.fixture.FileSystem("/usr/local")
   ');
        $inject = new Injector(new ConfiguredBindings($prop, 'one'));
        $this->assertEquals(new FileSystem('/usr/local'), $inject->get(Storage::class));
    }