Skip to content

Commit

Permalink
Merge pull request #48 from FLUX-SE/fix-psr-http-message-factory
Browse files Browse the repository at this point in the history
Fix psr http message factory
  • Loading branch information
Prometee authored Jan 4, 2024
2 parents 87ce5c5 + 3fea7e5 commit b7ab104
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 2 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,17 @@ jobs:
composer require "friendsofsymfony/oauth-server-bundle:>2.0.0-alpha.0 ^2.0@dev" --no-update --no-scripts --no-interaction
# Sylius issues on `json_array` type not existing
composer require "doctrine/dbal:^2.6" --no-update --no-scripts --no-interaction
composer require "nyholm/psr7" --no-update --no-scripts --no-interaction
-
name: Fix build on Sylius 1.10
if: matrix.sylius == '~1.10.0'
run: |
composer require "nyholm/psr7" --no-update --no-scripts --no-interaction
-
name: Fix build on Sylius 1.11
if: matrix.sylius == '~1.11.0'
run: |
composer require "nyholm/psr7" --no-update --no-scripts --no-interaction
-
name: Install PHP dependencies
Expand Down Expand Up @@ -281,7 +292,7 @@ jobs:

-
name: Upload Behat logs
uses: actions/upload-artifact@v3
uses: codecov/codecov-action@v3
if: failure()
with:
name: Behat logs
Expand Down
2 changes: 1 addition & 1 deletion tests/Application/.env
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ JWT_PASSPHRASE=acme_plugin_development
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=smtp://localhost
MAILER_URL=null://localhost
###< symfony/swiftmailer-bundle ###

###> symfony/mailer ###
Expand Down
25 changes: 25 additions & 0 deletions tests/Application/config/sylius/1.10/packages/payum.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
app.payum.http_client:
public: true
class: Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\HttpClient\HttpClient
arguments:
$client: '@Psr\Http\Client\ClientInterface'
app.payum.message_factory:
public: true
class: Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\Factory\MessageFactory
arguments:
$requestFactory: '@Psr\Http\Client\ClientInterface'
$responseFactory: '@nyholm.psr17.factory'
$streamFactory: '@Psr\Http\Client\ClientInterface'

nyholm.psr17.factory:
public: true
class: Nyholm\Psr7\Factory\Psr17Factory

payum:
gateways:
core:
httplug.message_factory: '@app.payum.message_factory'
httplug.stream_factory: '@app.payum.message_factory'
httplug.client: '@Symfony\Component\HttpClient\HttplugClient'
payum.http_client: '@app.payum.http_client'
29 changes: 29 additions & 0 deletions tests/Application/config/sylius/1.11/packages/payum.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
services:
app.payum.http_client:
public: true
class: Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\HttpClient\HttpClient
arguments:
$client: '@Psr\Http\Client\ClientInterface'
app.payum.message_factory:
public: true
class: Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\Factory\MessageFactory
arguments:
$requestFactory: '@Psr\Http\Client\ClientInterface'
$responseFactory: '@nyholm.psr17.factory'
$streamFactory: '@Psr\Http\Client\ClientInterface'

nyholm.psr17.factory:
public: true
class: Nyholm\Psr7\Factory\Psr17Factory

framework:
http_client:
enabled: true # require to alias the service Psr\Http\Client\ClientInterface

payum:
gateways:
core:
httplug.message_factory: '@app.payum.message_factory'
httplug.stream_factory: '@app.payum.message_factory'
httplug.client: '@Symfony\Component\HttpClient\HttplugClient'
payum.http_client: '@app.payum.http_client'
25 changes: 25 additions & 0 deletions tests/Application/config/sylius/1.9/packages/payum.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
app.payum.http_client:
public: true
class: Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\HttpClient\HttpClient
arguments:
$client: '@Psr\Http\Client\ClientInterface'
app.payum.message_factory:
public: true
class: Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\Factory\MessageFactory
arguments:
$requestFactory: '@Psr\Http\Client\ClientInterface'
$responseFactory: '@nyholm.psr17.factory'
$streamFactory: '@Psr\Http\Client\ClientInterface'

nyholm.psr17.factory:
public: true
class: Nyholm\Psr7\Factory\Psr17Factory

payum:
gateways:
core:
httplug.message_factory: '@app.payum.message_factory'
httplug.stream_factory: '@app.payum.message_factory'
httplug.client: '@Symfony\Component\HttpClient\HttplugClient'
payum.http_client: '@app.payum.http_client'
60 changes: 60 additions & 0 deletions tests/Application/src/Payum/Factory/MessageFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\Factory;

use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\StreamInterface;

class MessageFactory implements RequestFactoryInterface, ResponseFactoryInterface, StreamFactoryInterface
{
/** @var RequestFactoryInterface */
private $requestFactory;

/** @var ResponseFactoryInterface */
private $responseFactory;

/** @var StreamFactoryInterface */
private $streamFactory;

public function __construct(
RequestFactoryInterface $requestFactory,
ResponseFactoryInterface $responseFactory,
StreamFactoryInterface $streamFactory
) {
$this->requestFactory = $requestFactory;
$this->responseFactory = $responseFactory;
$this->streamFactory = $streamFactory;
}

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 createStream(string $content = ''): StreamInterface
{
return $this->streamFactory->createStream($content);
}

public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
{
return $this->streamFactory->createStreamFromFile($filename, $mode);
}

public function createStreamFromResource($resource): StreamInterface
{
return $this->streamFactory->createStreamFromResource($resource);
}
}
25 changes: 25 additions & 0 deletions tests/Application/src/Payum/HttpClient/HttpClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Tests\FluxSE\SyliusPayumStripePlugin\App\Payum\HttpClient;

use Payum\Core\HttpClientInterface;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

final class HttpClient implements HttpClientInterface
{
/** @var ClientInterface */
private $client;
public function __construct(ClientInterface $client)
{
$this->client = $client;
}

public function send(RequestInterface $request): ResponseInterface
{
return $this->client->sendRequest($request);
}
}

0 comments on commit b7ab104

Please sign in to comment.