Skip to content

Commit

Permalink
[php-slim4] Partial generation (#11069)
Browse files Browse the repository at this point in the history
* Update tests folder

I forgot to update tests folder in latest PR. Fixing my mistake.

* Implement part generation
  • Loading branch information
ybelenko authored Dec 17, 2021
1 parent 7dbcac3 commit d65bf8d
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ public String modelFileFolder() {
public void processOpts() {
super.processOpts();

Boolean generateModels = additionalProperties.containsKey(CodegenConstants.GENERATE_MODELS) && Boolean.TRUE.equals(additionalProperties.get(CodegenConstants.GENERATE_MODELS));
Boolean generateApiTests = additionalProperties.containsKey(CodegenConstants.GENERATE_API_TESTS) && Boolean.TRUE.equals(additionalProperties.get(CodegenConstants.GENERATE_API_TESTS));
Boolean generateModelTests = additionalProperties.containsKey(CodegenConstants.GENERATE_MODEL_TESTS) && Boolean.TRUE.equals(additionalProperties.get(CodegenConstants.GENERATE_MODEL_TESTS));

if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
// Update the invokerPackage for the default authPackage
authPackage = invokerPackage + "\\" + authDirName;
Expand Down Expand Up @@ -210,14 +214,26 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("index.mustache", "public", "index.php"));
supportingFiles.add(new SupportingFile(".htaccess", "public", ".htaccess"));
supportingFiles.add(new SupportingFile("SlimRouter.mustache", toSrcPath(invokerPackage, srcBasePath), "SlimRouter.php"));
supportingFiles.add(new SupportingFile("phpunit.xml.mustache", "", "phpunit.xml.dist"));

// don't generate phpunit config when tests generation disabled
if (Boolean.TRUE.equals(generateApiTests) || Boolean.TRUE.equals(generateModelTests)) {
supportingFiles.add(new SupportingFile("phpunit.xml.mustache", "", "phpunit.xml.dist"));
additionalProperties.put("generateTests", Boolean.TRUE);
}

supportingFiles.add(new SupportingFile("phpcs.xml.mustache", "", "phpcs.xml.dist"));

supportingFiles.add(new SupportingFile("htaccess_deny_all", "config", ".htaccess"));
supportingFiles.add(new SupportingFile("config_example.mustache", "config" + File.separator + "dev", "example.inc.php"));
supportingFiles.add(new SupportingFile("config_example.mustache", "config" + File.separator + "prod", "example.inc.php"));
supportingFiles.add(new SupportingFile("base_model.mustache", toSrcPath(invokerPackage, srcBasePath), "BaseModel.php"));
supportingFiles.add(new SupportingFile("base_model_test.mustache", toSrcPath(invokerPackage, testBasePath), "BaseModelTest.php"));

if (Boolean.TRUE.equals(generateModels)) {
supportingFiles.add(new SupportingFile("base_model.mustache", toSrcPath(invokerPackage, srcBasePath), "BaseModel.php"));
}

if (Boolean.TRUE.equals(generateModelTests)) {
supportingFiles.add(new SupportingFile("base_model_test.mustache", toSrcPath(invokerPackage, testBasePath), "BaseModelTest.php"));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ $ php -S localhost:8888 -t php-slim-server/public
> It may also be useful for testing purposes or for application demonstrations that are run in controlled environments.
> It is not intended to be a full-featured web server. It should not be used on a public network.

{{#generateTests}}
## Tests

### PHPUnit
Expand All @@ -59,9 +60,14 @@ How to write tests read at [2. Writing Tests for PHPUnit - PHPUnit 8.5 Manual](h
Command | Target
---- | ----
`$ composer test` | All tests
{{#generateApiTests}}
`$ composer test-apis` | Apis tests
{{/generateApiTests}}
{{#generateModelTests}}
`$ composer test-models` | Models tests
{{/generateModelTests}}

{{/generateTests}}
#### Config

Package contains fully functional config `./phpunit.xml.dist` file. Create `./phpunit.xml` in root folder to override it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
{{/isZendDiactoros}}
},
"require-dev": {
{{#generateTests}}
"phpunit/phpunit": "^8.0 || ^9.0",
{{/generateTests}}
"overtrue/phplint": "^2.0.2",
"squizlabs/php_codesniffer": "^3.5"
},
Expand All @@ -43,11 +45,17 @@
"psr-4": { "{{escapedInvokerPackage}}\\": "{{testBasePath}}/" }
},
"scripts": {
{{#generateTests}}
"test": [
"phpunit"
],
{{#generateApiTests}}
"test-apis": "phpunit --testsuite Apis",
{{/generateApiTests}}
{{#generateModelTests}}
"test-models": "phpunit --testsuite Models",
{{/generateModelTests}}
{{/generateTests}}
"phpcs": "phpcs",
"phplint": "phplint ./ --exclude=vendor"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
</include>
</coverage>
<testsuites>
{{#generateApiTests}}
<testsuite name="Apis">
<directory>{{apiTestPath}}</directory>
</testsuite>
{{/generateApiTests}}
{{#generateModelTests}}
<testsuite name="Models">
<file>./{{testBasePath}}/BaseModelTest.php</file>
<directory>{{modelTestPath}}</directory>
</testsuite>
{{/generateModelTests}}
</testsuites>
<php>
<ini name="error_reporting" value="E_ALL"/>
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion samples/server/petstore/php-slim4/tests/Api/PetApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* OpenAPI Petstore
* PHP version 7.2
* PHP version 7.4
*
* @package OpenAPIServer
* @author OpenAPI Generator team
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* OpenAPI Petstore
* PHP version 7.2
* PHP version 7.4
*
* @package OpenAPIServer
* @author OpenAPI Generator team
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* OpenAPI Petstore
* PHP version 7.2
* PHP version 7.4
*
* @package OpenAPIServer
* @author OpenAPI Generator team
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* OpenAPI Petstore
* PHP version 7.2
* PHP version 7.4
*
* @package OpenAPIServer
* @author OpenAPI Generator team
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* OpenAPI Petstore
* PHP version 7.2
* PHP version 7.4
*
* @package OpenAPIServer
* @author OpenAPI Generator team
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* OpenAPI Petstore
* PHP version 7.2
* PHP version 7.4
*
* @package OpenAPIServer
* @author OpenAPI Generator team
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/php-slim4/tests/Model/PetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* OpenAPI Petstore
* PHP version 7.2
* PHP version 7.4
*
* @package OpenAPIServer
* @author OpenAPI Generator team
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/php-slim4/tests/Model/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* OpenAPI Petstore
* PHP version 7.2
* PHP version 7.4
*
* @package OpenAPIServer
* @author OpenAPI Generator team
Expand Down
2 changes: 1 addition & 1 deletion samples/server/petstore/php-slim4/tests/Model/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* OpenAPI Petstore
* PHP version 7.2
* PHP version 7.4
*
* @package OpenAPIServer
* @author OpenAPI Generator team
Expand Down

0 comments on commit d65bf8d

Please sign in to comment.