Skip to content

Commit d52728d

Browse files
authored
doc(v1): reworked testing(fake), commands & index documentation (#17)
1 parent 1dcd71a commit d52728d

File tree

10 files changed

+231
-275
lines changed

10 files changed

+231
-275
lines changed

docs/commands.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# :fontawesome-solid-journal-whills: **Commands**
2+
3+
---
4+
Yes this package comes with some artisan commands to make soap a bit more enjoyable.
5+
6+
---
7+
![alt text](https://forum.endeavouros.com/uploads/default/original/2X/5/55b7271051f1bfcdcafcfd56e6704dade6936e1f.png "Artisan Commands"){: style="height:auto;width:100%"}
8+
9+
---
10+
## :fontawesome-brands-jedi-order: **Requirements**
11+
12+
You need to install following package to use the code generation feature
13+
14+
````bash
15+
composer require --dev laminas/laminas-code wsdl2phpgenerator/wsdl2phpgenerator
16+
````
17+
18+
## :fontawesome-brands-jedi-order: **Overview**
19+
20+
Command | Description
21+
---------------------------------- | -------------
22+
`php artisan soap:make:client` | Create a customized client by wsdl or config name
23+
`php artisan soap:make:validation` | Create one or all validation classes by wsdl or config name
24+
25+
## :fontawesome-brands-jedi-order: **Configuration**
26+
27+
If you have published the configuration file then you have some options for the code generation.
28+
29+
Config | Default | Description
30+
------------------ | ------------------ | -----------
31+
``code.path`` | `app_path('Soap')` | Define where the generated Code should be saved in your project
32+
``code.namespace`` | `App\\Soap` | Define the namespace of the generated Code

docs/commands/make-client.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

docs/commands/make-validation.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

docs/commands/overview.md

Lines changed: 0 additions & 29 deletions
This file was deleted.

docs/index.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1-
# Introduction
1+
# :fontawesome-solid-journal-whills: **Get started**
22

3+
---
34
This package provides an expressive, minimal API around the [Soap Client from Phpro](https://github.com/phpro/soap-client), allowing you to quickly make outgoing SOAP requests to communicate with other web applications.
5+
6+
---
7+
![alt text](https://www.netways.de/wp-content/uploads/2009/12/6a00d8341d3df553ef012875f312f9970c-800wi.jpg "Laravel Soap"){: style="height:auto;width:100%"}
8+
9+
---
10+
## :fontawesome-brands-jedi-order: **Introduction**
11+
412
It is using [HTTPplug](http://httplug.io/) as handler with [Guzzle](https://github.com/php-http/guzzle6-adapter) as client.
513
Some code is based/copied on/from [Laravel Http wrapper](https://github.com/illuminate/http). Thanks for inspiration :-)
14+
15+
## :fontawesome-brands-jedi-order: **Installation**
16+
17+
!!! abstract "Package"
18+
Execute the following command to get the latest version of the package:
19+
````bash
20+
composer require codedredd/laravel-soap
21+
````
22+
23+
!!! info "Configuration"
24+
Publish Configuration
25+
```bash
26+
php artisan vendor:publish --provider "CodeDredd\Soap\SoapServiceProvider"
27+
```
28+
29+
!!! warning "Code generation feature"
30+
If you also want to use the code generation feature you have to install following packages:
31+
````bash
32+
composer require --dev laminas/laminas-code wsdl2phpgenerator/wsdl2phpgenerator
33+
````

docs/installation.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

docs/testing.md

Lines changed: 163 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,195 @@
11
# :fontawesome-solid-journal-whills: **Testing**
22

3-
Many Laravel services provide functionality to help you easily and expressively write tests, and this SOAP wrapper is no exception.
3+
---
4+
Many Laravel services provide functionality to help you easily and expressively write tests,
5+
and this SOAP wrapper is no exception.
46

7+
---
8+
![alt text](https://image.slidesharecdn.com/agilelessonsfromstarwarsapil17-170125183657/95/agile-lessons-to-learn-from-star-wars-15-638.jpg?cb=1485369462 "Testing"){: style="height:auto;width:100%"}
9+
10+
---
511
## :fontawesome-brands-jedi-order: **Faking**
612

7-
The `Soap` facade's `fake` method allows you to instruct the SOAP client to return stubbed / dummy responses when requests are made.
13+
Include `#!php-inline use CodeDredd\Soap\Facades\Soap` in your testing class.
14+
The `Soap` facade's `fake` method allows you to instruct the SOAP client to return stubbed / dummy responses
15+
when requests are made.
16+
17+
### :fontawesome-solid-jedi: ***fake***
18+
19+
> Intercepts request with possible given responses
20+
21+
!!! info ""
22+
- **`Method`** : `#!php-inline function fake($callback = null)`
23+
- **`Param`** : `#!php-inline callable|array $callback`
24+
- **`Return`** : `#!php-inline \CodeDredd\Soap\SoapFactory`
25+
26+
!!! example "Examples with Soap::response"
27+
=== "simple"
28+
For returning empty `200` status code responses for every request, you may call the `fake` method with no arguments
29+
``` php-inline
30+
Soap::fake();
31+
```
32+
=== "with arguments"
33+
You may pass an array to the `fake` method. The array's keys should represent ACTION patterns that you wish to fake and their associated responses. The `*` character may be used as a wildcard character. You may use the `response` method to construct stub / fake responses for these endpoints
34+
```` php-inline
35+
Soap::fake([
36+
// Stub a JSON response for all Get_ actions...
37+
'Get_*' => Soap::response(['foo' => 'bar'], 200, ['Headers']),
38+
39+
// Stub a string response for Submit_User action
40+
'Submit_User' => Soap::response('Hello World', 200, ['Headers']),
41+
]);
42+
````
43+
44+
!!! warning "Difference between Laravel Http"
45+
The difference between Laravels HTTP wrapper is the fact that actions which are not defined in fake are also faked with a default 200 response!
46+
47+
=== "overwrite default response"
48+
``` php-inline
49+
Soap::fake([
50+
// Stub a JSON response for all Get_ actions...
51+
'Get_*' => Soap::response(['foo' => 'bar'], 200, ['Headers']),
52+
53+
// Stub a string response for all other actions
54+
'*' => Soap::response('Hello World', 200, ['Headers']),
55+
]);
56+
```
57+
=== "with callback"
58+
If you require more complicated logic to determine what responses to return for certain endpoints, you may pass a callback to the `fake` method. This callback will receive an instance of `CodeDredd\Soap\Client\Request` and should return a response instance:
59+
``` php-inline
60+
Soap::fake(function ($request) {
61+
return Soap::response('Hello World', 200);
62+
});
63+
```
64+
65+
!!! example "Examples with Soap::sequence"
66+
=== "simple"
67+
Sometimes you may need to specify that a single ACTION should return a series of fake responses in a specific order. You may accomplish this by using the `Soap::sequence` method to build the responses:
68+
```` php-inline
69+
Soap::fake([
70+
// Stub a series of responses for Get_* actions...
71+
'Get_*' => Soap::sequence()
72+
->push('Hello World')
73+
->push(['foo' => 'bar'])
74+
->pushStatus(404)
75+
]);
76+
````
77+
78+
!!! warning "Throws exception if empty"
79+
When all of the responses in a response sequence have been consumed, any further requests will cause the response sequence to throw an exception!
80+
81+
=== "wtih whenEmpty"
82+
If you would like to specify a default response that should be returned when a sequence is empty, you may use the `whenEmpty` method
83+
``` php-inline
84+
Soap::fake([
85+
// Stub a series of responses for Get_* actions...
86+
'Get_*' => Soap::sequence()
87+
->push('Hello World')
88+
->push(['foo' => 'bar'])
89+
->whenEmpty(Soap::response())
90+
]);
91+
```
92+
93+
### :fontawesome-solid-jedi: ***response***
894

9-
### Simple Fake
10-
For example, to instruct the SOAP client to return empty, `200` status code responses for every request, you may call the `fake` method with no arguments:
95+
> Create a new response instance for use during stubbing (for fake responses)
1196
12-
use CodeDredd\Soap\Facades\Soap;
97+
!!! info ""
1398

14-
Soap::fake();
99+
- **`Method`** : `#!php-inline static function response($body = null, $status = 200, $headers = [])`
100+
- **`Param`** : `#!php-inline array|string|null $body`
101+
- **`Param`** : `#!php-inline int $status`
102+
- **`Param`** : `#!php-inline array $headers`
103+
- **`Return`** : `#!php-inline \GuzzleHttp\Promise\PromiseInterface`
15104

16-
$response = Soap::baseWsdl(...)->call(...);
105+
!!! warning "When `$body` is string"
106+
One important notice. Because a SOAP API doesn't return a single string value every response with only a string in the body is wrapped in an array with key `response`.
107+
108+
[
109+
'response' => 'Hello World'
110+
]
17111

18-
### Faking Specific URLs
112+
### :fontawesome-solid-jedi: ***sequence***
19113

20-
Alternatively, you may pass an array to the `fake` method. The array's keys should represent ACTION patterns that you wish to fake and their associated responses. The `*` character may be used as a wildcard character. You may use the `response` method to construct stub / fake responses for these endpoints:
21-
The difference between Laravels HTTP wrapper is the fact that actions which are not defined in fake are also faked with a default 200 response!
22-
Also a faked response status code is always 200 if you define it in the range between 200 and 400. Status codes 400 and greater are correct responded.
114+
> Get an invokable object that returns a sequence of responses in order for use during stubbing
23115
24-
Soap::fake([
25-
// Stub a JSON response for all Get_ actions...
26-
'Get_*' => Soap::response(['foo' => 'bar'], 200, ['Headers']),
116+
!!! info ""
117+
- **`Method`** : `#!php-inline function sequence(array $responses = [])`
118+
- **`Return`** : `#!php-inline \CodeDredd\Soap\Client\ResponseSequence`
119+
120+
#### :fontawesome-brands-galactic-republic: ***push***
27121

28-
// Stub a string response for Submit_User action
29-
'Submit_User' => Soap::response('Hello World', 200, ['Headers']),
30-
]);
122+
> Push a response to the sequence.
31123
32-
If you would like to overwrite the fallback ACTION pattern that will stub all unmatched URLs, you may use a single `*` character:
124+
!!! info ""
125+
- **`Method`** : `#!php-inline function push($body = '', int $status = 200, array $headers = [])`
126+
- **`Return`** : `#!php-inline \CodeDredd\Soap\Client\ResponseSequence`
33127

34-
Soap::fake([
35-
// Stub a JSON response for all Get_ actions...
36-
'Get_*' => Soap::response(['foo' => 'bar'], 200, ['Headers']),
128+
#### :fontawesome-brands-galactic-republic: ***pushResponse***
37129

38-
// Stub a string response for all other actions
39-
'*' => Soap::response('Hello World', 200, ['Headers']),
40-
]);
130+
> Push a response to the sequence.
41131
42-
One important notice. Because a SOAP API doesn't return only string every response with only a string in the body will be formatted to an array:
132+
!!! info ""
133+
- **`Method`** : `#!php-inline function pushResponse($response)`
134+
- **`Param`** : `#!php-inline \GuzzleHttp\Promise\PromiseInterface|\Closure $response`
135+
- **`Return`** : `#!php-inline \CodeDredd\Soap\Client\ResponseSequence`
136+
137+
#### :fontawesome-brands-galactic-republic: ***pushStatus***
43138

44-
//For above example
45-
[
46-
'response' => 'Hello World'
47-
]
139+
> Push a response with the given status code to the sequence.
48140
49-
### Faking Response Sequences
141+
!!! info ""
142+
- **`Method`** : `#!php-inline function pushStatus(string $filePath, int $status = 200, array $headers = [])`
143+
- **`Return`** : `#!php-inline \CodeDredd\Soap\Client\ResponseSequence`
144+
145+
#### :fontawesome-brands-galactic-republic: ***dontFailWhenEmpty***
50146

51-
Sometimes you may need to specify that a single ACTION should return a series of fake responses in a specific order. You may accomplish this by using the `Soap::sequence` method to build the responses:
147+
> Make the sequence return a default response when it is empty.
52148
53-
Soap::fake([
54-
// Stub a series of responses for Get_* actions...
55-
'Get_*' => Soap::sequence()
56-
->push('Hello World')
57-
->push(['foo' => 'bar'])
58-
->pushStatus(404)
59-
]);
149+
!!! info ""
150+
- **`Method`** : `#!php-inline function dontFailWhenEmpty()`
151+
- **`Return`** : `#!php-inline \CodeDredd\Soap\Client\ResponseSequence`
152+
153+
#### :fontawesome-brands-galactic-republic: ***whenEmpty***
60154

61-
When all of the responses in a response sequence have been consumed, any further requests will cause the response sequence to throw an exception. If you would like to specify a default response that should be returned when a sequence is empty, you may use the `whenEmpty` method:
155+
> Make the sequence return a custom default response when it is empty.
62156
63-
Soap::fake([
64-
// Stub a series of responses for Get_* actions...
65-
'Get_*' => Soap::sequence()
66-
->push('Hello World')
67-
->push(['foo' => 'bar'])
68-
->whenEmpty(Soap::response())
69-
]);
157+
!!! info ""
158+
- **`Method`** : `#!php-inline function whenEmpty($response)`
159+
- **`Param`** : `#!php-inline \GuzzleHttp\Promise\PromiseInterface|\Closure $response`
160+
- **`Return`** : `#!php-inline \CodeDredd\Soap\Client\ResponseSequence`
161+
162+
#### :fontawesome-brands-galactic-republic: ***pushFile***
70163

71-
If you would like to fake a sequence of responses but do not need to specify a specific ACTION pattern that should be faked, you may use the `Soap::fakeSequence` method:
164+
> Push response with the contents of a file as the body to the sequence.
72165
73-
Soap::fakeSequence()
74-
->push('Hello World')
75-
->whenEmpty(Soap::response());
166+
!!! info ""
167+
- **`Method`** : `#!php-inline function pushFile(int $status = 200, array $headers = [])`
168+
- **`Return`** : `#!php-inline \CodeDredd\Soap\Client\ResponseSequence`
76169

77-
### Fake Callback
170+
### :fontawesome-solid-jedi: ***fakeSequence***
78171

79-
If you require more complicated logic to determine what responses to return for certain endpoints, you may pass a callback to the `fake` method. This callback will receive an instance of `CodeDredd\Soap\Client\Request` and should return a response instance:
172+
If you would like to fake a sequence of responses but do not need to specify a specific ACTION pattern that should be faked, you may use the `Soap::fakeSequence` method.
80173

81-
Soap::fake(function ($request) {
82-
return Soap::response('Hello World', 200);
83-
});
174+
> Register a response sequence for the given URL pattern.
84175
85-
------------------------
176+
!!! info ""
177+
- **`Method`** : `#!php-inline function fakeSequence(string $url = '*')`
178+
- **`Return`** : `#!php-inline \CodeDredd\Soap\Client\ResponseSequence`
179+
180+
!!! example "Example"
181+
``` php-inline
182+
Soap::fakeSequence()
183+
->push('Hello World')
184+
->whenEmpty(Soap::response());
185+
```
186+
187+
!!! tip "Tip"
188+
``fakeSequence`` has the same methods as [`Soap::response`](#response).
189+
So in most cases `fakeSequence` will be the better choice to fake response because its an easier and shorter
190+
way to define fake responses.
191+
192+
---
86193

87194
## :fontawesome-brands-jedi-order: **Asserts**
88195

0 commit comments

Comments
 (0)