Skip to content

Commit

Permalink
Re-add faker seed + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed May 23, 2019
1 parent 5890893 commit d2901e5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
- Add tests for bindings and bindings prefixes
- Add tests for config overrides
- Add tests for faker seed
- Add tests on output (deterministic)
- Bring `bindings` outside of `response_calls`
- Should `routes.*.apply.response_calls.headers` be replaced by `routes.*.apply.headers`?
7 changes: 7 additions & 0 deletions config/apidoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,11 @@
*/
'serializer' => null,
],

/*
* If you would like the package to generate the same example values for parameters on each run,
* set this to any number (eg. 1234)
*
*/
'faker_seed' => null,
];
24 changes: 24 additions & 0 deletions tests/Unit/GeneratorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,30 @@ public function can_parse_multiple_response_file_tags_with_status_codes()
unlink(storage_path('response_error_test.json'));
}

/** @test */
public function generates_consistent_examples_when_faker_seed_is_set()
{
$route = $this->createRoute('GET', '/withBodyParameters', 'withBodyParameters');

$paramName = 'room_id';
$results = [];
$results[$this->generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
$results[$this->generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
$results[$this->generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
$results[$this->generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
$results[$this->generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
// Examples should have different values
$this->assertNotEquals(count($results), 1);

$generator = new Generator(12345);
$results = [];
$results[$generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
$results[$generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
$results[$generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
$results[$generator->processRoute($route)['cleanBodyParameters'][$paramName]] = true;
// Examples should have same values
$this->assertEquals(count($results), 1);
}
/** @test */
public function uses_configured_settings_when_calling_route()
{
Expand Down

0 comments on commit d2901e5

Please sign in to comment.