|
9 | 9 | use Tempest\Discovery\DiscoveryConfig; |
10 | 10 | use Tempest\Discovery\DiscoveryLocation; |
11 | 11 | use Tempest\Discovery\Tests\Fixtures\ContainerWithoutAutowiring; |
| 12 | +use Tempest\Discovery\Tests\Fixtures\DependencyForItemWithClosureSkip; |
| 13 | +use Tempest\Discovery\Tests\Fixtures\DiscoveryForItemWithClosureSkip; |
12 | 14 | use Tempest\Discovery\Tests\Fixtures\MyDiscoveryClass; |
13 | 15 |
|
14 | 16 | final class DiscoveryTest extends TestCase |
@@ -38,6 +40,38 @@ public function test_standalone_discovery(): void |
38 | 40 | $this->assertSame('check', MyDiscoveryClass::$discoveredItem->name); |
39 | 41 | } |
40 | 42 |
|
| 43 | + public function test_skip_discovery_with_closure(): void |
| 44 | + { |
| 45 | + $container = new GenericContainer(); |
| 46 | + |
| 47 | + $bootDiscovery = fn () => (new BootDiscovery( |
| 48 | + container: $container, |
| 49 | + config: new DiscoveryConfig(), |
| 50 | + ))( |
| 51 | + discoveryClasses: [ |
| 52 | + DiscoveryForItemWithClosureSkip::class, |
| 53 | + ], |
| 54 | + discoveryLocations: [ |
| 55 | + new DiscoveryLocation( |
| 56 | + namespace: 'Tempest\Discovery\Tests\Fixtures', |
| 57 | + path: __DIR__ . '/Fixtures', |
| 58 | + ), |
| 59 | + ], |
| 60 | + ); |
| 61 | + |
| 62 | + // Should be skipped |
| 63 | + DiscoveryForItemWithClosureSkip::$discovered = false; |
| 64 | + $container->singleton(DependencyForItemWithClosureSkip::class, new DependencyForItemWithClosureSkip(true)); |
| 65 | + $bootDiscovery(); |
| 66 | + $this->assertFalse(DiscoveryForItemWithClosureSkip::$discovered); |
| 67 | + |
| 68 | + // Should not be skipped |
| 69 | + DiscoveryForItemWithClosureSkip::$discovered = false; |
| 70 | + $container->singleton(DependencyForItemWithClosureSkip::class, new DependencyForItemWithClosureSkip(false)); |
| 71 | + $bootDiscovery(); |
| 72 | + $this->assertTrue(DiscoveryForItemWithClosureSkip::$discovered); |
| 73 | + } |
| 74 | + |
41 | 75 | public function test_discovery_with_other_container(): void |
42 | 76 | { |
43 | 77 | $container = new Container(); |
|
0 commit comments