[PHP] fix PHPUnit invocation, add basic phpunit.xml.dist (#3864)

* feature(phpunit) fix PHPUnit invocation, add basic phpunit.xml.dist

* fix(phpunit) add proper paths relative to phpunit.xml.dist
This commit is contained in:
Dalibor Karlović 2016-09-28 13:44:07 +02:00 committed by wing328
parent ec25bd793f
commit 10d3dea89e
9 changed files with 85 additions and 25 deletions

View File

@ -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("*/", "");
}
}

View File

@ -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"));

View File

@ -7,4 +7,4 @@ php:
- 7.0
- hhvm
before_install: "composer install"
script: "phpunit lib/Tests"
script: "vendor/bin/phpunit"

View File

@ -56,7 +56,7 @@ To run the unit tests:
```
composer install
./vendor/bin/phpunit lib/Tests
./vendor/bin/phpunit
```
## Getting Started

View File

@ -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>

View File

@ -7,4 +7,4 @@ php:
- 7.0
- hhvm
before_install: "composer install"
script: "phpunit lib/Tests"
script: "vendor/bin/phpunit"

View File

@ -45,7 +45,7 @@ To run the unit tests:
```
composer install
./vendor/bin/phpunit lib/Tests
./vendor/bin/phpunit
```
## Getting Started

View File

@ -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>

View File

@ -47,9 +47,6 @@
</goals>
<configuration>
<executable>vendor/bin/phpunit</executable>
<arguments>
<argument>test</argument>
</arguments>
</configuration>
</execution>
</executions>