Using a testPool to show progress and test result info. Added icons...
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/"/>
+ <classpathentry kind="src" path="/org.eclipse.ui"/>
+ <classpathentry kind="src" path="/org.eclipse.ui.views"/>
+ <classpathentry kind="src" path="/org.eclipse.core.boot"/>
+ <classpathentry kind="src" path="/org.eclipse.core.runtime"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="C:/Documents and Settings/Ali Echihabi/My Documents/eclipse/eclipse-SDK-3_1.0-win32/eclipse/plugins/org.junit_3.8.1/junit.jar"/>
+ <classpathentry kind="src" path="/org.eclipse.core.resources"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>net.sourceforge.phpeclipse.phpunit</name>
+ <comment></comment>
+ <projects>
+ <project>org.eclipse.core.boot</project>
+ <project>org.eclipse.core.resources</project>
+ <project>org.eclipse.core.runtime</project>
+ <project>org.eclipse.ui</project>
+ <project>org.eclipse.ui.views</project>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>net.sourceforge.metrics.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>net.sourceforge.metrics.nature</nature>
+ </natures>
+</projectDescription>
--- /dev/null
+source.phpunit.jar = src/
+bin.includes = plugin.xml,\
+ *.jar,\
+ phpunit.jar
name="net.sourceforge.phpeclipse.phpunit"
version="1.0.0"
provider-name="Ali Echihabi"
- class="">
+ class="net.sourceforge.phpeclipse.phpunit.PHPUnitPlugin">
<runtime>
<library name="phpunit.jar"/>
<category
name="PHP Unit"
parentCategory="PHPUnit"
- id="net.sourceforge.phpeclipse.phpunit">
+ id="net.sourceforge.phpeclipse.phpunit.PHPUnitView">
</category>
<view
name="PHP Unit Testing"
point="org.eclipse.ui.popupMenus">
<objectContribution
objectClass="org.eclipse.core.resources.IFile"
+ adaptable="true"
nameFilter="*.php"
id="net.sourceforge.phpeclipse.phpunit.actions.runTestsAction">
<action
--- /dev/null
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/*
+ * Created on Jul 28, 2004
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+
+/**
+ * @author Ali Echihabi
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class Messages {
+
+ private static final String BUNDLE_NAME = "net.sourceforge.phpeclipse.phpunit.test"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE =
+ ResourceBundle.getBundle(BUNDLE_NAME);
+
+ /**
+ *
+ */
+ private Messages() {
+
+ // TODO Auto-generated constructor stub
+ }
+ /**
+ * @param key
+ * @return
+ */
+ public static String getString(String key) {
+ // TODO Auto-generated method stub
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
--- /dev/null
+/*
+ * Created on Sep 4, 2004
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package net.sourceforge.phpeclipse.phpunit;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ResourceBundle;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.jface.dialogs.IDialogSettings;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.resource.ImageRegistry;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+
+/**
+ * @author Ali Echihabi
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class PHPUnitPlugin extends AbstractUIPlugin {
+
+
+
+ private static PHPUnitPlugin plugin;
+ private ResourceBundle resourceBundle;
+
+
+ /**
+ * @param descriptor
+ */
+ public PHPUnitPlugin(IPluginDescriptor descriptor) {
+ super(descriptor);
+
+ plugin = this;
+
+
+
+
+ }
+
+ public static PHPUnitPlugin getDefault() {
+ return plugin;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#createImageRegistry()
+ */
+ protected ImageRegistry createImageRegistry() {
+ // TODO Auto-generated method stub
+ return super.createImageRegistry();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#getDialogSettings()
+ */
+ public IDialogSettings getDialogSettings() {
+ // TODO Auto-generated method stub
+ return super.getDialogSettings();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#getImageRegistry()
+ */
+ public ImageRegistry getImageRegistry() {
+ // TODO Auto-generated method stub
+ return super.getImageRegistry();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#getPreferenceStore()
+ */
+ public IPreferenceStore getPreferenceStore() {
+ // TODO Auto-generated method stub
+ return super.getPreferenceStore();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#getWorkbench()
+ */
+ public IWorkbench getWorkbench() {
+ // TODO Auto-generated method stub
+ return super.getWorkbench();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugin#initializeDefaultPluginPreferences()
+ */
+ protected void initializeDefaultPluginPreferences() {
+ // TODO Auto-generated method stub
+ super.initializeDefaultPluginPreferences();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeDefaultPreferences(org.eclipse.jface.preference.IPreferenceStore)
+ */
+ protected void initializeDefaultPreferences(IPreferenceStore store) {
+ // TODO Auto-generated method stub
+ super.initializeDefaultPreferences(store);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#initializeImageRegistry(org.eclipse.jface.resource.ImageRegistry)
+ */
+ protected void initializeImageRegistry(ImageRegistry reg) {
+ // TODO Auto-generated method stub
+ super.initializeImageRegistry(reg);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#loadDialogSettings()
+ */
+ protected void loadDialogSettings() {
+ // TODO Auto-generated method stub
+ super.loadDialogSettings();
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#refreshPluginActions()
+ */
+ protected void refreshPluginActions() {
+ // TODO Auto-generated method stub
+ super.refreshPluginActions();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#saveDialogSettings()
+ */
+ protected void saveDialogSettings() {
+ // TODO Auto-generated method stub
+ super.saveDialogSettings();
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugin#shutdown()
+ */
+ public void shutdown() throws CoreException {
+ // TODO Auto-generated method stub
+ super.shutdown();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.Plugin#startup()
+ */
+ public void startup() throws CoreException {
+ // TODO Auto-generated method stub
+ super.startup();
+ }
+
+ /**
+ * @param string
+ */
+ public static ImageDescriptor getImageDescriptor(String name) {
+
+ String iconPath = "icons/";
+ try {
+ URL installURL = getDefault().getDescriptor().getInstallURL();
+ URL url = new URL(installURL, iconPath + name);
+
+ System.out.println("url:" + url.toExternalForm());
+
+ return ImageDescriptor.createFromURL(url);
+ } catch (MalformedURLException e) {
+ // should not happen
+ return ImageDescriptor.getMissingImageDescriptor();
+ }
+
+
+ }
+
+}
package net.sourceforge.phpeclipse.phpunit;
+
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
import java.io.IOException;
+import net.sourceforge.phpeclipse.phpunit.testpool.TestCase;
+import net.sourceforge.phpeclipse.phpunit.testpool.TestPool;
+import net.sourceforge.phpeclipse.phpunit.testpool.TestSuite;
+
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Group;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
public class PHPUnitView extends ViewPart {
+
+
+
/*
* like J Unit
* a tree.
* hierarchy: package->testsuite1->testcase->test_function
*/
- private int numTests; // total number of tests
- private int numTestsRun; // number of tests run so far
- private int numFailures; // number of failures so far
- private int numErrors; // number of errors so far
- private int numPasses; // number of passes so far (they should add up)
+ private static PHPUnitView view = null;
private XMLReportHandler handler;
-
-
-
+
private TestPool testPool;
private Button startButton;
private ProgressInfoComposite progressInfoComposite;
private ResultsInfoComposite resultsInfoComposite;
- private Group settingsInfoComposite; //TODO: move somewhere else, launcher, wizard or preferences.
+ private SettingsInfoComposite settingsInfoComposite; //TODO: move somewhere else, launcher, wizard or preferences.
public PHPUnitView() {
- handler = new XMLReportHandler();
- testPool = new TestPool();
+ if(view == null)
+ view = this;
}
+
+ public static PHPUnitView getDefault() {
+
+
+ return view;
+ }
public void createPartControl(Composite parent) {
- parent.setLayout(new FillLayout(SWT.VERTICAL));
+ //parent.setLayout(new FillLayout(SWT.VERTICAL));
+
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 1;
+
+ // set title and layout
+ parent.setLayout(gridLayout);
+
//Launch ToolBar:
setActions();
- //Build the progress info Composite s
+ //Build the progress info Composites
progressInfoComposite = new ProgressInfoComposite(parent);
+ progressInfoComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
-
+
+
//Build the result info composite
resultsInfoComposite = new ResultsInfoComposite(parent);
+ resultsInfoComposite.setLayoutData(new GridData(GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
//build the settings composite
- buildSettingsComposite(parent);
+ //buildSettingsComposite(parent);
+
+ settingsInfoComposite = new SettingsInfoComposite(parent, SWT.NONE);
+
startButton = new Button(parent, SWT.CENTER);
startButton.setText("Start Tests");
public void mouseDown(MouseEvent arg0) {
- startTests();
+
}
public void mouseUp(MouseEvent arg0) {
+ try {
+ String testFile = settingsInfoComposite.getTestSuite();
+ startTests(testFile);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
}
}); // end add action listener.
private void buildSettingsComposite(Composite parent) {
- settingsInfoComposite = new Group(parent, SWT.NONE);
-// settingsInfoComposite.setText("Settings");
+ //settingsInfoComposite = new Group(parent, SWT.NONE);
+ //settingsInfoComposite.setText("Settings");
// settingsInfoComposite.setLayout(new GridLayout(2,false));
//
//
// phpPathLabel.setText("php Path:");
// //testSuiteLabel.setLayoutData(new GridData())
// Text phpPathText = new Text(settingsInfoComposite, SWT.NONE);
-
-
}
private void setActions() {
*
* @param testID
*/
- public void markTestPassed(String testID) {
+ private void markTestPassed(String testID) {
// testid, use it in hashmap to retrieve tree item of test and
// change icon color, increment pass counter, etc...
- testPool.getTest(testID).setVerdict(Test.PASS);
+ testPool.getTest(testID).setVerdict(TestCase.PASS);
}
- public void markTestStarted(String testID) {
+ private void markTestStarted(String testID) {
}
- public void createNewTest(String testName, String testID) {
+ private void createNewTest(String testName, String testID) {
- testPool.addTest(new Test(testName, testID));
+ testPool.addTest(new TestCase(testName, testID));
}
- public void markTestFail(String testID) {
- numFailures++;
- testPool.getTest(testID).setVerdict(Test.FAIL);
+ private void markTestFail(String testID) {
+
+ testPool.getTest(testID).setVerdict(TestCase.FAIL);
}
- public void markTestingStarted(int numTestsToBeRun) {
+ private void markTestingStarted(int numTestsToBeRun) {
+
- this.numTests = numTestsToBeRun;
//reportArea.append("Tests started expecting: " + numTests + " \n");
}
- public void markTestingFinished() {
+ private void markTestingFinished() {
//reportArea.append("end all tests \n");
}
// action to start tests:
- private void startTests() {
+ public void startTests() throws IOException {
+
+// // preparation:
+// // take the full test suite (could containt other test suites).
+// // create temp php file that starts that suite and uses socketTestReport
+// // as a test result reporter.
+// // add listener: localhost , port 13579
+// // start listening at port.
+//
+// testPool = new TestPool("RUN MONDAY 11:15 PM");
+// listenForReports();
+//
+// try {
+// Runtime.getRuntime().exec("php.exe \"C:/Program Files/Apache Group/Apache2/htdocs/phpUnit/suite.php\"");
+// } catch (Exception e) {
+//
+// e.printStackTrace();
+// }
+
+ startTests("C:/Program Files/Apache Group/Apache2/htdocs/phpUnit/suite.php");
+
+ }
+
+ public void startTests(String testSuite) throws IOException {
+
+ //testSuite: the name of the file containing the suite we want to run.
+ // we will put that test suite inside a contained that uses our SocketResult.
+
+
+ //reset from previous run
+ reset();
+
+ //where the plugin's temp files should go
+ String tempFolder = "C:\\tmp";
+ String tempFileName = "temTest.php";
+
+ //create the file.
+ File testFile = new File(tempFolder + "/" + tempFileName);
+ BufferedWriter out = new BufferedWriter(new FileWriter(testFile));
+
+ out.write("<?php" + "\n");
+ out.write("$path = \"C:/Documents and Settings/Ali Echihabi/My Documents/workspace.eclipse2.1/PHPUnit/phpunit\";" + "\n");
+ out.write("include_once($path . \"/phpunit_test.php\");" + "\n");
+ out.write("include_once $path . \"/socketTestResult.php\";" + "\n");
+
+ //include the test suite that we want to run.
+ String testSuiteName = "ManyFailingTests2";
+ String testSuitePath = "C:/eclipse/eclipse/runtime-workspace/PHPProject/testSuite.php";
+
+ out.write("include_once(\"" + testSuitePath + "\");" + "\n");
+
- // preparation:
- // take the full test suite (could containt other test suites).
- // create temp php file that starts that suite and uses socketTestReport
- // as a test result reporter.
- // add listener: localhost , port 13579
- // start listening at port.
+ out.write("" + "\n");
+ out.write("" + "\n");
+
+ out.write("$suite = new TestSuite();" + "\n");
+ out.write("$suite->addTest(new TestSuite(\"" + testSuiteName + "\"));" + "\n");
+
+
+
+ //out.write("$suite->addTest(new TestSuite(\"MoreTesterTests\"));" + "\n");
+
+ //out.write("$suite->addTest(new TestSuite(\"ManyFailingTests\"));" + "\n");
+ //out.write("$suite->addTest(new TestSuite(\"AssertEqualsTests\"));" + "\n");
+
+ out.write("$result = new SocketTestResult();" + "\n");
+ out.write("$suite->run($result);" + "\n");
+ out.write("$result->report(); " + "\n");
+ out.write("" + "\n");
+ out.write("" + "\n");
+
+ out.write("?>" + "\n");
+
+ out.flush();
+ out.close();
listenForReports();
try {
- Runtime.getRuntime().exec("php.exe \"C:/Program Files/Apache Group/Apache2/htdocs/phpUnit/suite.php\"");
- } catch (IOException e) {
- // TODO Auto-generated catch block
+ Runtime.getRuntime().exec("php.exe " + tempFolder + "/" + tempFileName);
+ } catch (Exception e) {
+
e.printStackTrace();
}
+
+ //testFile.delete();
+
+ }
+ /**
+ *
+ */
+ private void reset() {
+
+ handler = new XMLReportHandler();
+ testPool = new TestPool("Ali Baba");
+
+ progressInfoComposite.resetInfo();
+ resultsInfoComposite.resetInfo();
+
}
/**
markTestingStarted(new Integer(testCount).intValue());
- }else if (command.equals("testStarted")) {
+ } else if (command.equals("testSuiteStarted")) {
+
+ createNewTestSuite("TestSuiteName: " + testID, testID, new Integer(testCount).intValue());
+ markTestSuiteStarted(testID);
+
+ } else if (command.equals("testStarted")) {
- createNewTest("testName", testID);
+ createNewTest("TestName: " + testID, testID);
markTestStarted(testID);
} else if (command.equals("testFINISHED")) {
markTestingFinished();
}
+
+ update();
+
- progressInfoComposite.updateInfo(numTests, numTestsRun, numFailures, numErrors);
+
+ }
+
+ /**
+ *
+ */
+ private void update() {
+
+ //progressInfoComposite.updateInfo(numTests, testPool.getNumTestsRun(), numFailures, numErrors);
+ progressInfoComposite.updateInfo(testPool);
resultsInfoComposite.updateInfo(testPool);
+
+ }
+
+ /**
+ * @param testID
+ */
+ private void markTestSuiteStarted(String testID) {
+ // TODO Auto-generated method stub
+
+ }
+ /**
+ * @param string
+ * @param testID
+ * @param testCount
+ */
+ private void createNewTestSuite(String name, String testID, int testCount) {
+
+ TestSuite suite = new TestSuite(name, testID, testCount);
+ testPool.addTestSuite(suite);
+
}
/**
*/
private void markTestFinished() {
- numTestsRun++;
}
*/
package net.sourceforge.phpeclipse.phpunit;
+import net.sourceforge.phpeclipse.phpunit.testpool.TestPool;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
labelErrorsVal.setText("0");
}
+ public void resetInfo() {
+
+ labelErrorsVal.setText("0");
+ labelFailuresVal.setText("0");
+ labelRunsVal.setText("0 / 0");
+ progressBar.setSelection(0);
+
+ }
+
public void updateInfo(int numTests, int numTestsRun, int numFailures, int numErrors) {
//update progress bar
progressBar.setMaximum(numTests);
progressBar.setSelection(numTestsRun);
-
- System.out.println("numTestsRun: " + numTestsRun);
+
//update labels
labelRunsVal.setText(numTestsRun + " / " + numTests);
}
+
+ public void updateInfo(TestPool testPool) {
+
+ int numTestsOverall = testPool.getNumTestsOverall();
+ int numTestsRun = testPool.getNumTestsRun();
+
+ //update progress bar
+ progressBar.setMaximum(numTestsOverall);
+ progressBar.setSelection(numTestsRun);
+
+
+ //update labels
+ labelRunsVal.setText(numTestsRun + " / " + numTestsOverall);
+ labelFailuresVal.setText("" + testPool.getNumFailures());
+ labelErrorsVal.setText("" + testPool.getNumErrors());
+
+ //TODO: change Failures label to red if some exist.
+
+
+
+ }
+
}
while ( (report = in.readLine()) != null &&
(report != "end_all_tests") ) {
- System.out.println("received something...");
+ //System.out.println("received something...");
view.handleReport(report);
- System.out.println(report);
+ //System.out.println(report);
}
//reportArea.append("Finished!");
*/
package net.sourceforge.phpeclipse.phpunit;
+import net.sourceforge.phpeclipse.phpunit.testpool.TestPool;
+
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Text;
/**
* @author Ali Echihabi
public class ResultsInfoComposite extends Composite {
- private Text reportArea; // TODO: replace with Tree display like JUnit
+
+ private TreeViewer treeViewer;
/**
* @param arg0
*/
public ResultsInfoComposite(Composite parent) {
- super(parent, SWT.NONE);
+ super(parent, SWT.BORDER);
- setLayout(new FillLayout(SWT.VERTICAL));
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 1;
+
+ setLayout(layout);
+
+ treeViewer = new TreeViewer(this, SWT.BORDER | SWT.SHADOW_ETCHED_IN);
- reportArea =
- new Text(
- this,
- SWT.MULTI
- | SWT.BORDER
- | SWT.WRAP
- | SWT.V_SCROLL
- | SWT.READ_ONLY);
+ treeViewer.getControl().setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.FILL_BOTH | GridData.GRAB_VERTICAL));
+
+ TestPoolLabelProvider labelProvider = new TestPoolLabelProvider();
+ TestPoolContentProvider contentProvider= new TestPoolContentProvider();
+
+ treeViewer.setContentProvider(contentProvider);
+ treeViewer.setLabelProvider(labelProvider);
+
}
+ public void resetInfo() {
+
+ treeViewer.setInput(null);
+ }
public void updateInfo(TestPool testPool) {
// take care of the TreeView and its content and label providers.
+
+ treeViewer.setInput(testPool.getRoot());
}
-
-
-
-
-
}
--- /dev/null
+/*
+ * Created on Sep 11, 2004
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package net.sourceforge.phpeclipse.phpunit;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.FileDialog;
+
+/**
+ * @author Ali Echihabi
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class SettingsInfoComposite extends Composite {
+
+ FileDialog dialog;
+ Button button;
+
+ String testSuitePath;
+
+ /**
+ * @param arg0
+ * @param arg1
+ */
+ public SettingsInfoComposite(Composite parent, int style) {
+
+ super(parent, style);
+
+ dialog = new FileDialog(parent.getShell());
+
+ button = new Button(parent, SWT.NONE);
+ button.setText("Browser for test...");
+
+ button.addMouseListener(new MouseListener() {
+ public void mouseDoubleClick(MouseEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void mouseDown(MouseEvent arg0) {
+
+ testSuitePath = dialog.open();
+ System.out.println("file: " + testSuitePath);
+
+ }
+
+ public void mouseUp(MouseEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+
+
+
+
+
+ }
+
+
+ public String getTestSuite() {
+
+ return testSuitePath;
+ }
+
+
+
+}
+++ /dev/null
-/*
- * Created on Jul 31, 2004
- *
- * To change the template for this generated file go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-package net.sourceforge.phpeclipse.phpunit;
-
-import java.util.HashMap;
-
-/**
- * @author Ali Echihabi
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class TestPool {
-
- private HashMap tests;
-
- public TestPool() {
-
- tests = new HashMap();
- }
-
- public void addTest(TestCase test) {
-
- tests.put(test.getTestID(), test);
-
- }
-
- public TestCase getTest(String testID) {
-
- return (TestCase) tests.get(testID);
- }
-
-}
--- /dev/null
+/*
+ * Created on Aug 8, 2004
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package net.sourceforge.phpeclipse.phpunit;
+
+import java.util.Vector;
+
+import net.sourceforge.phpeclipse.phpunit.testpool.*;
+
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+
+/**
+ * @author Ali Echihabi
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class TestPoolContentProvider implements ITreeContentProvider {
+
+
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
+ */
+ public Object[] getChildren(Object parentElement) {
+
+ if(parentElement instanceof TestSuite) {
+
+ Vector allChildren = new Vector();
+ allChildren.addAll(((TestSuite)parentElement).getTestCases());
+ allChildren.addAll(((TestSuite)parentElement).getTestSuites());
+
+ return allChildren.toArray();
+
+ } else {
+ return new Object[0];
+ }
+
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
+ */
+ public Object getParent(Object element) {
+
+ if(element instanceof TestSuite)
+ return ((TestSuite)element).getParent();
+ else if (element instanceof TestCase)
+ return ((TestCase)element).getParentSuite();
+ else
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
+ */
+ public boolean hasChildren(Object element) {
+
+ return getChildren(element).length > 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
+ */
+ public Object[] getElements(Object inputElement) {
+
+ return getChildren(inputElement);
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#dispose()
+ */
+ public void dispose() {
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
+ */
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
--- /dev/null
+/*
+ * Created on Aug 8, 2004
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package net.sourceforge.phpeclipse.phpunit;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import net.sourceforge.phpeclipse.phpunit.testpool.TestCase;
+import net.sourceforge.phpeclipse.phpunit.testpool.TestSuite;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Ali Echihabi
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class TestPoolLabelProvider extends LabelProvider {
+
+ //TODO: replace with installDir + path
+ private static String iconsPath = "C:\\Documents and Settings\\Ali Echihabi\\My Documents\\workspace.eclipse2.1\\net.sourceforge.phpeclipse.phpunit\\icons";
+
+ public String getText(Object element) {
+
+ if(element instanceof TestSuite)
+ return ((TestSuite)element).getName();
+ else if(element instanceof TestCase)
+ return ((TestCase)element).getTestName();
+ else
+ return "UNKNOWN ELEMENT TYPE";
+
+
+
+ }
+
+ public Image getImage(Object element) {
+
+ Image image = null;
+
+ try {
+
+ String icon = "";
+ if(element instanceof TestSuite) {
+
+ TestSuite suite = (TestSuite)element;
+
+ //TODO check if there has been an error, a failure...
+
+ icon = "tsuite.gif";
+
+ } else if(element instanceof TestCase) {
+
+ TestCase test = (TestCase)element;
+
+ if(test.isError())
+ icon = "testerr.gif";
+ else if(test.isFailure())
+ icon = "testfail.gif";
+ else if(test.isPass())
+ icon = "testok.gif";
+
+ }
+
+
+ ImageDescriptor descriptor = ImageDescriptor.createFromURL(new URL("file://" + iconsPath + "//" + icon));
+ image = descriptor.createImage();
+
+ } catch (MalformedURLException e) {
+
+ e.printStackTrace();
+ image = ImageDescriptor.getMissingImageDescriptor().createImage();
+ }
+
+
+
+
+
+ return image;
+
+ }
+
+}
+++ /dev/null
-/*
- * Created on Jul 31, 2004
- *
- * To change the template for this generated file go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-package net.sourceforge.phpeclipse.phpunit;
-
-import java.util.Vector;
-
-/**
- * @author Ali Echihabi
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-public class TestSuite {
-
- private Vector testCases;
- private String name;
- private String id;
-
- public void addTestCase(TestCase test) {
-
- }
-
- public void removeTestCase(TestCase test) {}
-
- public boolean contains(TestCase test) {
- return false;
- }
-
-
-
-}
*/
package net.sourceforge.phpeclipse.phpunit.actions;
+import java.io.IOException;
+
+import net.sourceforge.phpeclipse.phpunit.PHPUnitView;
+
+import org.eclipse.core.resources.IFile;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Item;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.views.navigator.ResourceNavigator;
/**
* @author Ali Echihabi
*/
public class RunTestsAction implements IObjectActionDelegate {
+
+
+
/* (non-Javadoc)
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
// TODO Auto-generated method stub
+ System.out.println(targetPart.getTitle());
+ ResourceNavigator nav = (ResourceNavigator)targetPart;
+
+ Item selectedItem = nav.getViewer().getTree().getSelection()[0];
+
+ Object d = selectedItem.getData();
+//
+// try {
+//
+// IFile data = (IFile) selectedItem.getData();
+//
+// }
+// catch(Exception e) {
+//
+// e.printStackTrace();
+//
+// }
+//
+
+
+
+// Shell shell = PHPUnitPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
+//
+// if(shell instanceof IStructuredSelection) {
+//
+// Object testObj = ((IStructuredSelection) )
+// }
+//
+
+
+
}
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run(IAction action) {
- // TODO Auto-generated method stub
+
+ try {
+ PHPUnitView.getDefault().startTests();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
}
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
-package net.sourceforge.phpeclipse.phpunit;
+package net.sourceforge.phpeclipse.phpunit.testpool;
+
/**
* @author Ali Echihabi
*/
public class TestCase {
+ public static final String PASS = "PASS";
+ public static final String FAIL = "FAIL";
+ public static final String ERROR = "ERROR";
+
+
+ private TestSuite parentSuite;
+
+
+
/**
* @param testName
* @param testID
this.testID = testID;
}
- static final String PASS = "PASS";
- static final String FAIL = "PASS";
- static final String ERROR = "PASS";
String testName;
String testID;
*/
public void setVerdict(String string) {
verdict = string;
+
+
+
+
+
+ }
+
+ /**
+ * @param suite
+ */
+ public void setParentSuite(TestSuite suite) {
+ this.parentSuite = suite;
+
+ }
+
+ /**
+ * @return
+ */
+ public Object getParentSuite() {
+
+ return parentSuite;
+ }
+
+ /**
+ * @return
+ */
+ public boolean isError() {
+
+ return getVerdict().equals(TestCase.ERROR);
+ }
+
+ /**
+ * @return
+ */
+ public boolean isFailure() {
+
+ return getVerdict().equals(TestCase.FAIL);
+
+ }
+
+ /**
+ * @return
+ */
+ public boolean isPass() {
+
+ return getVerdict().equals(TestCase.PASS);
+
}
}
--- /dev/null
+/*
+ * Created on Jul 31, 2004
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package net.sourceforge.phpeclipse.phpunit.testpool;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Vector;
+
+
+/**
+ * @author Ali Echihabi
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class TestPool {
+
+ //private TestSuite currentParentTestSuite;
+ private HashMap tests;
+ private TestSuite root;
+ private TestSuite currentTestSuite;
+
+
+ /**
+ *
+ */
+ public TestPool(String rootTitle) {
+
+ tests = new HashMap();
+ root = new TestSuite(rootTitle, "-1", 0);
+
+ currentTestSuite = root;
+
+ }
+
+ /**
+ * @param test
+ */
+ public void addTest(TestCase test) {
+
+ tests.put(test.getTestID(), test);
+
+ currentTestSuite.addTestCase(test);
+
+
+ //if we run all tests. then this is the end of this test suite.
+ if( currentTestSuite != root && currentTestSuite.isFinished()) {
+
+ currentTestSuite = currentTestSuite.getParent();
+
+ }
+
+ }
+
+ /**
+ * @param suite
+ * @param numTestsRunSinceStartOfTestSuite
+ */
+ public void addTestSuite(TestSuite suite) {
+
+ //add as sibling
+ currentTestSuite.addTestSuite(suite);
+ suite.setParent(currentTestSuite);
+
+ currentTestSuite = suite;
+ }
+
+ /**
+ * @return
+ */
+ public TestSuite getRoot() {
+
+ return root;
+ }
+
+ /**
+ * @param r
+ */
+ public void setRoot(TestSuite r) {
+ this.root = r;
+ }
+
+
+
+ /**
+ * @param testID
+ * @return
+ */
+ public TestCase getTest(String testID) {
+
+ return (TestCase) tests.get(testID);
+ }
+
+ public String toString() {
+
+ String string = "";
+
+ TestSuite node = root;
+
+ string = root.toString();
+
+ return string;
+
+ }
+
+ private int countSuiteExpectedTests(TestSuite suite) {
+
+ int total = 0;
+
+ total += suite.getNumTestCasesExpected();
+
+ for(int i = 0; i < suite.getTestSuites().size(); i++)
+ total += countSuiteExpectedTests((TestSuite) suite.getTestSuites().elementAt(i));
+
+ return total;
+
+ }
+
+ public int getNumTestsOverall() {
+
+ return countSuiteExpectedTests(root);
+
+ }
+
+ public int getNumTestsRun() {
+
+ return tests.size();
+
+
+ }
+
+ public int getNumFailures() {
+
+ int total = 0;
+
+ Iterator i = tests.keySet().iterator();
+ String key = "";
+ while (i.hasNext()) {
+
+
+ key = (String) i.next();
+ TestCase element = (TestCase) tests.get(key);
+
+
+ if(element.isFailure())
+ total++;
+
+ }
+
+ return total;
+ }
+
+ public int getNumErrors() {
+
+ int total = 0;
+
+// Iterator i = tests.keySet().iterator();
+// String key = "";
+// while (i.hasNext()) {
+//
+//
+// key = (String) i.next();
+// TestCase element = (TestCase) tests.get(key);
+//
+// if(element.isError())
+// total++;
+//
+// }
+
+ return total;
+
+ }
+
+
+
+}
--- /dev/null
+/*
+ * Created on Jul 31, 2004
+ *
+ * To change the template for this generated file go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+package net.sourceforge.phpeclipse.phpunit.testpool;
+
+import java.util.Vector;
+
+/**
+ * @author Ali Echihabi
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class TestSuite {
+
+
+
+ private Vector testCases; // current or actual.
+ private Vector testSuites; // current or actual.
+ private String name;
+ private String id;
+ private int numTestCasesExpected; //expected
+ private int numTestCasesRunSoFar;
+ TestSuite parent;
+
+ /**
+ * @param name
+ * @param testID
+ * @param testCount
+ */
+ public TestSuite(String name, String testID, int testCount) {
+
+ this.parent = null;
+ this.id = testID;
+ this.name = name;
+ this.numTestCasesExpected = testCount;
+
+ testCases = new Vector();
+ testSuites = new Vector();
+
+ }
+
+ /**
+ * @param name
+ * @param testID
+ * @param testCount
+ */
+ public TestSuite(TestSuite parent, String name, String testID, int testCount) {
+
+ this.parent = parent;
+ this.id = testID;
+ this.name = name;
+ this.numTestCasesExpected = testCount;
+
+ testCases = new Vector();
+ testSuites = new Vector();
+ }
+
+ public void addTestCase(TestCase test) {
+ testCases.addElement(test);
+ test.setParentSuite(this);
+ numTestCasesRunSoFar++;
+ }
+
+ public void removeTestCase(TestCase test) {}
+
+ public boolean contains(TestCase test) {
+
+ return false;
+
+ }
+
+ public String toString() {
+
+ String string = "";
+
+ //print test cases.
+ TestCase tc = null;
+ for(int i = 0; i < testCases.size(); i++) {
+
+ tc = (TestCase) testCases.elementAt(i);
+ string += " - " + tc.getTestID() + ", " + tc.getTestName() + "\n";
+
+
+ }
+
+ for(int i = 0; i < testSuites.size(); i++)
+ string += ((TestSuite) testSuites.elementAt(i)).toString();
+
+ //print its own test suites.
+ return string;
+ }
+
+ /**
+ * @return
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @return
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return
+ */
+ public int getNumTestCasesExpected() {
+ return numTestCasesExpected;
+ }
+
+ /**
+ * @param string
+ */
+ public void setId(String string) {
+ id = string;
+ }
+
+ /**
+ * @param string
+ */
+ public void setName(String string) {
+ name = string;
+ }
+
+ /**
+ * @param i
+ */
+ public void setNumTestCasesExpected(int i) {
+ numTestCasesExpected = i;
+ }
+
+ /**
+ * @param suite
+ */
+ public void addTestSuite(TestSuite suite) {
+ testSuites.addElement(suite);
+
+ }
+
+ /**
+ * @return
+ */
+ public boolean isFinished() {
+
+ return numTestCasesRunSoFar >= numTestCasesExpected;
+
+ }
+
+ /**
+ * @return
+ */
+ public TestSuite getParent() {
+ return parent;
+ }
+
+ /**
+ * @param suite
+ */
+ public void setParent(TestSuite suite) {
+ parent = suite;
+ }
+
+ /**
+ * @return
+ */
+ public int getNumTestCases() {
+
+ return testCases.size();
+ }
+
+ /**
+ * @return
+ */
+ public Vector getTestCases() {
+ return testCases;
+ }
+
+ /**
+ * @return
+ */
+ public Vector getTestSuites() {
+ return testSuites;
+ }
+
+ /**
+ * @param vector
+ */
+ public void setTestCases(Vector vector) {
+ testCases = vector;
+ }
+
+ /**
+ * @param vector
+ */
+ public void setTestSuites(Vector vector) {
+ testSuites = vector;
+ }
+
+}