diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractPhpCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractPhpCodegen.java
index ff51beaef7f..f0eb365d0c8 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractPhpCodegen.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractPhpCodegen.java
@@ -56,7 +56,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
apiTestTemplateFiles.put("api_test.mustache", ".php");
modelDocTemplateFiles.put("model_doc.mustache", ".md");
apiDocTemplateFiles.put("api_doc.mustache", ".md");
-
+
apiPackage = invokerPackage + "\\" + apiDirName;
modelPackage = invokerPackage + "\\" + modelDirName;
@@ -197,6 +197,12 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
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);
@@ -213,6 +219,10 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
}
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'.
@@ -232,13 +242,13 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
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
@@ -392,7 +402,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
@Override
public String toModelName(String name) {
- // remove [
+ // remove [
name = name.replaceAll("\\]", "");
// Note: backslash ("\\") is allowed for e.g. "\\DateTime"
@@ -417,7 +427,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
if (!name.matches("^\\\\.*")) {
name = modelNamePrefix + name + modelNameSuffix;
}
-
+
// camelize the model name
// phone_number => PhoneNumber
return camelize(name);
@@ -642,5 +652,5 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
public String escapeUnsafeCharacters(String input) {
return input.replace("*/", "");
}
-
+
}
diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java
index 610e5da1db5..232bf9fa56c 100644
--- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java
+++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java
@@ -150,6 +150,10 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
}
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'.
@@ -169,13 +173,13 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
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
@@ -276,6 +280,12 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
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);
@@ -290,6 +300,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
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"));
diff --git a/modules/swagger-codegen/src/main/resources/php/.travis.yml b/modules/swagger-codegen/src/main/resources/php/.travis.yml
index 3c97d942552..d77f3825f6f 100644
--- a/modules/swagger-codegen/src/main/resources/php/.travis.yml
+++ b/modules/swagger-codegen/src/main/resources/php/.travis.yml
@@ -7,4 +7,4 @@ php:
- 7.0
- hhvm
before_install: "composer install"
-script: "phpunit lib/Tests"
+script: "vendor/bin/phpunit"
diff --git a/modules/swagger-codegen/src/main/resources/php/README.mustache b/modules/swagger-codegen/src/main/resources/php/README.mustache
index 67f5e31f68a..ab0da1711f2 100644
--- a/modules/swagger-codegen/src/main/resources/php/README.mustache
+++ b/modules/swagger-codegen/src/main/resources/php/README.mustache
@@ -56,7 +56,7 @@ To run the unit tests:
```
composer install
-./vendor/bin/phpunit lib/Tests
+./vendor/bin/phpunit
```
## Getting Started
diff --git a/modules/swagger-codegen/src/main/resources/php/phpunit.xml.mustache b/modules/swagger-codegen/src/main/resources/php/phpunit.xml.mustache
new file mode 100644
index 00000000000..5de6fea575c
--- /dev/null
+++ b/modules/swagger-codegen/src/main/resources/php/phpunit.xml.mustache
@@ -0,0 +1,21 @@
+
+
+
+
+ {{apiTestPath}}
+ {{modelTestPath}}
+
+
+
+
+
+ {{apiSrcPath}}
+ {{modelSrcPath}}
+
+
+
diff --git a/samples/client/petstore/php/SwaggerClient-php/.travis.yml b/samples/client/petstore/php/SwaggerClient-php/.travis.yml
index 3c97d942552..d77f3825f6f 100644
--- a/samples/client/petstore/php/SwaggerClient-php/.travis.yml
+++ b/samples/client/petstore/php/SwaggerClient-php/.travis.yml
@@ -7,4 +7,4 @@ php:
- 7.0
- hhvm
before_install: "composer install"
-script: "phpunit lib/Tests"
+script: "vendor/bin/phpunit"
diff --git a/samples/client/petstore/php/SwaggerClient-php/README.md b/samples/client/petstore/php/SwaggerClient-php/README.md
index 055a49f1f5b..6089d21da1c 100644
--- a/samples/client/petstore/php/SwaggerClient-php/README.md
+++ b/samples/client/petstore/php/SwaggerClient-php/README.md
@@ -45,7 +45,7 @@ To run the unit tests:
```
composer install
-./vendor/bin/phpunit lib/Tests
+./vendor/bin/phpunit
```
## Getting Started
diff --git a/samples/client/petstore/php/SwaggerClient-php/phpunit.xml.dist b/samples/client/petstore/php/SwaggerClient-php/phpunit.xml.dist
new file mode 100644
index 00000000000..c12ee148477
--- /dev/null
+++ b/samples/client/petstore/php/SwaggerClient-php/phpunit.xml.dist
@@ -0,0 +1,21 @@
+
+
+
+
+ ./test/Api
+ ./test/Model
+
+
+
+
+
+ ./lib/Api
+ ./lib/Model
+
+
+
diff --git a/samples/client/petstore/php/SwaggerClient-php/pom.xml b/samples/client/petstore/php/SwaggerClient-php/pom.xml
index faaeba82c11..5a0007c898b 100644
--- a/samples/client/petstore/php/SwaggerClient-php/pom.xml
+++ b/samples/client/petstore/php/SwaggerClient-php/pom.xml
@@ -47,9 +47,6 @@
vendor/bin/phpunit
-
- test
-