Skip to content

Commit

Permalink
Merge pull request #58 from thibaut-algrin/master
Browse files Browse the repository at this point in the history
Update Package
  • Loading branch information
rpkamp authored Jan 19, 2024
2 parents dafb05c + 6ca5fa3 commit 18c3af6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"ext-iconv": "*",
"php-http/client-implementation": "^1.0",
"php-http/httplug": "^1.0|^2.0",
"php-http/message-factory": "^1.0",
"psr/http-message": "^1.0"
"psr/http-message": "^2.0",
"psr/http-factory": "^1.0"
},
"require-dev": {
"phpmd/phpmd": "^2.9.1",
Expand All @@ -40,5 +40,11 @@
"php-parallel-lint/php-parallel-lint": "^1.2",
"egulias/email-validator": "^2.1.23",
"symfony/mailer": "^5.0"
},
"config": {
"allow-plugins": {
"php-http/discovery": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
30 changes: 20 additions & 10 deletions src/MailhogClient.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?php

declare(strict_types=1);

namespace rpkamp\Mailhog;

use Generator;
use Http\Client\HttpClient;
use Http\Message\RequestFactory;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use rpkamp\Mailhog\Message\Message;
use rpkamp\Mailhog\Message\MessageFactory;
use rpkamp\Mailhog\Specification\Specification;
Expand All @@ -22,24 +24,34 @@
class MailhogClient
{
/**
* @var HttpClient
* @var ClientInterface
*/
private $httpClient;

/**
* @var RequestFactory
* @var RequestFactoryInterface
*/
private $requestFactory;

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

/**
* @var string
*/
private $baseUri;

public function __construct(HttpClient $client, RequestFactory $requestFactory, string $baseUri)
{
public function __construct(
ClientInterface $client,
RequestFactoryInterface $requestFactory,
StreamFactoryInterface $streamFactory,
string $baseUri
) {
$this->httpClient = $client;
$this->requestFactory = $requestFactory;
$this->streamFactory = $streamFactory;
$this->baseUri = rtrim($baseUri, '/');
}

Expand Down Expand Up @@ -165,12 +177,10 @@ public function releaseMessage(string $messageId, string $host, int $port, strin

$request = $this->requestFactory->createRequest(
'POST',
sprintf('%s/api/v1/messages/%s/release', $this->baseUri, $messageId),
[],
$body
sprintf('%s/api/v1/messages/%s/release', $this->baseUri, $messageId)
);

$this->httpClient->sendRequest($request);
$this->httpClient->sendRequest($request->withBody($this->streamFactory->createStream($body)));
}

public function getMessageById(string $messageId): Message
Expand Down
9 changes: 7 additions & 2 deletions tests/integration/MailhogClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use Generator;
use Http\Client\Curl\Client;
use Nyholm\Psr7\Factory\HttplugFactory;
use Nyholm\Psr7\Factory\Psr17Factory;
use PHPUnit\Framework\TestCase;
use rpkamp\Mailhog\MailhogClient;
use rpkamp\Mailhog\Message\Mime\Attachment;
Expand Down Expand Up @@ -35,7 +35,12 @@ class MailhogClientTest extends TestCase

public function setUp(): void
{
$this->client = new MailhogClient(new Client(), new HttplugFactory(), $_ENV['mailhog_api_uri']);
$this->client = new MailhogClient(
new Client(),
new Psr17Factory(),
new Psr17Factory(),
$_ENV['mailhog_api_uri']
);
$this->client->purgeMessages();
}

Expand Down
5 changes: 3 additions & 2 deletions tests/unit/MailhogClientTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

declare(strict_types=1);

namespace rpkamp\Mailhog\Tests\unit;

use Http\Client\Curl\Client;
use Http\Message\MessageFactory\GuzzleMessageFactory;
use Nyholm\Psr7\Factory\Psr17Factory;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use rpkamp\Mailhog\MailhogClient;
Expand All @@ -16,7 +17,7 @@ final class MailhogClientTest extends TestCase
*/
public function it_should_remove_trailing_slashes_from_base_uri(): void
{
$client = new MailhogClient(new Client(), new GuzzleMessageFactory(), 'http://mailhog/');
$client = new MailhogClient(new Client(), new Psr17Factory(), new Psr17Factory(), 'http://mailhog/');

$property = new ReflectionProperty($client, 'baseUri');
$property->setAccessible(true);
Expand Down

0 comments on commit 18c3af6

Please sign in to comment.