Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Slim4] Add array support to Data Mocker #4801

Merged
merged 4 commits into from
Dec 18, 2019

Conversation

ybelenko
Copy link
Contributor

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

mockArray method added to interface and implemented class. Mocker creates smallest arrays(single item when possible) to avoid huge JSON responses.

Related to #3545

How to test

  1. Checkout into feature branch
$ git checkout -b ybelenko-slim_data_mocker_array master
$ git pull https://github.com/ybelenko/openapi-generator.git slim_data_mocker_array
  1. Generate new Slim4 samples and go to just created build
$ mvn clean package
$ bin/php-slim4-server-petstore.sh
$ cd samples/server/petstore/php-slim4
  1. Start Composer installation and run unit tests
$ composer install
$ composer test
$ composer phpcs

cc @jebentier, @dkarlovi, @mandrean, @jfastnacht, @ackintosh, @renepardon

@ybelenko
Copy link
Contributor Author

I've made a small example of what do we have right now:

<?php
require __DIR__ . '/vendor/autoload.php';

use OpenAPIServer\Mock\OpenApiDataMocker as Mocker;
$mocker = new Mocker();
$data = [
    'Integer from 1 to 100' => $mocker->mockInteger(null, 1, 100),
    'Float from -3 to 3' =>  $mocker->mockNumber(null, -3, 3),
    'String 10 chars' => $mocker->mockString(null, 10, 10),
    'Boolean' =>  $mocker->mockBoolean(),
    'Array of strings' => $mocker->mockArray(
        [
            'type' => 'string',
            'maxLength' => 20,
        ]
    ),
];
echo json_encode($data, JSON_PRETTY_PRINT);

output:

{
    "Integer from 1 to 100": 89,
    "Float from -3 to 3": -1.1508,
    "String 10 chars": "Lorem ipsu",
    "Boolean": false,
    "Array of strings": [
        "Lorem ipsum dol"
    ]
}

@wing328
Copy link
Member

wing328 commented Dec 18, 2019

Start Composer installation and run unit tests

What about adding these steps to the CI tests in a separate PR?

I only saw tests for php-slim but not php-slim4 in the CI.

@wing328 wing328 merged commit 0ae1ea6 into OpenAPITools:master Dec 18, 2019
@ybelenko ybelenko deleted the slim_data_mocker_array branch December 18, 2019 02:00
@ybelenko
Copy link
Contributor Author

Start Composer installation and run unit tests

What about adding these steps to the CI tests in a separate PR?

I only saw tests for php-slim but not php-slim4 in the CI.

Where I should add them? I didn't know that CI runs any tests from samples.

@wing328
Copy link
Member

wing328 commented Dec 18, 2019

https://github.com/OpenAPITools/openapi-generator/blob/master/samples/server/petstore/php-slim/pom.xml is a good starting point. You will need to add a similar file for slim4 (you will need to use a different artifact ID)

then add another line similar to https://github.com/OpenAPITools/openapi-generator/blob/master/pom.xml#L1050 in pom.xml

@wing328 wing328 added this to the 4.2.3 milestone Jan 31, 2020
@ybelenko ybelenko restored the slim_data_mocker_array branch February 5, 2020 09:20
@ybelenko ybelenko deleted the slim_data_mocker_array branch May 9, 2020 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants