app = require $root . '/bootstrap/app.php'; CircuitBreakerMiddleware::clear(); } public function testCircuitBreakerOpensAfterFailures(): void { $mock = new MockHandler([ new Response(500), new Response(500), new Response(200), // Won't be reached if threshold is 2 ]); $stack = HandlerStack::create($mock); // Threshold = 2, Timeout = 60 $stack->push(new CircuitBreakerMiddleware(2, 60.0)); $client = new Client(['handler' => $stack]); // First failure $p1 = $client->getAsync('http://example.com'); try { $p1->wait(); } catch (\Throwable) {} // Second failure -> should open circuit $p2 = $client->getAsync('http://example.com'); try { $p2->wait(); } catch (\Throwable) {} // Third call should be rejected by CB immediately $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Circuit breaker is open for host: example.com'); $client->get('http://example.com'); } public function testS3AdapterResolutionThrowsWhenMissingDependencies(): void { $config = $this->createStub(\Phred\Support\Contracts\ConfigInterface::class); $config->method('get')->willReturnMap([ ['storage.default', 'local', 's3'], ['storage.disks.s3', null, [ 'driver' => 's3', 'key' => 'key', 'secret' => 'secret', 'region' => 'us-east-1', 'bucket' => 'test', ]], ]); $provider = new \Phred\Providers\Core\StorageServiceProvider(); $builder = new \DI\ContainerBuilder(); $builder->addDefinitions([ \Phred\Support\Contracts\ConfigInterface::class => $config, ]); $provider->register($builder, $config); $container = $builder->build(); $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('AWS SDK not found'); $container->get(\League\Flysystem\FilesystemOperator::class); } }