5
5
6
6
PHP Client for [ hoverfly] ( https://hoverfly.io/ ) based on [ java version] ( https://github.com/SpectoLabs/hoverfly-java ) .
7
7
8
- *** Project is under heavy development! API may change in future!***
8
+ ## Why I would use it for?
9
+
10
+ Consider having a functional test that sends a request to the application. While handling the request application can
11
+ use multiple external services like forecast, billing or booking system. We don't wanna test external services because
12
+ they are not stable, require an internet connection, can limit request rate per second and add delay. During the test we
13
+ just want ** something** to respond to our requests according to the specification, it does not have to be a real service
14
+ and that's where hoverfly and this client come in.
9
15
10
16
## Installation
11
17
@@ -15,6 +21,9 @@ $ composer require ns3777k/hoverfly
15
21
16
22
## Example
17
23
24
+ Your tests have to be configured to use hoverfly proxy server (use ` HTTP_PROXY ` ) and ignore proxy for itself (use
25
+ ` NO_PROXY ` ).
26
+
18
27
``` php
19
28
<?php
20
29
@@ -23,26 +32,38 @@ require_once __DIR__ . '/vendor/autoload.php';
23
32
use Hoverfly\Client;
24
33
use Hoverfly\Model\Response;
25
34
26
- $client = new Client();
27
- $client->simulate(
28
- $client->buildSimulation()
29
- ->serviceExact('test.ru')
30
- ->getExact('/test')
31
- ->withState('customer', 'individual')
32
- ->willReturn(
33
- Response::json(['test' => true])
34
- ->setDelay(3000)
35
- ->addTransitionsState('step', 'order')
36
- ->addTransitionsState('customer', 'individual')
37
- ->addRemovesState('basket')
38
- )
39
- );
40
- ```
35
+ class SomeTest
36
+ {
37
+ private $hoverfly;
41
38
42
- ## TODO: Basic
43
- 1 . Write tests
39
+ public function _before()
40
+ {
41
+ $this->hoverfly = new Client(['base_uri' => getenv('HOVERFLY_URL')]);
42
+ $this->hoverfly->deleteSimulation();
43
+ }
44
+
45
+ public function testFeature(ApiTester $I)
46
+ {
47
+ $this->hoverfly->simulate(
48
+ $this->hoverfly->buildSimulation()
49
+ ->serviceExact('test.ru')
50
+ ->getExact('/test')
51
+ ->withState('customer', 'individual')
52
+ ->willReturn(
53
+ Response::json(['test' => true])
54
+ ->setDelay(3000)
55
+ ->addTransitionsState('step', 'order')
56
+ ->addTransitionsState('customer', 'individual')
57
+ ->addRemovesState('basket')
58
+ )
59
+ );
60
+
61
+ $I->sendPOST('/api/v1/faq/9999999/dislike', ['comment' => 'test']);
62
+ }
63
+ }
64
+ ```
44
65
45
- ## TODO: Advanced
46
- 1 . Implement the rest of API
47
- 2 . Implement phpunit integration?
48
- 3 . Implement codeception integration?
66
+ ## Coming soon
67
+ 1 . Journal API
68
+ 2 . Verify method
69
+ 3 . Write tests
0 commit comments