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.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.part.ViewPart; /** * @author Ali Echihabi * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ /* * Created on May 22, 2004 * * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ /** * @author Ali Echihabi (ali_echihabi@ieee.org) * * Plugin for PHP unit Testing. * www.phpeclipse.de * * This the main view showing the progress and reports. * */ public class PHPUnitView extends ViewPart { /* * like J Unit * a tree. * The first level nodes are the test suites. * children are nested test suites. * leafs: test functions. * 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 XMLReportHandler handler; Label labelRuns, labelRunsVal; // Runs: 12 Label labelErrors, labelErrorsVal; Label labelFailures, labelFailuresVal; Text reportArea; // TODO: replace with Tree display like JUnit Button startButton; public PHPUnitView() { handler = new XMLReportHandler(); } public void createPartControl(Composite parent) { // //viewer = new TreeViewer(parent); // labelRuns = new Label(parent, SWT.WRAP); // labelRuns.setText("Runs: "); // labelRunsVal = new Label(parent, SWT.WRAP); // labelRunsVal.setText("0 / 0"); // // labelFailures = new Label(parent, SWT.WRAP); // labelFailures.setText("Failures: "); // labelFailuresVal = new Label(parent, SWT.WRAP); // labelFailuresVal.setText("0"); // // labelErrors = new Label(parent, SWT.WRAP); // labelErrors.setText("Errors: "); // labelErrorsVal = new Label(parent, SWT.WRAP); // labelErrorsVal.setText("0"); reportArea = new Text(parent, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY); startButton = new Button(parent, SWT.CENTER); startButton.setText("Start Tests"); startButton.addMouseListener( new MouseListener() { public void mouseDoubleClick(MouseEvent arg0) { // TODO Auto-generated method stub } public void mouseDown(MouseEvent arg0) { // TODO Auto-generated method stub startTests(); } public void mouseUp(MouseEvent arg0) { // TODO Auto-generated method stub } }); // end add action listener. // TODO layout! } /* (non-Javadoc) * @see org.eclipse.ui.IWorkbenchPart#setFocus() */ public void setFocus() { //markTestPass("hello"); } /** * mark the given test as passed in the GUI. * * @param testID */ public void markTestPassed(String testID) { // testid, use it in hashmap to retrieve tree item of test and // change icon color, increment pass counter, etc... //for now: reportArea.append("test passed \n"); } public void markTestStarted(String testID) { reportArea.append("test started \n"); } public void createNewTest(String testName, String testID) { reportArea.append("new test: " + testName + " - testID \n"); } public void markTestFail(String testID) { reportArea.append("test failed \n"); } public void markTestingFinished() { reportArea.append("end all tests \n"); } // action to start tests: private void startTests() { // 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. reportArea.append("Tests started \n"); listenForReports(); } private void listenForReports() { ConnectionListener conListener = new ConnectionListener(); conListener.start(); } //end of method /** * handle this report: test passed, faile, end of all. * @param report */ private void handleReport(String report) { reportArea.append("msg: " + report + "\n"); String event = report.substring(0, report.indexOf(" ")); System.out.println(event); handler.handle(report, this); } public void handleCommand(String command, String testCount, String testID) { } } //end of class