GuzzleSoapClientDriverTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 7
dl 0
loc 45
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testSend() 0 40 1
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatEET\Driver;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Psr7\Request;
7
use GuzzleHttp\Psr7\Response;
8
use PHPUnit\Framework\TestCase;
9
use const SOAP_1_1;
10
11
class GuzzleSoapClientDriverTest extends TestCase
12
{
13
14
	public function testSend(): void
15
	{
16
		$requestData = 'fooData';
17
		$responseData = 'responseData';
18
		$location = 'https://pg.eet.cz';
19
		$soapAction = 'fooAction';
20
21
		$guzzleHttpClient = $this->createMock(Client::class);
22
		$guzzleHttpClient
23
			->expects(self::once())
24
			->method('send')
25
			->with(self::callback(function (Request $request) use ($requestData, $location, $soapAction) {
26
				$this->assertEquals([
27
					'Host' => [
28
						'pg.eet.cz',
29
					],
30
					'User-Agent' => [
31
						GuzzleSoapClientDriver::HEADER_USER_AGENT,
32
					],
33
					'Content-Type' => [
34
						'text/xml; charset=utf-8',
35
					],
36
					'SOAPAction' => [
37
						$soapAction,
38
					],
39
					'Content-Length' => [
40
						strlen($requestData),
41
					],
42
				], $request->getHeaders());
43
				$this->assertEquals($location, (string) $request->getUri());
44
45
				return true;
46
			}))
47
			->willReturn(new Response(200, [], $responseData));
48
49
		$guzzleSoapClientDriver = new GuzzleSoapClientDriver($guzzleHttpClient);
0 ignored issues
show
Documentation introduced by
$guzzleHttpClient is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<GuzzleHttp\Client>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
		$response = $guzzleSoapClientDriver->send($requestData, $location, $soapAction, SOAP_1_1);
51
52
		$this->assertSame($responseData, $response);
53
	}
54
55
}
56