From 5a52f45a1d737ff1f58cfc5750cb48d14636bf53 Mon Sep 17 00:00:00 2001 From: Eric Krona Date: Wed, 1 Nov 2023 11:59:41 +0100 Subject: [PATCH 1/5] Replaced php-http/message-factory with psr/http-factory --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 2a6f228..546c722 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ "php-http/client-implementation": "^1.0", "php-http/httplug": "^1.0 || ^2.0", "php-http/message": "^1.0", - "php-http/message-factory": "^1.0", "php-xapi/exception": "^1.0", "php-xapi/model": "^4.0", "php-xapi/serializer": "^4.0", "php-xapi/symfony-serializer": "^3.0", - "psr/http-message": "^1.0" + "psr/http-message": "^1.0", + "psr/http-factory": "^1.0" }, "require-dev": { "phpspec/phpspec": "^6.0 || ^7.0", From 2785fff640e5b755cbee22fcc2062331681a0531 Mon Sep 17 00:00:00 2001 From: Eric Krona Date: Fri, 27 Jun 2025 08:09:31 +0200 Subject: [PATCH 2/5] test --- src/Request/Handler.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Request/Handler.php b/src/Request/Handler.php index 88f26f4..4204229 100644 --- a/src/Request/Handler.php +++ b/src/Request/Handler.php @@ -14,6 +14,7 @@ use Http\Client\Exception; use Http\Client\HttpClient; use Http\Message\RequestFactory; + use Psr\Http\Message\RequestInterface; use Xabbuh\XApi\Common\Exception\AccessDeniedException; use Xabbuh\XApi\Common\Exception\ConflictException; From 6c4bca8508973e38a457f2caf9c132b9b3402b2a Mon Sep 17 00:00:00 2001 From: Eric Krona Date: Fri, 27 Jun 2025 08:10:18 +0200 Subject: [PATCH 3/5] test --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6c24513..2b49b86 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -33,7 +33,7 @@ jobs: run: 'echo "::set-output name=cache-dir::$(composer config cache-files-dir)"' - name: 'Cache dependencies' - uses: 'actions/cache@v2' + uses: 'actions/cache@v4' with: path: '${{ steps.composer-cache.outputs.cache-dir }}' key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" From a740560303d6a719aac4088f53329c05f025017b Mon Sep 17 00:00:00 2001 From: Eric Krona Date: Fri, 27 Jun 2025 08:41:04 +0200 Subject: [PATCH 4/5] Switched to using psr/http-factory instead of php-http/message-factory --- spec/Request/HandlerSpec.php | 71 +++++++++++++++++++++--------- spec/XApiClientBuilderSpec.php | 59 +++++++++++++++++-------- src/Request/Handler.php | 13 +++--- src/XApiClientBuilder.php | 12 ++--- src/XApiClientBuilderInterface.php | 12 ++--- 5 files changed, 109 insertions(+), 58 deletions(-) diff --git a/spec/Request/HandlerSpec.php b/spec/Request/HandlerSpec.php index 8332689..8e9bd5b 100644 --- a/spec/Request/HandlerSpec.php +++ b/spec/Request/HandlerSpec.php @@ -2,9 +2,10 @@ namespace spec\Xabbuh\XApi\Client\Request; -use Http\Client\HttpClient; use Http\Message\RequestFactory; use PhpSpec\ObjectBehavior; +use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; use Xabbuh\XApi\Common\Exception\AccessDeniedException; @@ -14,7 +15,7 @@ class HandlerSpec extends ObjectBehavior { - function let(HttpClient $client, RequestFactory $requestFactory) + function let(ClientInterface $client, RequestFactoryInterface $requestFactory) { $this->beConstructedWith($client, $requestFactory, 'http://example.com/xapi/', '1.0.1'); } @@ -24,8 +25,10 @@ function it_throws_an_exception_if_a_request_is_created_with_an_invalid_method() $this->shouldThrow('\InvalidArgumentException')->during('createRequest', array('options', '/xapi/statements')); } - function it_returns_get_request_created_by_the_http_client(RequestFactory $requestFactory, RequestInterface $request) - { + function it_returns_get_request_created_by_the_http_client( + RequestFactoryInterface $requestFactory, + RequestInterface $request + ) { $requestFactory->createRequest('GET', 'http://example.com/xapi/statements', array( 'X-Experience-API-Version' => '1.0.1', 'Content-Type' => 'application/json', @@ -35,8 +38,10 @@ function it_returns_get_request_created_by_the_http_client(RequestFactory $reque $this->createRequest('GET', '/statements')->shouldReturn($request); } - function it_returns_post_request_created_by_the_http_client(RequestFactory $requestFactory, RequestInterface $request) - { + function it_returns_post_request_created_by_the_http_client( + RequestFactoryInterface $requestFactory, + RequestInterface $request + ) { $requestFactory->createRequest('POST', 'http://example.com/xapi/statements', array( 'X-Experience-API-Version' => '1.0.1', 'Content-Type' => 'application/json', @@ -46,8 +51,10 @@ function it_returns_post_request_created_by_the_http_client(RequestFactory $requ $this->createRequest('POST', '/statements', array(), 'body')->shouldReturn($request); } - function it_returns_put_request_created_by_the_http_client(RequestFactory $requestFactory, RequestInterface $request) - { + function it_returns_put_request_created_by_the_http_client( + RequestFactoryInterface $requestFactory, + RequestInterface $request + ) { $requestFactory->createRequest('PUT', 'http://example.com/xapi/statements', array( 'X-Experience-API-Version' => '1.0.1', 'Content-Type' => 'application/json', @@ -57,8 +64,10 @@ function it_returns_put_request_created_by_the_http_client(RequestFactory $reque $this->createRequest('PUT', '/statements', array(), 'body')->shouldReturn($request); } - function it_returns_delete_request_created_by_the_http_client(RequestFactory $requestFactory, RequestInterface $request) - { + function it_returns_delete_request_created_by_the_http_client( + RequestFactoryInterface $requestFactory, + RequestInterface $request + ) { $requestFactory->createRequest('DELETE', 'http://example.com/xapi/statements', array( 'X-Experience-API-Version' => '1.0.1', 'Content-Type' => 'application/json', @@ -68,8 +77,11 @@ function it_returns_delete_request_created_by_the_http_client(RequestFactory $re $this->createRequest('DELETE', '/statements')->shouldReturn($request); } - function it_throws_an_access_denied_exception_when_a_401_status_code_is_returned(HttpClient $client, RequestInterface $request, ResponseInterface $response) - { + function it_throws_an_access_denied_exception_when_a_401_status_code_is_returned( + ClientInterface $client, + RequestInterface $request, + ResponseInterface $response + ) { $client->sendRequest($request)->willReturn($response); $response->getStatusCode()->willReturn(401); $response->getBody()->willReturn('body'); @@ -77,8 +89,11 @@ function it_throws_an_access_denied_exception_when_a_401_status_code_is_returned $this->shouldThrow(AccessDeniedException::class)->during('executeRequest', array($request, array(200))); } - function it_throws_an_access_denied_exception_when_a_403_status_code_is_returned(HttpClient $client, RequestInterface $request, ResponseInterface $response) - { + function it_throws_an_access_denied_exception_when_a_403_status_code_is_returned( + ClientInterface $client, + RequestInterface $request, + ResponseInterface $response + ) { $client->sendRequest($request)->willReturn($response); $response->getStatusCode()->willReturn(403); $response->getBody()->willReturn('body'); @@ -86,8 +101,11 @@ function it_throws_an_access_denied_exception_when_a_403_status_code_is_returned $this->shouldThrow(AccessDeniedException::class)->during('executeRequest', array($request, array(200))); } - function it_throws_a_not_found_exception_when_a_404_status_code_is_returned(HttpClient $client, RequestInterface $request, ResponseInterface $response) - { + function it_throws_a_not_found_exception_when_a_404_status_code_is_returned( + ClientInterface $client, + RequestInterface $request, + ResponseInterface $response + ) { $client->sendRequest($request)->willReturn($response); $response->getStatusCode()->willReturn(404); $response->getBody()->willReturn('body'); @@ -95,8 +113,11 @@ function it_throws_a_not_found_exception_when_a_404_status_code_is_returned(Http $this->shouldThrow(NotFoundException::class)->during('executeRequest', array($request, array(200))); } - function it_throws_a_conflict_exception_when_a_409_status_code_is_returned(HttpClient $client, RequestInterface $request, ResponseInterface $response) - { + function it_throws_a_conflict_exception_when_a_409_status_code_is_returned( + ClientInterface $client, + RequestInterface $request, + ResponseInterface $response + ) { $client->sendRequest($request)->willReturn($response); $response->getStatusCode()->willReturn(409); $response->getBody()->willReturn('body'); @@ -104,8 +125,11 @@ function it_throws_a_conflict_exception_when_a_409_status_code_is_returned(HttpC $this->shouldThrow(ConflictException::class)->during('executeRequest', array($request, array(200))); } - function it_throws_an_xapi_exception_when_an_unexpected_status_code_is_returned(HttpClient $client, RequestInterface $request, ResponseInterface $response) - { + function it_throws_an_xapi_exception_when_an_unexpected_status_code_is_returned( + ClientInterface $client, + RequestInterface $request, + ResponseInterface $response + ) { $client->sendRequest($request)->willReturn($response); $response->getStatusCode()->willReturn(204); $response->getBody()->willReturn('body'); @@ -113,8 +137,11 @@ function it_throws_an_xapi_exception_when_an_unexpected_status_code_is_returned( $this->shouldThrow(XApiException::class)->during('executeRequest', array($request, array(200))); } - function it_returns_the_response_on_success(HttpClient $client, RequestInterface $request, ResponseInterface $response) - { + function it_returns_the_response_on_success( + ClientInterface $client, + RequestInterface $request, + ResponseInterface $response + ) { $client->sendRequest($request)->willReturn($response); $response->getStatusCode()->willReturn(200); $response->getBody()->willReturn('body'); diff --git a/spec/XApiClientBuilderSpec.php b/spec/XApiClientBuilderSpec.php index e19ecf5..551dcd4 100644 --- a/spec/XApiClientBuilderSpec.php +++ b/spec/XApiClientBuilderSpec.php @@ -2,12 +2,13 @@ namespace spec\Xabbuh\XApi\Client; -use Http\Client\HttpClient; use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; use Http\Message\RequestFactory; use PhpSpec\Exception\Example\SkippingException; use PhpSpec\ObjectBehavior; +use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; use Xabbuh\Http\Authentication\OAuth1; use Xabbuh\XApi\Client\XApiClientBuilderInterface; use Xabbuh\XApi\Client\XApiClientInterface; @@ -19,7 +20,7 @@ function it_is_an_xapi_client_builder() $this->shouldHaveType(XApiClientBuilderInterface::class); } - function it_creates_an_xapi_client(HttpClient $httpClient, RequestFactory $requestFactory) + function it_creates_an_xapi_client(ClientInterface $httpClient, RequestFactoryInterface $requestFactory) { $this->setHttpClient($httpClient); $this->setRequestFactory($requestFactory); @@ -27,7 +28,7 @@ function it_creates_an_xapi_client(HttpClient $httpClient, RequestFactory $reque $this->build()->shouldHaveType(XApiClientInterface::class); } - function its_methods_can_be_chained(HttpClient $httpClient, RequestFactory $requestFactory) + function its_methods_can_be_chained(ClientInterface $httpClient, RequestFactoryInterface $requestFactory) { $this->setHttpClient($httpClient)->shouldReturn($this); $this->setRequestFactory($requestFactory)->shouldReturn($this); @@ -37,10 +38,12 @@ function its_methods_can_be_chained(HttpClient $httpClient, RequestFactory $requ $this->setOAuthCredentials('consumer key', 'consumer secret', 'token', 'token secret')->shouldReturn($this); } - function it_throws_an_exception_if_the_http_client_is_not_configured(RequestFactory $requestFactory) + function it_throws_an_exception_if_the_http_client_is_not_configured(RequestFactoryInterface $requestFactory) { if ($this->isAbleToDiscoverHttpClient()) { - throw new SkippingException('The builder does not throw an exception if it can automatically discover an HTTP client.'); + throw new SkippingException( + 'The builder does not throw an exception if it can automatically discover an HTTP client.' + ); } $this->setRequestFactory($requestFactory); @@ -49,10 +52,12 @@ function it_throws_an_exception_if_the_http_client_is_not_configured(RequestFact $this->shouldThrow('\LogicException')->during('build'); } - function it_throws_an_exception_if_the_request_factory_is_not_configured(HttpClient $httpClient) + function it_throws_an_exception_if_the_request_factory_is_not_configured(ClientInterface $httpClient) { if ($this->isAbleToDiscoverRequestFactory()) { - throw new SkippingException('The builder does not throw an exception if it can automatically discover a request factory.'); + throw new SkippingException( + 'The builder does not throw an exception if it can automatically discover a request factory.' + ); } $this->setHttpClient($httpClient); @@ -61,10 +66,16 @@ function it_throws_an_exception_if_the_request_factory_is_not_configured(HttpCli $this->shouldThrow('\LogicException')->during('build'); } - function it_can_build_the_client_when_it_is_able_to_discover_the_http_client_and_the_request_factory_without_configuring_them_explicitly() + function it_can_build_the_client_when_it_is_able_to_discover_the_http_client_and_the_request_factory_without_configuring_them_explicitly( + ) { if (!class_exists(HttpClientDiscovery::class)) { - throw new SkippingException(sprintf('The "%s" class is required to let the builder auto discover the HTTP client and request factory.', HttpClientDiscovery::class)); + throw new SkippingException( + sprintf( + 'The "%s" class is required to let the builder auto discover the HTTP client and request factory.', + HttpClientDiscovery::class + ) + ); } if (!$this->isAbleToDiscoverHttpClient()) { @@ -80,18 +91,24 @@ function it_can_build_the_client_when_it_is_able_to_discover_the_http_client_and $this->build()->shouldReturnAnInstanceOf(XApiClientInterface::class); } - function it_throws_an_exception_if_the_base_uri_is_not_configured(HttpClient $httpClient, RequestFactory $requestFactory) - { + function it_throws_an_exception_if_the_base_uri_is_not_configured( + ClientInterface $httpClient, + RequestFactoryInterface $requestFactory + ) { $this->setHttpClient($httpClient); $this->setRequestFactory($requestFactory); $this->shouldThrow('\LogicException')->during('build'); } - function it_throws_an_exception_when_oauth_credentials_are_configured_but_the_auth_package_is_missing(HttpClient $httpClient, RequestFactory $requestFactory) - { + function it_throws_an_exception_when_oauth_credentials_are_configured_but_the_auth_package_is_missing( + ClientInterface $httpClient, + RequestFactoryInterface $requestFactory + ) { if (class_exists(OAuth1::class)) { - throw new SkippingException('OAuth1 credentials can be used when the "xabbuh/oauth1-authentication" package is present.'); + throw new SkippingException( + 'OAuth1 credentials can be used when the "xabbuh/oauth1-authentication" package is present.' + ); } $this->setHttpClient($httpClient); @@ -99,13 +116,19 @@ function it_throws_an_exception_when_oauth_credentials_are_configured_but_the_au $this->setBaseUrl('http://example.com/xapi/'); $this->setOAuthCredentials('consumer_key', 'consumer_secret', 'access_token', 'token_secret'); - $this->shouldThrow(new \LogicException('The "xabbuh/oauth1-authentication package is needed to use OAuth1 authorization.'))->during('build'); + $this->shouldThrow( + new \LogicException('The "xabbuh/oauth1-authentication package is needed to use OAuth1 authorization.') + )->during('build'); } - function it_accepts_oauth_credentials_when_the_auth_package_is_present(HttpClient $httpClient, RequestFactory $requestFactory) - { + function it_accepts_oauth_credentials_when_the_auth_package_is_present( + ClientInterface $httpClient, + RequestFactoryInterface $requestFactory + ) { if (!class_exists(OAuth1::class)) { - throw new SkippingException('OAuth1 credentials cannot be used when the "xabbuh/oauth1-authentication" package is missing.'); + throw new SkippingException( + 'OAuth1 credentials cannot be used when the "xabbuh/oauth1-authentication" package is missing.' + ); } $this->setHttpClient($httpClient); diff --git a/src/Request/Handler.php b/src/Request/Handler.php index 4204229..f1fed5b 100644 --- a/src/Request/Handler.php +++ b/src/Request/Handler.php @@ -12,9 +12,10 @@ namespace Xabbuh\XApi\Client\Request; use Http\Client\Exception; -use Http\Client\HttpClient; use Http\Message\RequestFactory; +use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; use Xabbuh\XApi\Common\Exception\AccessDeniedException; use Xabbuh\XApi\Common\Exception\ConflictException; @@ -34,12 +35,12 @@ final class Handler implements HandlerInterface private $version; /** - * @param HttpClient $httpClient The HTTP client sending requests to the remote LRS - * @param RequestFactory $requestFactory The factory used to create PSR-7 HTTP requests - * @param string $baseUri The APIs base URI (all end points will be created relatively to this URI) - * @param string $version The xAPI version + * @param ClientInterface $httpClient The HTTP client sending requests to the remote LRS + * @param RequestFactoryInterface $requestFactory The factory used to create PSR-7 HTTP requests + * @param string $baseUri The APIs base URI (all end points will be created relatively to this URI) + * @param string $version The xAPI version */ - public function __construct(HttpClient $httpClient, RequestFactory $requestFactory, $baseUri, $version) + public function __construct(ClientInterface $httpClient, RequestFactoryInterface $requestFactory, $baseUri, $version) { $this->httpClient = $httpClient; $this->requestFactory = $requestFactory; diff --git a/src/XApiClientBuilder.php b/src/XApiClientBuilder.php index b1ece4a..cad0d11 100644 --- a/src/XApiClientBuilder.php +++ b/src/XApiClientBuilder.php @@ -18,11 +18,11 @@ use ApiClients\Tools\Psr7\Oauth1\RequestSigning\RequestSigner; use Http\Client\Common\Plugin\AuthenticationPlugin; use Http\Client\Common\PluginClient; -use Http\Client\HttpClient; use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; use Http\Message\Authentication\BasicAuth; -use Http\Message\RequestFactory; +use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; use Xabbuh\Http\Authentication\OAuth1; use Xabbuh\XApi\Client\Request\Handler; use Xabbuh\XApi\Serializer\SerializerFactoryInterface; @@ -39,12 +39,12 @@ final class XApiClientBuilder implements XApiClientBuilderInterface private $serializerFactory; /** - * @var HttpClient|null + * @var ClientInterface|null */ private $httpClient; /** - * @var RequestFactory|null + * @var RequestFactoryInterface|null */ private $requestFactory; @@ -65,7 +65,7 @@ public function __construct(SerializerFactoryInterface $serializerFactory = null /** * {@inheritdoc} */ - public function setHttpClient(HttpClient $httpClient) + public function setHttpClient(ClientInterface $httpClient) { $this->httpClient = $httpClient; @@ -75,7 +75,7 @@ public function setHttpClient(HttpClient $httpClient) /** * {@inheritdoc} */ - public function setRequestFactory(RequestFactory $requestFactory) + public function setRequestFactory(RequestFactoryInterface $requestFactory) { $this->requestFactory = $requestFactory; diff --git a/src/XApiClientBuilderInterface.php b/src/XApiClientBuilderInterface.php index 18b859a..1e4c078 100644 --- a/src/XApiClientBuilderInterface.php +++ b/src/XApiClientBuilderInterface.php @@ -11,8 +11,8 @@ namespace Xabbuh\XApi\Client; -use Http\Client\HttpClient; -use Http\Message\RequestFactory; +use Psr\Http\Client\ClientInterface; +use Psr\Http\Message\RequestFactoryInterface; /** * xAPI client builder. @@ -24,20 +24,20 @@ interface XApiClientBuilderInterface /** * Sets the HTTP client implementation that will be used to issue HTTP requests. * - * @param HttpClient $httpClient The HTTP client implementation + * @param ClientInterface $httpClient The HTTP client implementation * * @return XApiClientBuilderInterface The builder */ - public function setHttpClient(HttpClient $httpClient); + public function setHttpClient(ClientInterface $httpClient); /** * Sets the requests factory which creates requests that are then handled by the HTTP client. * - * @param RequestFactory $requestFactory The request factory + * @param RequestFactoryInterface $requestFactory The request factory * * @return XApiClientBuilderInterface The builder */ - public function setRequestFactory(RequestFactory $requestFactory); + public function setRequestFactory(RequestFactoryInterface $requestFactory); /** * Sets the LRS base URL. From 45e0caeac107789c1d78a6fe9e65e96b19bf5b27 Mon Sep 17 00:00:00 2001 From: Eric Krona Date: Fri, 27 Jun 2025 09:06:06 +0200 Subject: [PATCH 5/5] Removed invalid uses. --- spec/Request/HandlerSpec.php | 1 - spec/XApiClientBuilderSpec.php | 1 - 2 files changed, 2 deletions(-) diff --git a/spec/Request/HandlerSpec.php b/spec/Request/HandlerSpec.php index 8e9bd5b..5c8f26b 100644 --- a/spec/Request/HandlerSpec.php +++ b/spec/Request/HandlerSpec.php @@ -2,7 +2,6 @@ namespace spec\Xabbuh\XApi\Client\Request; -use Http\Message\RequestFactory; use PhpSpec\ObjectBehavior; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; diff --git a/spec/XApiClientBuilderSpec.php b/spec/XApiClientBuilderSpec.php index 551dcd4..a2b4524 100644 --- a/spec/XApiClientBuilderSpec.php +++ b/spec/XApiClientBuilderSpec.php @@ -4,7 +4,6 @@ use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; -use Http\Message\RequestFactory; use PhpSpec\Exception\Example\SkippingException; use PhpSpec\ObjectBehavior; use Psr\Http\Client\ClientInterface;