PHP code example of loophp / mock-soapclient
1. Go to this page and download the library: Download loophp/mock-soapclient library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
loophp / mock-soapclient example snippets
oophp\MockSoapClient\MockSoapClient;
$responses = ['a', 'b', 'c'];
$client = new MockSoapClient($responses);
$client->foo(); // a
$client->bar(); // b
$client->w00t(); // c
$client->foobar(); // a
$client->barfoo(); // b
$client->plop(); // c
oophp\MockSoapClient\MockSoapClient;
$responses = static function ($method, $arguments) {
return $method;
};
$client = new MockSoapClient($responses);
$client->foo(); // foo
$client->bar(); // bar
$client->w00t(); // w00t
$client->foobar(); // foobar
$client->barfoo(); // barfoo
$client->plop(); // plop
declare(strict_types=1);
oapClient;
$responses = static function ($method, $arguments) {
switch ($method) {
case 'foo':
return 'foo_method';
case 'bar':
return 'bar_method';
}
throw new SoapFault('Server', sprintf('Unknown SOAP method "%s"', $method));
};
$client = new MockSoapClient($responses);
$client->foo(); // foo_method
$client->__soapCall('foo', []); // foo_method
$client->bar(); // bar_method
$client->__soapCall('bar', []); // bar_method
$client->w00t(); // Throws exception SoapFault.
$client->__soapCall('w00t', []); // Throws exception SoapFault.
oophp\MockSoapClient\MockSoapClient;
$responses = [
static function (string $method, array $arguments) {
return '00' . $method;
},
static function (string $method, array $arguments) {
return '11' . $method;
},
static function (string $method, array $arguments) {
throw new SoapFault('Server', 'Server');
},
];
$client = new MockSoapClient($responses);
$client->foo(); // 00foo
$client->bar(); // 11bar
$client->w00t(); // SoapFault exception.
declare(strict_types=1);
oapClient;
$responses = [
'a',
'b',
'c',
'a' => 'aaa',
'b' => [
'bbb1',
'bbb2',
],
'c' => [
static function ($method, $arguments) {
return 'ccc1';
},
static function ($method, $arguments) {
return 'ccc2';
},
],
];
$client = new MockSoapClient($responses);
$client->foo(); // a
$client->foo(); // b
$client->foo(); // c
$client->foo(); // a
$client->a(); // aaa
$client->a(); // aaa
$client->b(); // bbb1
$client->b(); // bbb2
$client->b(); // bbb1
$client->c(); // ccc1
$client->c(); // ccc2
$client->c(); // ccc1