Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public AbstractPhpCodegen() {
apiTestTemplateFiles.put("api_test.mustache", ".php");
modelDocTemplateFiles.put("model_doc.mustache", ".md");
apiDocTemplateFiles.put("api_doc.mustache", ".md");

apiPackage = invokerPackage + "\\" + apiDirName;
modelPackage = invokerPackage + "\\" + modelDirName;

Expand Down Expand Up @@ -197,6 +197,12 @@ public void processOpts() {

additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));

// make api and model src path available in mustache template
additionalProperties.put("apiSrcPath", "./" + toSrcPath(apiPackage, srcBasePath));
additionalProperties.put("modelSrcPath", "./" + toSrcPath(modelPackage, srcBasePath));
additionalProperties.put("apiTestPath", "./" + testBasePath + "/" + apiDirName);
additionalProperties.put("modelTestPath", "./" + testBasePath + "/" + modelDirName);

// make api and model doc path available in mustache template
additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);
Expand All @@ -213,6 +219,10 @@ public String getPackagePath() {
}

public String toPackagePath(String packageName, String basePath) {
return (getPackagePath() + File.separatorChar + toSrcPath(packageName, basePath));
}

public String toSrcPath(String packageName, String basePath) {
packageName = packageName.replace(invokerPackage, ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
if (basePath != null && basePath.length() > 0) {
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
Expand All @@ -232,13 +242,13 @@ public String toPackagePath(String packageName, String basePath) {
regLastPathSeparator = "\\\\$";
}

return (getPackagePath() + File.separatorChar + basePath
// Replace period, backslash, forward slash with file separator in package name
+ packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement(File.separator))
// Trim prefix file separators from package path
.replaceAll(regFirstPathSeparator, ""))
// Trim trailing file separators from the overall path
.replaceAll(regLastPathSeparator+ "$", "");
return (basePath
// Replace period, backslash, forward slash with file separator in package name
+ packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement(File.separator))
// Trim prefix file separators from package path
.replaceAll(regFirstPathSeparator, ""))
// Trim trailing file separators from the overall path
.replaceAll(regLastPathSeparator+ "$", "");
}

@Override
Expand Down Expand Up @@ -392,7 +402,7 @@ public String toParamName(String name) {

@Override
public String toModelName(String name) {
// remove [
// remove [
name = name.replaceAll("\\]", "");

// Note: backslash ("\\") is allowed for e.g. "\\DateTime"
Expand All @@ -417,7 +427,7 @@ public String toModelName(String name) {
if (!name.matches("^\\\\.*")) {
name = modelNamePrefix + name + modelNameSuffix;
}

// camelize the model name
// phone_number => PhoneNumber
return camelize(name);
Expand Down Expand Up @@ -642,5 +652,5 @@ public String escapeQuotationMark(String input) {
public String escapeUnsafeCharacters(String input) {
return input.replace("*/", "");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public String getPackagePath() {
}

public String toPackagePath(String packageName, String basePath) {
return (getPackagePath() + File.separatorChar + toSrcPath(packageName, basePath));
}

public String toSrcPath(String packageName, String basePath) {
packageName = packageName.replace(invokerPackage, ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
if (basePath != null && basePath.length() > 0) {
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
Expand All @@ -169,13 +173,13 @@ public String toPackagePath(String packageName, String basePath) {
regLastPathSeparator = "\\\\$";
}

return (getPackagePath() + File.separatorChar + basePath
// Replace period, backslash, forward slash with file separator in package name
+ packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement(File.separator))
// Trim prefix file separators from package path
.replaceAll(regFirstPathSeparator, ""))
// Trim trailing file separators from the overall path
.replaceAll(regLastPathSeparator+ "$", "");
return (basePath
// Replace period, backslash, forward slash with file separator in package name
+ packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement(File.separator))
// Trim prefix file separators from package path
.replaceAll(regFirstPathSeparator, ""))
// Trim trailing file separators from the overall path
.replaceAll(regLastPathSeparator+ "$", "");
}

@Override
Expand Down Expand Up @@ -276,6 +280,12 @@ public void processOpts() {

additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));

// make api and model src path available in mustache template
additionalProperties.put("apiSrcPath", "./" + toSrcPath(apiPackage, srcBasePath));
additionalProperties.put("modelSrcPath", "./" + toSrcPath(modelPackage, srcBasePath));
additionalProperties.put("apiTestPath", "./" + testBasePath + "/" + apiDirName);
additionalProperties.put("modelTestPath", "./" + testBasePath + "/" + modelDirName);

// make api and model doc path available in mustache template
additionalProperties.put("apiDocPath", apiDocPath);
additionalProperties.put("modelDocPath", modelDocPath);
Expand All @@ -290,6 +300,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("composer.mustache", getPackagePath(), "composer.json"));
supportingFiles.add(new SupportingFile("autoload.mustache", getPackagePath(), "autoload.php"));
supportingFiles.add(new SupportingFile("README.mustache", getPackagePath(), "README.md"));
supportingFiles.add(new SupportingFile("phpunit.xml.mustache", getPackagePath(), "phpunit.xml.dist"));
supportingFiles.add(new SupportingFile(".travis.yml", getPackagePath(), ".travis.yml"));
supportingFiles.add(new SupportingFile(".php_cs", getPackagePath(), ".php_cs"));
supportingFiles.add(new SupportingFile("git_push.sh.mustache", getPackagePath(), "git_push.sh"));
Expand Down
2 changes: 1 addition & 1 deletion modules/swagger-codegen/src/main/resources/php/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ php:
- 7.0
- hhvm
before_install: "composer install"
script: "phpunit lib/Tests"
script: "vendor/bin/phpunit"
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ To run the unit tests:

```
composer install
./vendor/bin/phpunit lib/Tests
./vendor/bin/phpunit
```

## Getting Started
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<testsuites>
<testsuite>
<directory>{{apiTestPath}}</directory>
<directory>{{modelTestPath}}</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">{{apiSrcPath}}</directory>
<directory suffix=".php">{{modelSrcPath}}</directory>
</whitelist>
</filter>
</phpunit>
2 changes: 1 addition & 1 deletion samples/client/petstore/php/SwaggerClient-php/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ php:
- 7.0
- hhvm
before_install: "composer install"
script: "phpunit lib/Tests"
script: "vendor/bin/phpunit"
2 changes: 1 addition & 1 deletion samples/client/petstore/php/SwaggerClient-php/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ To run the unit tests:

```
composer install
./vendor/bin/phpunit lib/Tests
./vendor/bin/phpunit
```

## Getting Started
Expand Down
21 changes: 21 additions & 0 deletions samples/client/petstore/php/SwaggerClient-php/phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<testsuites>
<testsuite>
<directory>./test/Api</directory>
<directory>./test/Model</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./lib/Api</directory>
<directory suffix=".php">./lib/Model</directory>
</whitelist>
</filter>
</phpunit>
3 changes: 0 additions & 3 deletions samples/client/petstore/php/SwaggerClient-php/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@
</goals>
<configuration>
<executable>vendor/bin/phpunit</executable>
<arguments>
<argument>test</argument>
</arguments>
</configuration>
</execution>
</executions>
Expand Down