Skip to content

Commit b5d81f5

Browse files
authored
container currentlyResolving test (#55694)
1 parent 6c184ac commit b5d81f5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/Container/ContainerTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace Illuminate\Tests\Container;
44

5+
use Attribute;
56
use Illuminate\Container\Container;
67
use Illuminate\Container\EntryNotFoundException;
78
use Illuminate\Contracts\Container\BindingResolutionException;
9+
use Illuminate\Contracts\Container\ContextualAttribute;
810
use PHPUnit\Framework\TestCase;
911
use Psr\Container\ContainerExceptionInterface;
1012
use stdClass;
@@ -522,6 +524,23 @@ public function testGetAlias()
522524
$this->assertSame('ConcreteStub', $container->getAlias('foo'));
523525
}
524526

527+
public function testCurrentlyResolving()
528+
{
529+
$container = new Container;
530+
531+
$container->afterResolvingAttribute(ContainerCurrentResolvingAttribute::class, function ($attr, $instance, $container) {
532+
$this->assertEquals(ContainerCurrentResolvingConcrete::class, $container->currentlyResolving());
533+
});
534+
535+
$container->when(ContainerCurrentResolvingConcrete::class)
536+
->needs('$currentlyResolving')
537+
->give(fn ($container) => $container->currentlyResolving());
538+
539+
$resolved = $container->make(ContainerCurrentResolvingConcrete::class);
540+
541+
$this->assertEquals(ContainerCurrentResolvingConcrete::class, $resolved->currentlyResolving);
542+
}
543+
525544
public function testGetAliasRecursive()
526545
{
527546
$container = new Container;
@@ -860,3 +879,23 @@ public function work(IContainerContractStub $stub)
860879
return $stub;
861880
}
862881
}
882+
883+
#[Attribute(Attribute::TARGET_PARAMETER)]
884+
class ContainerCurrentResolvingAttribute implements ContextualAttribute
885+
{
886+
public function resolve()
887+
{
888+
}
889+
}
890+
891+
class ContainerCurrentResolvingConcrete
892+
{
893+
public $currentlyResolving;
894+
895+
public function __construct(
896+
#[ContainerCurrentResolvingAttribute]
897+
string $currentlyResolving
898+
) {
899+
$this->currentlyResolving = $currentlyResolving;
900+
}
901+
}

0 commit comments

Comments
 (0)