/** @test */
public function it_should_respect_singletons_when_auto_resolving() {
$c = new tad_DI52_Container;
$c->singleton(Dependency::class, function() {
return new Dependency;
});
$parent = $c->make(Depending::class);
$parent2 = $c->make(Depending::class);
// Failed asserting that two variables reference the same object.
$this->assertSame($parent->getDependency(), $parent2->getDependency());
// If not using a closure, the test would pass:
//$c->singleton(Dependency::class, Dependency::class);
}
If the callback was executed already, it should save that instance in the singletons array and return from that.
Before I try to open a PR for it, can you please confirm this is not the expected behavior, and that test should be passing?