diff --git a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/commands/PhpUnit.java b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/commands/PhpUnit.java index 07027324defc..eaecda749000 100644 --- a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/commands/PhpUnit.java +++ b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/commands/PhpUnit.java @@ -28,6 +28,7 @@ import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -473,7 +474,7 @@ private TestParams getTestParams(PhpModule phpModule, TestRunInfo runInfo) throw params.add(getNbSuite().getAbsolutePath()); } else { // GH-5790 we can use NetBeansSuite.php no longer with PHPUnit 10 - params.add(FileUtil.toFile(startFiles.get(0)).getAbsolutePath()); + params.add(getTestFilePath(phpModule, FileUtil.toFile(startFiles.get(0)))); } // #254276 //params.add(PARAM_SEPARATOR); @@ -485,6 +486,16 @@ private TestParams getTestParams(PhpModule phpModule, TestRunInfo runInfo) throw return new TestParams(params, envVariables); } + private String getTestFilePath(PhpModule phpModule, File file) { + if (PhpUnitPreferences.isRelativePathEnabled(phpModule)) { + String basePathText = phpModule.getSourceDirectory().getPath(); + return Paths.get(basePathText) + .relativize(file.toPath()) + .toString(); + } + return file.getAbsolutePath(); + } + private void addBootstrap(PhpModule phpModule, List params) { if (PhpUnitPreferences.isBootstrapEnabled(phpModule)) { params.add(BOOTSTRAP_PARAM); diff --git a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/preferences/PhpUnitPreferences.java b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/preferences/PhpUnitPreferences.java index 07752f74dfc2..26a0105b79ba 100644 --- a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/preferences/PhpUnitPreferences.java +++ b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/preferences/PhpUnitPreferences.java @@ -49,11 +49,20 @@ public final class PhpUnitPreferences { private static final String ASK_FOR_TEST_GROUPS = "test.groups.ask"; // NOI18N private static final String TEST_GROUPS = "test.groups"; // NOI18N private static final String TEST_GROUPS_DELIMITER = ","; // NOI18N + private static final String PHPUNIT_USE_RELATIVE_PATHS = "relativePath.enabled"; // NOI18N private PhpUnitPreferences() { } + public static void setRelativePathEnabled(PhpModule phpModule, boolean relativePathEnabled) { + getPreferences(phpModule).putBoolean(PHPUNIT_USE_RELATIVE_PATHS, relativePathEnabled); + } + + public static boolean isRelativePathEnabled(PhpModule phpModule) { + return getPreferences(phpModule).getBoolean(PHPUNIT_USE_RELATIVE_PATHS, false); + } + public static boolean isBootstrapEnabled(PhpModule phpModule) { return getPreferences(phpModule).getBoolean(BOOTSTRAP_ENABLED, false); } diff --git a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/Bundle.properties b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/Bundle.properties index 982bfe189122..f9a89cf43756 100644 --- a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/Bundle.properties +++ b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/Bundle.properties @@ -69,3 +69,4 @@ CustomizerPhpUnit.scriptBrowseButton.text=Brow&se... CustomizerPhpUnit.runPhpUnitOnlyCheckBox.text=&Test Project Using Just 'phpunit' Command CustomizerPhpUnit.versionLabel.text=PHPUnit &Version: CustomizerPhpUnit.versionLabel.AccessibleContext.accessibleDescription=PHPUnit version label +CustomizerPhpUnit.isRelativePathEnabled.text=Use relative paths for test files (uses source directory as base path) diff --git a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/CustomizerPhpUnit.form b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/CustomizerPhpUnit.form index 06604e4cee8c..f06e9cf5d441 100644 --- a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/CustomizerPhpUnit.form +++ b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/CustomizerPhpUnit.form @@ -100,6 +100,7 @@ + @@ -144,7 +145,7 @@ - + @@ -152,7 +153,9 @@ - + + + @@ -482,9 +485,6 @@ - - - @@ -500,5 +500,12 @@ + + + + + + + diff --git a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/CustomizerPhpUnit.java b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/CustomizerPhpUnit.java index 012ba60dd116..9f367185d2f9 100644 --- a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/CustomizerPhpUnit.java +++ b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/CustomizerPhpUnit.java @@ -96,6 +96,7 @@ private void init() { runPhpUnitOnlyCheckBox.setSelected(PhpUnitPreferences.getRunPhpUnitOnly(phpModule)); runTestUsingUnitCheckBox.setSelected(PhpUnitPreferences.getRunAllTestFiles(phpModule)); askForTestGroupsCheckBox.setSelected(PhpUnitPreferences.getAskForTestGroups(phpModule)); + isRelativePathEnabled.setSelected(PhpUnitPreferences.isRelativePathEnabled(phpModule)); initPhpUnitVersion(); enableFile(bootstrapCheckBox.isSelected(), bootstrapLabel, bootstrapTextField, bootstrapGenerateButton, bootstrapBrowseButton, bootstrapForCreateTestsCheckBox); @@ -180,6 +181,7 @@ void storeData() { PhpUnitPreferences.setRunPhpUnitOnly(phpModule, runPhpUnitOnlyCheckBox.isSelected()); PhpUnitPreferences.setRunAllTestFiles(phpModule, runTestUsingUnitCheckBox.isSelected()); PhpUnitPreferences.setAskForTestGroups(phpModule, askForTestGroupsCheckBox.isSelected()); + PhpUnitPreferences.setRelativePathEnabled(phpModule, isRelativePathEnabled.isSelected()); } private void initFile(boolean enabled, String file, JCheckBox checkBox, JTextField textField) { @@ -329,6 +331,7 @@ private void initComponents() { askForTestGroupsCheckBox = new JCheckBox(); versionLabel = new JLabel(); versionLineLabel = new JLabel(); + isRelativePathEnabled = new JCheckBox(); bootstrapLabel.setLabelFor(bootstrapTextField); Mnemonics.setLocalizedText(bootstrapLabel, NbBundle.getMessage(CustomizerPhpUnit.class, "CustomizerPhpUnit.bootstrapLabel.text")); // NOI18N @@ -414,6 +417,8 @@ public void actionPerformed(ActionEvent evt) { Mnemonics.setLocalizedText(versionLineLabel, "VERSION"); // NOI18N + Mnemonics.setLocalizedText(isRelativePathEnabled, NbBundle.getMessage(CustomizerPhpUnit.class, "CustomizerPhpUnit.isRelativePathEnabled.text")); // NOI18N + GroupLayout layout = new GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING) @@ -464,7 +469,8 @@ public void actionPerformed(ActionEvent evt) { .addComponent(runTestUsingUnitCheckBox) .addComponent(askForTestGroupsCheckBox) .addComponent(scriptCheckBox) - .addComponent(runPhpUnitOnlyCheckBox)) + .addComponent(runPhpUnitOnlyCheckBox) + .addComponent(isRelativePathEnabled)) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(versionLabel) @@ -504,14 +510,16 @@ public void actionPerformed(ActionEvent evt) { .addComponent(suiteBrowseButton)) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(suiteInfoLabel) - .addPreferredGap(ComponentPlacement.UNRELATED) + .addPreferredGap(ComponentPlacement.RELATED) .addComponent(scriptCheckBox) .addPreferredGap(ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(Alignment.BASELINE) .addComponent(scriptLabel) .addComponent(scriptTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(scriptBrowseButton)) - .addPreferredGap(ComponentPlacement.UNRELATED) + .addPreferredGap(ComponentPlacement.RELATED) + .addComponent(isRelativePathEnabled) + .addPreferredGap(ComponentPlacement.RELATED) .addComponent(runPhpUnitOnlyCheckBox) .addPreferredGap(ComponentPlacement.RELATED) .addComponent(runTestUsingUnitCheckBox) @@ -645,6 +653,7 @@ private void scriptBrowseButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:eve private JButton configurationGenerateButton; private JLabel configurationLabel; private JTextField configurationTextField; + private JCheckBox isRelativePathEnabled; private JCheckBox runPhpUnitOnlyCheckBox; private JCheckBox runTestUsingUnitCheckBox; private JButton scriptBrowseButton;