1 package net.sourceforge.phpeclipse.phpunit;
 
   4 import org.eclipse.swt.SWT;
 
   5 import org.eclipse.swt.events.MouseEvent;
 
   6 import org.eclipse.swt.events.MouseListener;
 
   7 import org.eclipse.swt.widgets.Button;
 
   8 import org.eclipse.swt.widgets.Composite;
 
   9 import org.eclipse.swt.widgets.Label;
 
  10 import org.eclipse.swt.widgets.Text;
 
  11 import org.eclipse.ui.part.ViewPart;
 
  14  * @author Ali Echihabi
 
  16  * To change the template for this generated type comment go to
 
  17  * Window>Preferences>Java>Code Generation>Code and Comments
 
  20  * Created on May 22, 2004
 
  22  * To change the template for this generated file go to
 
  23  * Window>Preferences>Java>Code Generation>Code and Comments
 
  27  * @author Ali Echihabi (ali_echihabi@ieee.org)
 
  29  * Plugin for PHP unit Testing.
 
  32  * This the main view showing the progress and reports.
 
  37 public class PHPUnitView extends ViewPart {
 
  42          * The first level nodes are the test suites.
 
  43          * children are nested test suites.
 
  44          * leafs: test functions.
 
  45          * hierarchy: package->testsuite1->testcase->test_function
 
  49         private int numTests; // total number of tests
 
  50         private int numTestsRun; // number of tests run so far
 
  51         private int numFailures; // number of failures so far
 
  52         private int numErrors; // number of errors so far
 
  53         private int numPasses; // number of passes so far (they should add up)   
 
  56         private XMLReportHandler handler;
 
  58         Label labelRuns, labelRunsVal; // Runs: 12
 
  59         Label labelErrors, labelErrorsVal;
 
  60         Label labelFailures, labelFailuresVal;
 
  62         Text reportArea; // TODO: replace with Tree display like JUnit
 
  66         public PHPUnitView() {
 
  67                 handler = new XMLReportHandler();
 
  70         public void createPartControl(Composite parent) {
 
  72 //              //viewer = new TreeViewer(parent);
 
  73 //              labelRuns = new Label(parent, SWT.WRAP);
 
  74 //              labelRuns.setText("Runs: ");
 
  75 //              labelRunsVal = new Label(parent, SWT.WRAP);
 
  76 //              labelRunsVal.setText("0 / 0");
 
  78 //              labelFailures = new Label(parent, SWT.WRAP);
 
  79 //              labelFailures.setText("Failures: ");
 
  80 //              labelFailuresVal = new Label(parent, SWT.WRAP);
 
  81 //              labelFailuresVal.setText("0");
 
  83 //              labelErrors = new Label(parent, SWT.WRAP);
 
  84 //              labelErrors.setText("Errors: ");
 
  85 //              labelErrorsVal = new Label(parent, SWT.WRAP);
 
  86 //              labelErrorsVal.setText("0");
 
  88                 reportArea = new Text(parent, SWT.MULTI | SWT.BORDER |
 
  89                 SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
 
  91                 startButton = new Button(parent, SWT.CENTER);
 
  92                 startButton.setText("Start Tests");
 
  93                 startButton.addMouseListener( new MouseListener() {
 
  95                         public void mouseDoubleClick(MouseEvent arg0) {
 
  96                                 // TODO Auto-generated method stub
 
 100                         public void mouseDown(MouseEvent arg0) {
 
 101                                 // TODO Auto-generated method stub
 
 105                         public void mouseUp(MouseEvent arg0) {
 
 106                                 // TODO Auto-generated method stub
 
 113                         }); // end add action listener.
 
 119          * @see org.eclipse.ui.IWorkbenchPart#setFocus()
 
 121         public void setFocus() {
 
 122                 //markTestPass("hello");
 
 126          * mark the given test as passed in the GUI.
 
 130         public void markTestPassed(String testID) {
 
 132                 // testid, use it in hashmap to retrieve tree item of test and
 
 133                 // change icon color, increment pass counter, etc...
 
 137                 reportArea.append("test : " + testID + " passed \n");
 
 140         public void markTestStarted(String testID) {
 
 142                 reportArea.append("test started: " + testID + " \n");
 
 145         public void createNewTest(String testName, String testID) {
 
 147                 reportArea.append("new test: " + testName + " - testID " + testID + " \n");     
 
 151         public void markTestFail(String testID) {
 
 152                 reportArea.append("test "  + testID + " failed \n");
 
 155         public void markTestingFinished() {
 
 157                 reportArea.append("end all tests \n");  
 
 161         // action to start tests:
 
 162         private void startTests() {
 
 165                 // take the full test suite (could containt other test suites).
 
 166                 // create temp php file that starts that suite and uses socketTestReport 
 
 167                 // as a test result reporter.
 
 168                 // add listener: localhost , port 13579
 
 169                 // start listening at port.
 
 171                 reportArea.append("Tests started \n");
 
 181         private void listenForReports() {
 
 185                 ConnectionListener conListener = new ConnectionListener();
 
 186                 conListener.start(this);
 
 191          * handle this report: test passed, faile, end of all.
 
 194         public void handleReport(String report) {
 
 196                 //delegate to the XML report handler.           
 
 197                 //reportArea.append("msg: " + report + "\n");
 
 198                 handler.handle(report, this);
 
 209         public void handleCommand(String command, String testCount, String testID) {
 
 211                 if (command.equals("testStarted")) {
 
 213                         createNewTest("testName", testID);
 
 214                         markTestStarted(testID);
 
 216                 } else if (command.equals("testFinished")) {
 
 219                         // do nothing wait for verdict
 
 220                 } else if (command.equals("endAll")) {
 
 222                         markTestingFinished();
 
 229          * @param currentTestID
 
 232         public void setTestVerdict(String currentTestID, String verdict) {
 
 234                 if( verdict.equals("passed")) 
 
 235                         markTestPassed(currentTestID);
 
 237                         markTestFail(currentTestID);
 
 243          * @param currentTestID
 
 246         public void addTestException(String currentTestID, String exception) {
 
 248                 reportArea.append("   test " + currentTestID + " exception: " + exception + "\n");