-
Notifications
You must be signed in to change notification settings - Fork 2
/
AbstractClientTest.php
70 lines (57 loc) · 1.99 KB
/
AbstractClientTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* @author Timo Förster <tfoerster@webfoersterei.de>
* @date 18.07.18
*/
namespace Webfoersterei\DomainBestellSystemApiClient\Tests;
use PHPUnit\Framework\TestCase;
use Webfoersterei\DomainBestellSystemApiClient\Client\DomainClient;
use Webfoersterei\DomainBestellSystemApiClient\Client\NameServerClient;
abstract class AbstractClientTest extends TestCase
{
/**
* @param $method
* @param mixed $response Most probably a stdClass (@see createStdClassFromApiResponse)
* @return \PHPUnit\Framework\MockObject\MockObject|\SoapClient
*/
protected function getSoapClient($method, $response)
{
$stub = $this->getMockFromWsdl(__DIR__.'/Resources/soap.wsdl');
$stub->expects($this->once())->method('__soapCall')
->with(
$this->equalTo($method),
$this->isType('array') // parameters
)
->willReturn($response);
return $stub;
}
/**
* Hack to return stdClass of api returnValue only (for XML-Mocks)
* @param $apiXmlResponseString
* @return mixed
*/
protected function createStdClassFromApiResponse($apiXmlResponseString)
{
$xml = preg_replace('/(<\/?)([\w-]+):([^>]*>)/', '$1$2$3', $apiXmlResponseString);
$returnValueInXml = (new \SimpleXMLElement($xml))->xpath('//return')[0];
return json_decode(json_encode($returnValueInXml));
}
/**
* @param \SoapClient $soapClient
* @return NameServerClient
*/
protected function getNameServerClient($soapClient): NameServerClient
{
SoapMockClientFactory::setSoapClient($soapClient);
return SoapMockClientFactory::createNameServerClient(null, null, null);
}
/**
* @param \SoapClient $soapClient
* @return DomainClient
*/
protected function getDomainClient($soapClient): DomainClient
{
SoapMockClientFactory::setSoapClient($soapClient);
return SoapMockClientFactory::createDomainClient(null, null, null);
}
}