1 package net.sourceforge.phpeclipse.phpunit;
4 import java.io.BufferedReader;
5 import java.io.InputStreamReader;
6 import java.net.ServerSocket;
7 import java.net.Socket;
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.events.ControlEvent;
11 import org.eclipse.swt.events.ControlListener;
12 import org.eclipse.swt.events.MouseEvent;
13 import org.eclipse.swt.events.MouseListener;
14 import org.eclipse.swt.widgets.Button;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Label;
17 import org.eclipse.swt.widgets.Text;
18 import org.eclipse.ui.part.ViewPart;
21 * @author Ali Echihabi
23 * To change the template for this generated type comment go to
24 * Window>Preferences>Java>Code Generation>Code and Comments
27 * Created on May 22, 2004
29 * To change the template for this generated file go to
30 * Window>Preferences>Java>Code Generation>Code and Comments
34 * @author Ali Echihabi (ali_echihabi@ieee.org)
36 * Plugin for PHP unit Testing.
39 * This the main view showing the progress and reports.
44 public class PHPUnitView extends ViewPart {
49 * The first level nodes are the test suites.
50 * children are nested test suites.
51 * leafs: test functions.
55 private int numTests; // total number of tests
56 private int numTestsRun; // number of tests run so far
57 private int numFailures; // number of failures so far
58 private int numErrors; // number of errors so far
59 private int numPasses; // number of passes so far (they should add up)
61 Label labelRuns, labelRunsVal; // Runs: 12
62 Label labelErrors, labelErrorsVal;
63 Label labelFailures, labelFailuresVal;
65 Text reportArea; // TODO: replace with Tree display like JUnit
69 public PHPUnitView() {
73 public void createPartControl(Composite parent) {
75 //viewer = new TreeViewer(parent);
76 labelRuns = new Label(parent, SWT.WRAP);
77 labelRuns.setText("Runs: ");
78 labelRunsVal = new Label(parent, SWT.WRAP);
79 labelRunsVal.setText("0 / 0");
81 labelFailures = new Label(parent, SWT.WRAP);
82 labelFailures.setText("Failures: ");
83 labelFailuresVal = new Label(parent, SWT.WRAP);
84 labelFailuresVal.setText("0");
86 labelErrors = new Label(parent, SWT.WRAP);
87 labelErrors.setText("Errors: ");
88 labelErrorsVal = new Label(parent, SWT.WRAP);
89 labelErrorsVal.setText("0");
91 reportArea = new Text(parent, SWT.MULTI | SWT.BORDER |
92 SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
94 startButton = new Button(parent, SWT.CENTER);
95 startButton.setText("Start Tests");
96 startButton.addMouseListener( new MouseListener() {
98 public void mouseDoubleClick(MouseEvent arg0) {
99 // TODO Auto-generated method stub
103 public void mouseDown(MouseEvent arg0) {
104 // TODO Auto-generated method stub
108 public void mouseUp(MouseEvent arg0) {
109 // TODO Auto-generated method stub
116 }); // end add action listener.
122 * @see org.eclipse.ui.IWorkbenchPart#setFocus()
124 public void setFocus() {
125 //markTestPass("hello");
129 * mark the given test as passed in the GUI.
133 private void markTestPass(String testID) {
135 // testid, use it in hashmap to retrieve tree item of test and
136 // change icon color, increment pass counter, etc...
140 reportArea.append("test passed");
146 // action to start tests:
147 private void startTests() {
150 // take the full test suite (could containt other test suites).
151 // create temp php file that starts that suite and uses socketTestReport
152 // as a test result reporter.
153 // add listener: localhost , port 13579
154 // start listening at port.
156 reportArea.append("Tests started \n");
163 private void listenForReports() {
165 ServerSocket sSocket = null;
166 Socket serviceSocket = null;
170 reportArea.append("listening at port 12345");
172 sSocket = new ServerSocket(12345);
174 // accept connection from test reporter.
175 serviceSocket = sSocket.accept();
178 InputStreamReader reader = new InputStreamReader(serviceSocket.getInputStream());
179 BufferedReader in = new BufferedReader(reader);
180 String report = null;
182 // keep listening until the
183 while ( (report = in.readLine()) != null && (report != "end_all_tests") ) {
185 handleReport(report);
188 reportArea.append("Finished!");
191 serviceSocket.close();
193 } catch (Exception e) {
205 * handle this report: test passed, faile, end of all.
208 private void handleReport(String report) {
210 reportArea.append("msg: " + report + "\n");