diff --git a/src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php b/src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php new file mode 100644 index 000000000..b1fd40b79 --- /dev/null +++ b/src/SDK/Common/Adapter/HttpDiscovery/DependencyResolver.php @@ -0,0 +1,89 @@ +messageFactoryResolver = $messageFactoryResolver ?? MessageFactoryResolver::create(); + $this->psrClientResolver = $psrClientResolver ?? PsrClientResolver::create(); + $this->httpPlugClientResolver = $httpPlugClientResolver ?? HttpPlugClientResolver::create(); + } + + public static function create( + ?MessageFactoryResolverInterface $messageFactoryResolver = null, + ?PsrClientResolverInterface $psrClientResolver = null, + ?HttpPlugClientResolverInterface $httpPlugClientResolver = null + ): self { + return new self($messageFactoryResolver, $psrClientResolver, $httpPlugClientResolver); + } + + public function resolveRequestFactory(): RequestFactoryInterface + { + return $this->messageFactoryResolver->resolveRequestFactory(); + } + + public function resolveResponseFactory(): ResponseFactoryInterface + { + return $this->messageFactoryResolver->resolveResponseFactory(); + } + + public function resolveServerRequestFactory(): ServerRequestFactoryInterface + { + return $this->messageFactoryResolver->resolveServerRequestFactory(); + } + + public function resolveStreamFactory(): StreamFactoryInterface + { + return $this->messageFactoryResolver->resolveStreamFactory(); + } + + public function resolveUploadedFileFactory(): UploadedFileFactoryInterface + { + return $this->messageFactoryResolver->resolveUploadedFileFactory(); + } + + public function resolveUriFactory(): UriFactoryInterface + { + return $this->messageFactoryResolver->resolveUriFactory(); + } + + public function resolveHttpPlugClient(): HttpClient + { + return $this->httpPlugClientResolver->resolveHttpPlugClient(); + } + + public function resolveHttpPlugAsyncClient(): HttpAsyncClient + { + return $this->httpPlugClientResolver->resolveHttpPlugAsyncClient(); + } + + public function resolvePsrClient(): ClientInterface + { + return $this->psrClientResolver->resolvePsrClient(); + } +} diff --git a/src/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php b/src/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php new file mode 100644 index 000000000..81b6943fa --- /dev/null +++ b/src/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolver.php @@ -0,0 +1,38 @@ +httpClient = $httpClient; + $this->httpAsyncClient = $httpAsyncClient; + } + + public static function create(?HttpClient $httpClient = null, ?HttpAsyncClient $httpAsyncClient = null): self + { + return new self($httpClient, $httpAsyncClient); + } + + public function resolveHttpPlugClient(): HttpClient + { + return $this->httpClient ??= HttpClientDiscovery::find(); + } + + public function resolveHttpPlugAsyncClient(): HttpAsyncClient + { + return $this->httpAsyncClient ??= HttpAsyncClientDiscovery::find(); + } +} diff --git a/src/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php b/src/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php new file mode 100644 index 000000000..6ed0895ff --- /dev/null +++ b/src/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolver.php @@ -0,0 +1,88 @@ +requestFactory = $requestFactory; + $this->responseFactory = $responseFactory; + $this->serverRequestFactory = $serverRequestFactory; + $this->streamFactory = $streamFactory; + $this->uploadedFileFactory = $uploadedFileFactory; + $this->uriFactory = $uriFactory; + } + + public static function create( + ?RequestFactoryInterface $requestFactory = null, + ?ResponseFactoryInterface $responseFactory = null, + ?ServerRequestFactoryInterface $serverRequestFactory = null, + ?StreamFactoryInterface $streamFactory = null, + ?UploadedFileFactoryInterface $uploadedFileFactory = null, + ?UriFactoryInterface $uriFactory = null + ): self { + return new self( + $requestFactory, + $responseFactory, + $serverRequestFactory, + $streamFactory, + $uploadedFileFactory, + $uriFactory + ); + } + + public function resolveRequestFactory(): RequestFactoryInterface + { + return $this->requestFactory ??= Psr17FactoryDiscovery::findRequestFactory(); + } + + public function resolveResponseFactory(): ResponseFactoryInterface + { + return $this->responseFactory ??= Psr17FactoryDiscovery::findResponseFactory(); + } + + public function resolveServerRequestFactory(): ServerRequestFactoryInterface + { + return $this->serverRequestFactory ??= Psr17FactoryDiscovery::findServerRequestFactory(); + } + + public function resolveStreamFactory(): StreamFactoryInterface + { + return $this->streamFactory ??= Psr17FactoryDiscovery::findStreamFactory(); + } + + public function resolveUploadedFileFactory(): UploadedFileFactoryInterface + { + return $this->uploadedFileFactory ??= Psr17FactoryDiscovery::findUploadedFileFactory(); + } + + public function resolveUriFactory(): UriFactoryInterface + { + return $this->uriFactory ??= Psr17FactoryDiscovery::findUriFactory(); + } +} diff --git a/src/SDK/Common/Adapter/HttpDiscovery/PsrClientResolver.php b/src/SDK/Common/Adapter/HttpDiscovery/PsrClientResolver.php new file mode 100644 index 000000000..46fb36312 --- /dev/null +++ b/src/SDK/Common/Adapter/HttpDiscovery/PsrClientResolver.php @@ -0,0 +1,29 @@ +client = $client; + } + + public static function create(?ClientInterface $client = null): self + { + return new self($client); + } + + public function resolvePsrClient(): ClientInterface + { + return $this->client ??= Psr18ClientDiscovery::find(); + } +} diff --git a/src/SDK/Common/Http/DependencyResolverInterface.php b/src/SDK/Common/Http/DependencyResolverInterface.php new file mode 100644 index 000000000..824335213 --- /dev/null +++ b/src/SDK/Common/Http/DependencyResolverInterface.php @@ -0,0 +1,13 @@ +propagator; + } +} diff --git a/src/SDK/Common/Http/Psr/Message/FactoryResolverInterface.php b/src/SDK/Common/Http/Psr/Message/FactoryResolverInterface.php new file mode 100644 index 000000000..4582e19ce --- /dev/null +++ b/src/SDK/Common/Http/Psr/Message/FactoryResolverInterface.php @@ -0,0 +1,22 @@ +requestFactory = $requestFactory; + $this->responseFactory = $responseFactory; + $this->serverRequestFactory = $serverRequestFactory; + } + + public static function create( + RequestFactoryInterface $requestFactory, + ResponseFactoryInterface $responseFactory, + ServerRequestFactoryInterface $serverRequestFactory + ): self { + return new self($requestFactory, $responseFactory, $serverRequestFactory); + } + + public function createRequest(string $method, $uri): RequestInterface + { + return $this->requestFactory->createRequest($method, $uri); + } + + public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface + { + return $this->responseFactory->createResponse($code, $reasonPhrase); + } + + public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface + { + return $this->serverRequestFactory->createServerRequest($method, $uri, $serverParams); + } +} diff --git a/src/SDK/Common/Http/Psr/Message/MessageFactoryInterface.php b/src/SDK/Common/Http/Psr/Message/MessageFactoryInterface.php new file mode 100644 index 000000000..97258491f --- /dev/null +++ b/src/SDK/Common/Http/Psr/Message/MessageFactoryInterface.php @@ -0,0 +1,13 @@ +decorated = $decorated; + $this->propagator = $propagator; + } + + public static function create(RequestFactoryInterface $decorated, TextMapPropagatorInterface $propagator): self + { + return new self($decorated, $propagator); + } + + public function createRequest(string $method, $uri): RequestInterface + { + return self::doCreateRequest( + $this->decorated, + $this->propagator, + $method, + $uri + ); + } +} diff --git a/src/SDK/Common/Http/Psr/Message/RequestFactoryDecoratorInterface.php b/src/SDK/Common/Http/Psr/Message/RequestFactoryDecoratorInterface.php new file mode 100644 index 000000000..3b043c48d --- /dev/null +++ b/src/SDK/Common/Http/Psr/Message/RequestFactoryDecoratorInterface.php @@ -0,0 +1,11 @@ +createServerRequest($method, $uri, $serverParams) + : $factory->createRequest($method, $uri); + + $headers = []; + + $propagator->inject($headers); + + foreach ($headers as $name => $value) { + $request = $request->withHeader($name, $value); + } + + return $request; + } +} diff --git a/src/SDK/Common/Http/Psr/Message/ResponseFactoryDecorator.php b/src/SDK/Common/Http/Psr/Message/ResponseFactoryDecorator.php new file mode 100644 index 000000000..783b2f45b --- /dev/null +++ b/src/SDK/Common/Http/Psr/Message/ResponseFactoryDecorator.php @@ -0,0 +1,40 @@ +decorated = $decorated; + $this->propagator = $propagator; + } + + public static function create(ResponseFactoryInterface $decorated, TextMapPropagatorInterface $propagator): self + { + return new self($decorated, $propagator); + } + + /** + * @inheritDoc + */ + public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface + { + /** @psalm-suppress PossiblyUndefinedMethod */ + $response = $this->decorated->createResponse($code, $reasonPhrase); + + $headers = $response->getHeaders(); + + $this->propagator->extract($headers); + + return $response; + } +} diff --git a/src/SDK/Common/Http/Psr/Message/ResponseFactoryDecoratorInterface.php b/src/SDK/Common/Http/Psr/Message/ResponseFactoryDecoratorInterface.php new file mode 100644 index 000000000..f5d05e92a --- /dev/null +++ b/src/SDK/Common/Http/Psr/Message/ResponseFactoryDecoratorInterface.php @@ -0,0 +1,11 @@ +decorated = $decorated; + $this->propagator = $propagator; + } + + public static function create(ServerRequestFactoryInterface $decorated, TextMapPropagatorInterface $propagator): self + { + return new self($decorated, $propagator); + } + + /** + * @psalm-suppress MoreSpecificReturnType + * @psalm-suppress LessSpecificReturnStatement + */ + public function createServerRequest(string $method, $uri, array $serverParams = []): ServerRequestInterface + { + /** @phpstan-ignore-next-line */ + return self::doCreateRequest( + $this->decorated, + $this->propagator, + $method, + $uri, + $serverParams + ); + } +} diff --git a/src/SDK/Common/Http/Psr/Message/ServerRequestFactoryDecoratorInterface.php b/src/SDK/Common/Http/Psr/Message/ServerRequestFactoryDecoratorInterface.php new file mode 100644 index 000000000..c14a8032d --- /dev/null +++ b/src/SDK/Common/Http/Psr/Message/ServerRequestFactoryDecoratorInterface.php @@ -0,0 +1,11 @@ + [ + RequestFactoryInterface::class, + ResponseFactoryInterface::class, + ServerRequestFactoryInterface::class, + StreamFactoryInterface::class, + UploadedFileFactoryInterface::class, + UriFactoryInterface::class, + ], + PsrClientResolverInterface::class => [ + PsrClientInterface::class, + ], + HttpPlugClientResolverInterface::class => [ + HttpClient::class, + HttpAsyncClient::class, + ], + ]; + private const METHOD_NAME_REPLACEMENTS = [ + MessageFactoryResolverInterface::class => [], + HttpPlugClientResolverInterface::class => ['Http', 'HttpPlug'], + PsrClientResolverInterface::class => ['Client', 'PsrClient'], + ]; + + /** + * @dataProvider provideDependencies + */ + public function test_resolve(string $method, object $dependency, array $arguments): void + { + $instance = DependencyResolver::create(...$arguments); + + $this->assertSame( + $dependency, + $instance->{$method}() + ); + } + + public function provideDependencies(): Generator + { + $arguments = []; + $dependencies = []; + + foreach (self::DEPENDENCIES as $resolverInterface => $interfaces) { + $resolver = $this->createMock($resolverInterface); + + foreach ($interfaces as $interface) { + $method = $this->resolveMethodName($interface, self::METHOD_NAME_REPLACEMENTS[$resolverInterface]); + $dependency = $this->createMock($interface); + $resolver->method($method)->willReturn($dependency); + $dependencies[$method] = $dependency; + } + + $arguments[] = $resolver; + } + + foreach ($dependencies as $method => $dependency) { + yield [$method, $dependency, $arguments]; + } + } + + /** + * @psalm-param class-string $interface + */ + private function resolveMethodName(string $interface, array $replacements = []): string + { + $interface = (new ReflectionClass($interface))->getShortName(); + + if (count($replacements) >= 2) { + $interface = str_replace($replacements[0], $replacements[1], $interface); + } + + return sprintf( + 'resolve%s', + str_replace( + 'Interface', + '', + $interface + ) + ); + } +} diff --git a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolverTest.php b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolverTest.php new file mode 100644 index 000000000..253d14231 --- /dev/null +++ b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/HttpPlugClientResolverTest.php @@ -0,0 +1,38 @@ +createMock(HttpClient::class); + $instance = HttpPlugClientResolver::create($dependency); + + $this->assertSame( + $dependency, + $instance->resolveHttpPlugClient() + ); + } + + public function test_resolve_http_plug_async_client(): void + { + $dependency = $this->createMock(HttpAsyncClient::class); + $instance = HttpPlugClientResolver::create(null, $dependency); + + $this->assertSame( + $dependency, + $instance->resolveHttpPlugAsyncClient() + ); + } +} diff --git a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolverTest.php b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolverTest.php new file mode 100644 index 000000000..e5dee1269 --- /dev/null +++ b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/MessageFactoryResolverTest.php @@ -0,0 +1,79 @@ +assertSame( + $dependency, + $instance->{$method}() + ); + } + + public function provideDependencies(): Generator + { + $dependencies = []; + + foreach (self::DEPENDENCIES as $interface) { + $dependencies[$this->resolveMethodName($interface)] = $this->createMock($interface); + } + + foreach ($dependencies as $method => $dependency) { + yield [$method, $dependency, array_values($dependencies)]; + } + } + + /** + * @psalm-param class-string $interface + */ + private function resolveMethodName(string $interface): string + { + return sprintf( + 'resolve%s', + str_replace( + 'Interface', + '', + (new ReflectionClass($interface))->getShortName() + ) + ); + } +} diff --git a/tests/Unit/SDK/Common/Adapter/HttpDiscovery/PsrClientResolverTest.php b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/PsrClientResolverTest.php new file mode 100644 index 000000000..48c5c0ba5 --- /dev/null +++ b/tests/Unit/SDK/Common/Adapter/HttpDiscovery/PsrClientResolverTest.php @@ -0,0 +1,33 @@ +createMock(ClientInterface::class); + $instance = PsrClientResolver::create($dependency); + + $this->assertSame( + $dependency, + $instance->resolvePsrClient() + ); + } +} diff --git a/tests/Unit/SDK/Common/Http/Psr/Message/CreatesMockTrait.php b/tests/Unit/SDK/Common/Http/Psr/Message/CreatesMockTrait.php new file mode 100644 index 000000000..7316143fd --- /dev/null +++ b/tests/Unit/SDK/Common/Http/Psr/Message/CreatesMockTrait.php @@ -0,0 +1,17 @@ + $originalClassName + * @psalm-return MockObject&RealInstanceType + */ + abstract protected function createMock(string $originalClassName): MockObject; +} diff --git a/tests/Unit/SDK/Common/Http/Psr/Message/FactoryDecoratorTraitTest.php b/tests/Unit/SDK/Common/Http/Psr/Message/FactoryDecoratorTraitTest.php new file mode 100644 index 000000000..9b182888d --- /dev/null +++ b/tests/Unit/SDK/Common/Http/Psr/Message/FactoryDecoratorTraitTest.php @@ -0,0 +1,39 @@ +createImplementation(); + $propagator = $this->createMock(TextMapPropagatorInterface::class); + + $instance->setPropagator($propagator); + + $this->assertSame( + $propagator, + $instance->getPropagator() + ); + } + + private function createImplementation(): object + { + return new class() { + use FactoryDecoratorTrait; + public function setPropagator(TextMapPropagatorInterface $propagator): void + { + $this->propagator = $propagator; + } + }; + } +} diff --git a/tests/Unit/SDK/Common/Http/Psr/Message/MessageFactoryTest.php b/tests/Unit/SDK/Common/Http/Psr/Message/MessageFactoryTest.php new file mode 100644 index 000000000..e2a4b8059 --- /dev/null +++ b/tests/Unit/SDK/Common/Http/Psr/Message/MessageFactoryTest.php @@ -0,0 +1,78 @@ +createResponseFactoryMock(); + $serverRequestFactory = $this->createServerRequestFactoryMock(); + $requestFactory = $this->createMock(RequestFactoryInterface::class); + $requestFactory->expects($this->once()) + ->method('createRequest') + ->willReturn( + $this->createMock(RequestInterface::class) + ); + + MessageFactory::create( + $requestFactory, + $responseFactory, + $serverRequestFactory + )->createRequest('POST', 'https://example.com/'); + } + + public function test_create_server_request(): void + { + $responseFactory = $this->createResponseFactoryMock(); + $requestFactory = $this->createRequestFactoryMock(); + $serverRequestFactory = $this->createMock(ServerRequestFactoryInterface::class); + $serverRequestFactory->expects($this->once()) + ->method('createServerRequest') + ->willReturn( + $this->createMock(ServerRequestInterface::class) + ); + + MessageFactory::create( + $requestFactory, + $responseFactory, + $serverRequestFactory + )->createServerRequest('POST', 'https://example.com/', []); + } + + public function test_create_response(): void + { + $requestFactory = $this->createRequestFactoryMock(); + $serverRequestFactory = $this->createServerRequestFactoryMock(); + $responseFactory = $this->createMock(ResponseFactoryInterface::class); + $responseFactory->expects($this->once()) + ->method('createResponse') + ->willReturn( + $this->createMock(ResponseInterface::class) + ); + + MessageFactory::create( + $requestFactory, + $responseFactory, + $serverRequestFactory + )->createResponse(201, 'because'); + } +} diff --git a/tests/Unit/SDK/Common/Http/Psr/Message/RequestFactoryDecoratorTest.php b/tests/Unit/SDK/Common/Http/Psr/Message/RequestFactoryDecoratorTest.php new file mode 100644 index 000000000..7bb2b08c2 --- /dev/null +++ b/tests/Unit/SDK/Common/Http/Psr/Message/RequestFactoryDecoratorTest.php @@ -0,0 +1,37 @@ +createRequestFactoryMock($method, $uri), + $this->createPropagatorMock() + ); + + $this->assertSame( + $method, + $instance->createRequest($method, $uri)->getMethod() + ); + $this->assertSame( + $uri, + (string) $instance->createRequest($method, $uri)->getUri() + ); + } +} diff --git a/tests/Unit/SDK/Common/Http/Psr/Message/RequestFactoryDecoratorTraitTest.php b/tests/Unit/SDK/Common/Http/Psr/Message/RequestFactoryDecoratorTraitTest.php new file mode 100644 index 000000000..342d77d63 --- /dev/null +++ b/tests/Unit/SDK/Common/Http/Psr/Message/RequestFactoryDecoratorTraitTest.php @@ -0,0 +1,85 @@ +createImplementation(); + $factory = $this->createRequestFactoryMock(); + $propagator = $this->createPropagatorMock(); + + $this->assertInstanceOf( + RequestInterface::class, + $instance->createRequest( + $factory, + $propagator, + 'POST', + 'https://example.com' + ) + ); + } + + public function test_create_server_request(): void + { + $instance = $this->createImplementation(); + $factory = $this->createServerRequestFactoryMock(); + $propagator = $this->createPropagatorMock(); + + $this->assertInstanceOf( + ServerRequestInterface::class, + $instance->createRequest( + $factory, + $propagator, + 'POST', + 'https://example.com', + [] + ) + ); + } + + private function createImplementation(): object + { + return new class() { + use RequestFactoryDecoratorTrait; + + /** + * @param $factory RequestFactoryInterface|ServerRequestFactoryInterface + * @return RequestInterface|ServerRequestInterface + */ + public static function createRequest( + $factory, + TextMapPropagatorInterface $propagator, + string $method, + $uri, + array $serverParams = [] + ) { + return self::doCreateRequest( + $factory, + $propagator, + $method, + $uri, + $serverParams + ); + } + }; + } +} diff --git a/tests/Unit/SDK/Common/Http/Psr/Message/ResponseFactoryDecoratorTest.php b/tests/Unit/SDK/Common/Http/Psr/Message/ResponseFactoryDecoratorTest.php new file mode 100644 index 000000000..4e17b7b57 --- /dev/null +++ b/tests/Unit/SDK/Common/Http/Psr/Message/ResponseFactoryDecoratorTest.php @@ -0,0 +1,37 @@ +createResponseFactoryMock($code, $reason), + $this->createPropagatorMock() + ); + + $this->assertSame( + $code, + $instance->createResponse($code, $reason)->getStatusCode() + ); + $this->assertSame( + $reason, + $instance->createResponse($code, $reason)->getReasonPhrase() + ); + } +} diff --git a/tests/Unit/SDK/Common/Http/Psr/Message/ServerRequestFactoryDecoratorTest.php b/tests/Unit/SDK/Common/Http/Psr/Message/ServerRequestFactoryDecoratorTest.php new file mode 100644 index 000000000..cb4235764 --- /dev/null +++ b/tests/Unit/SDK/Common/Http/Psr/Message/ServerRequestFactoryDecoratorTest.php @@ -0,0 +1,37 @@ +createServerRequestFactoryMock($method, $uri), + $this->createPropagatorMock() + ); + + $this->assertSame( + $method, + $instance->createServerRequest($method, $uri)->getMethod() + ); + $this->assertSame( + $uri, + (string) $instance->createServerRequest($method, $uri)->getUri() + ); + } +} diff --git a/tests/Unit/SDK/Common/Http/Psr/Message/UsesRequestFactoryTrait.php b/tests/Unit/SDK/Common/Http/Psr/Message/UsesRequestFactoryTrait.php new file mode 100644 index 000000000..e816e6f6b --- /dev/null +++ b/tests/Unit/SDK/Common/Http/Psr/Message/UsesRequestFactoryTrait.php @@ -0,0 +1,29 @@ +createMock(RequestInterface::class); + $request->method('withHeader') + ->willReturn($request); + $request->method('getMethod') + ->willReturn((string) $requestMethod); + $request->method('getUri') + ->willReturn((string) $requestUri); + $factory = $this->createMock(RequestFactoryInterface::class); + $factory->method('createRequest') + ->willReturn($request); + + return $factory; + } +} diff --git a/tests/Unit/SDK/Common/Http/Psr/Message/UsesResponseFactoryTrait.php b/tests/Unit/SDK/Common/Http/Psr/Message/UsesResponseFactoryTrait.php new file mode 100644 index 000000000..47aa263d4 --- /dev/null +++ b/tests/Unit/SDK/Common/Http/Psr/Message/UsesResponseFactoryTrait.php @@ -0,0 +1,29 @@ +createMock(ResponseInterface::class); + $response->method('getHeaders') + ->willReturn(['foo' => 'bar']); + $response->method('getStatusCode') + ->willReturn($code); + $response->method('getReasonPhrase') + ->willReturn($reasonPhrase); + $factory = $this->createMock(ResponseFactoryInterface::class); + $factory->method('createResponse') + ->willReturn($response); + + return $factory; + } +} diff --git a/tests/Unit/SDK/Common/Http/Psr/Message/UsesServerRequestFactoryTrait.php b/tests/Unit/SDK/Common/Http/Psr/Message/UsesServerRequestFactoryTrait.php new file mode 100644 index 000000000..2b7007ad8 --- /dev/null +++ b/tests/Unit/SDK/Common/Http/Psr/Message/UsesServerRequestFactoryTrait.php @@ -0,0 +1,29 @@ +createMock(ServerRequestInterface::class); + $request->method('withHeader') + ->willReturn($request); + $request->method('getMethod') + ->willReturn((string) $requestMethod); + $request->method('getUri') + ->willReturn((string) $requestUri); + $factory = $this->createMock(ServerRequestFactoryInterface::class); + $factory->method('createServerRequest') + ->willReturn($request); + + return $factory; + } +} diff --git a/tests/Unit/SDK/Common/Http/Psr/Message/UsesTextMapPropagatorTrait.php b/tests/Unit/SDK/Common/Http/Psr/Message/UsesTextMapPropagatorTrait.php new file mode 100644 index 000000000..5f437083c --- /dev/null +++ b/tests/Unit/SDK/Common/Http/Psr/Message/UsesTextMapPropagatorTrait.php @@ -0,0 +1,26 @@ +createMock(TextMapPropagatorInterface::class); + $propagator->method('inject') + ->willReturnCallback(static function (array &$carrier) { + $carrier['foo'] = 'bar'; + }); + $propagator->method('extract') + ->willReturn(Context::getCurrent()); + + return $propagator; + } +}