Skip to content

Commit 0a275a2

Browse files
authored
Merge pull request #5 from rezzza/feature/support-event
Support events of moco
2 parents f3d4709 + b4e0d2a commit 0a275a2

File tree

6 files changed

+115
-3
lines changed

6 files changed

+115
-3
lines changed

.atoum.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
This file will automatically be included before EACH run.
5+
6+
Use it to configure atoum or anything that needs to be done before EACH run.
7+
8+
More information on documentation:
9+
[en] http://docs.atoum.org/en/latest/chapter3.html#configuration-files
10+
[fr] http://docs.atoum.org/fr/latest/lancement_des_tests.html#fichier-de-configuration
11+
*/
12+
13+
use \mageekguy\atoum;
14+
15+
$report = $script->addDefaultReport();
16+
17+
// This will add a green or red logo after each run depending on its status.
18+
$report->addField(new atoum\report\fields\runner\result\logo());
19+
$runner->addTestsFromDirectory(__DIR__.'/tests/units');

.bootstrap.atoum.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
This file will automatically be included before EACH test if -bf/--bootstrap-file argument is not used.
5+
6+
Use it to initialize the tested code, add autoloader, require mandatory file, or anything that needs to be done before EACH test.
7+
8+
More information on documentation:
9+
[en] http://docs.atoum.org/en/latest/chapter3.html#bootstrap-file
10+
[fr] http://docs.atoum.org/fr/latest/lancement_des_tests.html#fichier-de-bootstrap
11+
*/
12+
13+
14+
// AUTOLOADER
15+
16+
// composer
17+
require __DIR__ . '/vendor/autoload.php';
18+

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ before_script:
1010
- bin/install-moco.sh
1111

1212
script:
13+
- vendor/bin/atoum
1314
- vendor/bin/behat -f progress

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
},
2020
"require-dev": {
2121
"rezzza/rest-api-behat-extension": "^3.1",
22-
"symfony/process": "^3.0"
22+
"symfony/process": "^3.0",
23+
"atoum/atoum": "^2.8"
2324
},
2425
"bin": ["bin/install-moco.sh"]
2526
}

src/MocoWriter.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@ public function __construct($jsonFile, $hostname, $port)
1919
$this->port = $port;
2020
}
2121

22-
public function mockHttpCall(array $matchedRequest, array $mockedResponse)
22+
public function mockHttpCall(array $matchedRequest, array $mockedResponse, array $events = [])
2323
{
24-
$this->payload[] = [
24+
$entry = [
2525
"request" => $matchedRequest,
2626
"response" => $mockedResponse
2727
];
28+
29+
if (0 < count($events)) {
30+
$entry['on'] = $events;
31+
}
32+
33+
$this->payload[] = $entry;
2834
}
2935

3036
public function writeForMoco()

tests/units/MocoWriter.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace Rezzza\MocoBehatExtension\Tests\Units;
4+
5+
use mageekguy\atoum;
6+
7+
class MocoWriter extends atoum
8+
{
9+
public function test_it_should_write_request_and_response()
10+
{
11+
$this
12+
->given(
13+
$this->newTestedInstance('fixtures.json', '127.0.0.1', '8888'),
14+
$this->function->file_put_contents = true,
15+
$this->function->stream_socket_client = true,
16+
$this->testedInstance->mockHttpCall(['uri' => '/coucou'], ['status' => '404'])
17+
)
18+
->when(
19+
$this->testedInstance->writeForMoco()
20+
)
21+
->then
22+
->function('file_put_contents')
23+
->wasCalledWithArguments('fixtures.json', json_encode([['request' => ['uri' => '/coucou'], 'response' => ['status' => '404']]]))
24+
->once()
25+
;
26+
}
27+
28+
public function test_it_should_reset_payload_to_moco()
29+
{
30+
$this
31+
->given(
32+
$this->newTestedInstance('fixtures.json', '127.0.0.1', '8888'),
33+
$this->function->file_put_contents = true,
34+
$this->function->stream_socket_client = true,
35+
$this->testedInstance->mockHttpCall(['uri' => '/coucou'], ['status' => '404'])
36+
)
37+
->when(
38+
$this->testedInstance->reset()
39+
)
40+
->then
41+
->function('file_put_contents')
42+
->wasCalledWithArguments('fixtures.json', json_encode([]))
43+
->once()
44+
;
45+
}
46+
47+
public function test_it_should_write_events_if_present()
48+
{
49+
$this
50+
->given(
51+
$this->newTestedInstance('fixtures.json', '127.0.0.1', '8888'),
52+
$this->function->file_put_contents = true,
53+
$this->function->stream_socket_client = true,
54+
$this->testedInstance->mockHttpCall(['uri' => '/coucou'], ['status' => '404'], ['complete' => 'ok'])
55+
)
56+
->when(
57+
$this->testedInstance->writeForMoco()
58+
)
59+
->then
60+
->function('file_put_contents')
61+
->wasCalledWithArguments('fixtures.json', json_encode([
62+
['request' => ['uri' => '/coucou'], 'response' => ['status' => '404'], 'on' => ['complete' => 'ok']]
63+
]))
64+
->once()
65+
;
66+
}
67+
}

0 commit comments

Comments
 (0)