Skip to content

Commit 7e72192

Browse files
committed
Add relative path preference settings to PhpUnit
This checkbox gives boolean setting switching between two behaviour of passing test file paths to the PhpUnit command: FALSE = Use absolute paths [Current behaviour] TRUE = Use relative paths [Based on source root]
1 parent 92eb77d commit 7e72192

File tree

5 files changed

+46
-9
lines changed

5 files changed

+46
-9
lines changed

php/php.phpunit/src/org/netbeans/modules/php/phpunit/commands/PhpUnit.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.InputStreamReader;
2929
import java.io.OutputStreamWriter;
3030
import java.nio.charset.StandardCharsets;
31+
import java.nio.file.Paths;
3132
import java.util.ArrayList;
3233
import java.util.Arrays;
3334
import java.util.Collections;
@@ -473,7 +474,7 @@ private TestParams getTestParams(PhpModule phpModule, TestRunInfo runInfo) throw
473474
params.add(getNbSuite().getAbsolutePath());
474475
} else {
475476
// GH-5790 we can use NetBeansSuite.php no longer with PHPUnit 10
476-
params.add(FileUtil.toFile(startFiles.get(0)).getAbsolutePath());
477+
params.add(getTestFilePath(phpModule, FileUtil.toFile(startFiles.get(0))));
477478
}
478479
// #254276
479480
//params.add(PARAM_SEPARATOR);
@@ -485,6 +486,16 @@ private TestParams getTestParams(PhpModule phpModule, TestRunInfo runInfo) throw
485486
return new TestParams(params, envVariables);
486487
}
487488

