Skip to content

Commit d2901e5

Browse files
committed
Re-add faker seed + tests
1 parent 5890893 commit d2901e5

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
- Add tests for bindings and bindings prefixes
22
- Add tests for config overrides
3-
- Add tests for faker seed
43
- Add tests on output (deterministic)
54
- Bring `bindings` outside of `response_calls`
65
- Should `routes.*.apply.response_calls.headers` be replaced by `routes.*.apply.headers`?

config/apidoc.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,11 @@
221221
*/
222222
'serializer' => null,
223223
],
224+
225+
/*
226+
* If you would like the package to generate the same example values for parameters on each run,
227+
* set this to any number (eg. 1234)
228+
*
229+
*/
230+
'faker_seed' => null,
224231
];

tests/Unit/GeneratorTestCase.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,30 @@ public function can_parse_multiple_response_file_tags_with_status_codes()
532532
unlink(storage_path('response_error_test.json'));
533533
}
534534

535+
/** @test */
536+
public function generates_consistent_examples_when_faker_seed_is_set()
537+
{
538+
$route = $this->createRoute('GET', '/withBodyParameters', 'withBodyParameters');
539+
540+
$paramName = 'room_id';
541+
$results = [];
542+
$results[$this->generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
543+
$results[$this->generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
544+
$results[$this->generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
545+
$results[$this->generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
546+
$results[$this->generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
547+
// Examples should have different values
548+
$this->assertNotEquals(count($results), 1);
549+
550+
$generator = new Generator(12345);
551+
$results = [];
552+
$results[$generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
553+
$results[$generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
554+
$results[$generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
555+
$results[$generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
556+
// Examples should have same values
557+
$this->assertEquals(count($results), 1);
558+
}
535559
/** @test */
536560
public function uses_configured_settings_when_calling_route()
537561
{

0 commit comments

Comments
 (0)