Skip to content

Add relative path preference settings to PhpUnit #8478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2025
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 @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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<String> params) {
if (PhpUnitPreferences.isBootstrapEnabled(phpModule)) {
params.add(BOOTSTRAP_PARAM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
<Component id="askForTestGroupsCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="scriptCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="runPhpUnitOnlyCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="isRelativePathEnabled" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
Expand Down Expand Up @@ -144,15 +145,17 @@
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="suiteInfoLabel" min="-2" max="-2" attributes="0"/>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="scriptCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="scriptLabel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="scriptTextField" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="scriptBrowseButton" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="isRelativePathEnabled" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="runPhpUnitOnlyCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="runTestUsingUnitCheckBox" min="-2" max="-2" attributes="0"/>
Expand Down Expand Up @@ -482,9 +485,6 @@
</Component>
<Component class="javax.swing.JLabel" name="versionLabel">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="default"/>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<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;)"/>
</Property>
Expand All @@ -500,5 +500,12 @@
<Property name="text" type="java.lang.String" value="VERSION" noResource="true"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="isRelativePathEnabled">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<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;)"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Form>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
Loading