|
3 | 3 | namespace Illuminate\Tests\Container; |
4 | 4 |
|
5 | 5 | use Attribute; |
| 6 | +use Illuminate\Container\Attributes\Bind; |
6 | 7 | use Illuminate\Container\Attributes\Scoped; |
7 | 8 | use Illuminate\Container\Attributes\Singleton; |
8 | 9 | use Illuminate\Container\Container; |
@@ -766,6 +767,29 @@ public function testContainerScopedAttribute() |
766 | 767 | $this->assertNotSame($firstInstantiation, $thirdInstantiation); |
767 | 768 | } |
768 | 769 |
|
| 770 | + public function testBindInterfaceToSingleton() |
| 771 | + { |
| 772 | + $container = new Container; |
| 773 | + $firstInstantiation = $container->get(ContainerBindSingletonTestInterface::class); |
| 774 | + $secondInstantiation = $container->get(ContainerBindSingletonTestInterface::class); |
| 775 | + |
| 776 | + $this->assertSame($firstInstantiation, $secondInstantiation); |
| 777 | + } |
| 778 | + |
| 779 | + public function testBindInterfaceToScoped() |
| 780 | + { |
| 781 | + $container = new Container; |
| 782 | + $firstInstantiation = $container->get(ContainerBindScopedTestInterface::class); |
| 783 | + $secondInstantiation = $container->get(ContainerBindScopedTestInterface::class); |
| 784 | + |
| 785 | + $this->assertSame($firstInstantiation, $secondInstantiation); |
| 786 | + |
| 787 | + $container->forgetScopedInstances(); |
| 788 | + |
| 789 | + $thirdInstantiation = $container->get(ContainerBindScopedTestInterface::class); |
| 790 | + $this->assertNotSame($firstInstantiation, $thirdInstantiation); |
| 791 | + } |
| 792 | + |
769 | 793 | // public function testContainerCanCatchCircularDependency() |
770 | 794 | // { |
771 | 795 | // $this->expectException(\Illuminate\Contracts\Container\CircularDependencyException::class); |
@@ -935,3 +959,13 @@ class ContainerSingletonAttribute |
935 | 959 | class ContainerScopedAttribute |
936 | 960 | { |
937 | 961 | } |
| 962 | + |
| 963 | +#[Bind(ContainerSingletonAttribute::class)] |
| 964 | +interface ContainerBindSingletonTestInterface |
| 965 | +{ |
| 966 | +} |
| 967 | + |
| 968 | +#[Bind(ContainerScopedAttribute::class)] |
| 969 | +interface ContainerBindScopedTestInterface |
| 970 | +{ |
| 971 | +} |
0 commit comments