Skip to content

Commit fa9c531

Browse files
committed
upd readme, add getSimulation method
1 parent 03d25d4 commit fa9c531

File tree

2 files changed

+50
-22
lines changed

2 files changed

+50
-22
lines changed

README.md

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66
PHP Client for [hoverfly](https://hoverfly.io/) based on [java version](https://github.com/SpectoLabs/hoverfly-java).
77

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.
915

1016
## Installation
1117

@@ -15,6 +21,9 @@ $ composer require ns3777k/hoverfly
1521

1622
## Example
1723

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+
1827
```php
1928
<?php
2029

@@ -23,26 +32,38 @@ require_once __DIR__ . '/vendor/autoload.php';
2332
use Hoverfly\Client;
2433
use Hoverfly\Model\Response;
2534

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;
4138

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+
```
4465

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

src/Client.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ public function deleteSimulation(): Simulation
215215
return $this->mapper->map($response, new Simulation());
216216
}
217217

218+
public function getSimulation(): Simulation
219+
{
220+
$response = $this->getJson('/api/v2/simulation');
221+
222+
return $this->mapper->map($response, new Simulation());
223+
}
224+
218225
/**
219226
* @param StubServiceBuilder ...$builders
220227
*

0 commit comments

Comments
 (0)