489+
private String getTestFilePath(PhpModule phpModule, File file) {
490+
if (PhpUnitPreferences.isRelativePathEnabled(phpModule)) {
491+
String basePathText = phpModule.getSourceDirectory().getPath();
492+
return Paths.get(basePathText)
493+
.relativize(file.toPath())
494+
.toString();
495+
}
496+
return file.getAbsolutePath();
497+
}
498+
488499
private void addBootstrap(PhpModule phpModule, List<String> params) {
489500
if (PhpUnitPreferences.isBootstrapEnabled(phpModule)) {
490501
params.add(BOOTSTRAP_PARAM);

php/php.phpunit/src/org/netbeans/modules/php/phpunit/preferences/PhpUnitPreferences.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,20 @@ public final class PhpUnitPreferences {
4949
private static final String ASK_FOR_TEST_GROUPS = "test.groups.ask"; // NOI18N
5050
private static final String TEST_GROUPS = "test.groups"; // NOI18N
5151
private static final String TEST_GROUPS_DELIMITER = ","; // NOI18N
52+
private static final String PHPUNIT_USE_RELATIVE_PATHS = "relativePath.enabled"; // NOI18N
5253

5354

5455
private PhpUnitPreferences() {
5556
}
5657

58+
public static void setRelativePathEnabled(PhpModule phpModule, boolean relativePathEnabled) {
59+
getPreferences(phpModule).putBoolean(PHPUNIT_USE_RELATIVE_PATHS, relativePathEnabled);
60+
}
61+
62+
public static boolean isRelativePathEnabled(PhpModule phpModule) {
63+
return getPreferences(phpModule).getBoolean(PHPUNIT_USE_RELATIVE_PATHS, false);
64+
}
65+
5766
public static boolean isBootstrapEnabled(PhpModule phpModule) {
5867
return getPreferences(phpModule).getBoolean(BOOTSTRAP_ENABLED, false);
5968
}

php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/Bundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,4 @@ CustomizerPhpUnit.scriptBrowseButton.text=Brow&se...
6969
CustomizerPhpUnit.runPhpUnitOnlyCheckBox.text=&Test Project Using Just 'phpunit' Command
7070
CustomizerPhpUnit.versionLabel.text=PHPUnit &Version:
7171
CustomizerPhpUnit.versionLabel.AccessibleContext.accessibleDescription=PHPUnit version label
72+
CustomizerPhpUnit.isRelativePathEnabled.text=Use relative paths for test files (uses source directory as base path)

php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/CustomizerPhpUnit.form

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<Component id="askForTestGroupsCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
101101
<Component id="scriptCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
102102
<Component id="runPhpUnitOnlyCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
103+
<Component id="isRelativePathEnabled" alignment="0" min="-2" max="-2" attributes="0"/>
103104
</Group>
104105
<EmptySpace max="32767" attributes="0"/>
105106
</Group>
@@ -144,15 +145,17 @@
144145
</Group>
145146
<EmptySpace max="-2" attributes="0"/>
146147
<Component id="suiteInfoLabel" min="-2" max="-2" attributes="0"/>
147-
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
148+
<EmptySpace min="-2" max="-2" attributes="0"/>
148149
<Component id="scriptCheckBox" min="-2" max="-2" attributes="0"/>
149150
<EmptySpace max="-2" attributes="0"/>
150151
<Group type="103" groupAlignment="3" attributes="0">
151152
<Component id="scriptLabel" alignment="3" min="-2" max="-2" attributes="0"/>
152153
<Component id="scriptTextField" alignment="3" min="-2" max="-2" attributes="0"/>
153154
<Component id="scriptBrowseButton" alignment="3" min="-2" max="-2" attributes="0"/>
154155
</Group>
155-
<EmptySpace type="unrelated" max="-2" attributes="0"/>
156+
<EmptySpace max="-2" attributes="0"/>
157+
<Component id="isRelativePathEnabled" min="-2" max="-2" attributes="0"/>
158+
<EmptySpace max="-2" attributes="0"/>
156159
<Component id="runPhpUnitOnlyCheckBox" min="-2" max="-2" attributes="0"/>
157160
<EmptySpace max="-2" attributes="0"/>
158161
<Component id="runTestUsingUnitCheckBox" min="-2" max="-2" attributes="0"/>
@@ -482,9 +485,6 @@
482485
</Component>
483486
<Component class="javax.swing.JLabel" name="versionLabel">
484487
<Properties>
485-
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
486-
<ComponentRef name="default"/>
487-
</Property>
488488
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
489489
<ResourceString bundle="org/netbeans/modules/php/phpunit/ui/customizer/Bundle.properties" key="CustomizerPhpUnit.versionLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
490490
</Property>
@@ -500,5 +500,12 @@
500500
<Property name="text" type="java.lang.String" value="VERSION" noResource="true"/>
501501
</Properties>
502502
</Component>
503+
<Component class="javax.swing.JCheckBox" name="isRelativePathEnabled">
504+
<Properties>
505+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
506+
<ResourceString bundle="org/netbeans/modules/php/phpunit/ui/customizer/Bundle.properties" key="CustomizerPhpUnit.isRelativePathEnabled.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
507+
</Property>
508+
</Properties>
509+
</Component>
503510
</SubComponents>
504511
</Form>

php/php.phpunit/src/org/netbeans/modules/php/phpunit/ui/customizer/CustomizerPhpUnit.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ private void init() {
9696
runPhpUnitOnlyCheckBox.setSelected(PhpUnitPreferences.getRunPhpUnitOnly(phpModule));
9797
runTestUsingUnitCheckBox.setSelected(PhpUnitPreferences.getRunAllTestFiles(phpModule));
9898
askForTestGroupsCheckBox.setSelected(PhpUnitPreferences.getAskForTestGroups(phpModule));
99+
isRelativePathEnabled.setSelected(PhpUnitPreferences.isRelativePathEnabled(phpModule));
99100
initPhpUnitVersion();
100101

101102
enableFile(bootstrapCheckBox.isSelected(), bootstrapLabel, bootstrapTextField, bootstrapGenerateButton, bootstrapBrowseButton, bootstrapForCreateTestsCheckBox);
@@ -180,6 +181,7 @@ void storeData() {
180181
PhpUnitPreferences.setRunPhpUnitOnly(phpModule, runPhpUnitOnlyCheckBox.isSelected());
181182
PhpUnitPreferences.setRunAllTestFiles(phpModule, runTestUsingUnitCheckBox.isSelected());
182183
PhpUnitPreferences.setAskForTestGroups(phpModule, askForTestGroupsCheckBox.isSelected());
184+
PhpUnitPreferences.setRelativePathEnabled(phpModule, isRelativePathEnabled.isSelected());
183185
}
184186

185187
private void initFile(boolean enabled, String file, JCheckBox checkBox, JTextField textField) {
@@ -329,6 +331,7 @@ private void initComponents() {
329331
askForTestGroupsCheckBox = new JCheckBox();
330332
versionLabel = new JLabel();
331333
versionLineLabel = new JLabel();
334+
isRelativePathEnabled = new JCheckBox();
332335

333336
bootstrapLabel.setLabelFor(bootstrapTextField);
334337
Mnemonics.setLocalizedText(bootstrapLabel, NbBundle.getMessage(CustomizerPhpUnit.class, "CustomizerPhpUnit.bootstrapLabel.text")); // NOI18N
@@ -414,6 +417,8 @@ public void actionPerformed(ActionEvent evt) {
414417

415418
Mnemonics.setLocalizedText(versionLineLabel, "VERSION"); // NOI18N
416419

420+
Mnemonics.setLocalizedText(isRelativePathEnabled, NbBundle.getMessage(CustomizerPhpUnit.class, "CustomizerPhpUnit.isRelativePathEnabled.text")); // NOI18N
421+
417422
GroupLayout layout = new GroupLayout(this);
418423
this.setLayout(layout);
419424
layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING)
@@ -464,7 +469,8 @@ public void actionPerformed(ActionEvent evt) {
464469
.addComponent(runTestUsingUnitCheckBox)
465470
.addComponent(askForTestGroupsCheckBox)
466471
.addComponent(scriptCheckBox)
467-
.addComponent(runPhpUnitOnlyCheckBox))
472+
.addComponent(runPhpUnitOnlyCheckBox)
473+
.addComponent(isRelativePathEnabled))
468474
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
469475
.addGroup(layout.createSequentialGroup()
470476
.addComponent(versionLabel)
@@ -504,14 +510,16 @@ public void actionPerformed(ActionEvent evt) {
504510
.addComponent(suiteBrowseButton))
505511
.addPreferredGap(ComponentPlacement.RELATED)
506512
.addComponent(suiteInfoLabel)
507-
.addPreferredGap(ComponentPlacement.UNRELATED)
513+
.addPreferredGap(ComponentPlacement.RELATED)
508514
.addComponent(scriptCheckBox)
509515
.addPreferredGap(ComponentPlacement.RELATED)
510516
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
511517
.addComponent(scriptLabel)
512518
.addComponent(scriptTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
513519
.addComponent(scriptBrowseButton))
514-
.addPreferredGap(ComponentPlacement.UNRELATED)
520+
.addPreferredGap(ComponentPlacement.RELATED)
521+
.addComponent(isRelativePathEnabled)
522+
.addPreferredGap(ComponentPlacement.RELATED)
515523
.addComponent(runPhpUnitOnlyCheckBox)
516524
.addPreferredGap(ComponentPlacement.RELATED)
517525
.addComponent(runTestUsingUnitCheckBox)
@@ -645,6 +653,7 @@ private void scriptBrowseButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:eve
645653
private JButton configurationGenerateButton;
646654
private JLabel configurationLabel;
647655
private JTextField configurationTextField;
656+
private JCheckBox isRelativePathEnabled;
648657
private JCheckBox runPhpUnitOnlyCheckBox;
649658
private JCheckBox runTestUsingUnitCheckBox;
650659
private JButton scriptBrowseButton;

0 commit comments

Comments
 (0)