Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Fix request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
pepakriz authored and janlanger committed Dec 12, 2016
1 parent 5bcc885 commit 5d0a969
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Driver/GuzzleSoapClientDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class GuzzleSoapClientDriver implements SoapClientDriver
{

const DEFAULT_TIMEOUT = 2.5;
const HEADER_USER_AGENT = 'PHP';

/** @var \GuzzleHttp\Client */
private $httpClient;
Expand All @@ -26,10 +27,10 @@ public function __construct(\GuzzleHttp\Client $httpClient, float $connectionTim
public function send(string $request, string $location, string $action, int $soapVersion): string
{
$headers = [
'User-Agent: PHP',
sprintf('Content-Type: %s; charset=utf-8', $soapVersion === 2 ? 'application/soap+xml' : 'text/xml'),
sprintf('SOAPAction: %s', $action),
sprintf('Content-Length: %s', strlen($request)),
'User-Agent' => self::HEADER_USER_AGENT,
'Content-Type' => sprintf('%s; charset=utf-8', $soapVersion === 2 ? 'application/soap+xml' : 'text/xml'),
'SOAPAction' => $action,
'Content-Length' => strlen($request),
];

$request = new \GuzzleHttp\Psr7\Request('POST', $location, $headers, $request);
Expand Down
49 changes: 49 additions & 0 deletions tests/SlevomatEET/Driver/GuzzleSoapClientDriverTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php declare(strict_types = 1);

namespace SlevomatEET\Driver;

class GuzzleSoapClientDriverTest extends \PHPUnit\Framework\TestCase
{

public function testSend()
{
$requestData = 'fooData';
$responseData = 'responseData';
$location = 'https://pg.eet.cz';
$soapAction = 'fooAction';

$guzzleHttpClient = $this->createMock(\GuzzleHttp\Client::class);
$guzzleHttpClient
->expects(self::once())
->method('send')
->with(self::callback(function (\GuzzleHttp\Psr7\Request $request) use ($requestData, $location, $soapAction) {
$this->assertEquals([
'Host' => [
'pg.eet.cz',
],
'User-Agent' => [
GuzzleSoapClientDriver::HEADER_USER_AGENT,
],
'Content-Type' => [
'text/xml; charset=utf-8',
],
'SOAPAction' => [
$soapAction,
],
'Content-Length' => [
strlen($requestData),
],
], $request->getHeaders());
$this->assertEquals($location, (string) $request->getUri());

return true;
}))
->willReturn(new \GuzzleHttp\Psr7\Response(200, [], $responseData));

$guzzleSoapClientDriver = new GuzzleSoapClientDriver($guzzleHttpClient);
$response = $guzzleSoapClientDriver->send($requestData, $location, $soapAction, SOAP_1_1);

$this->assertSame($responseData, $response);
}

}

0 comments on commit 5d0a969

Please sign in to comment.