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.layout.FillLayout;
8 import org.eclipse.swt.layout.GridData;
9 import org.eclipse.swt.layout.GridLayout;
10 import org.eclipse.swt.widgets.Button;
11 import org.eclipse.swt.widgets.Composite;
12 import org.eclipse.swt.widgets.Group;
13 import org.eclipse.swt.widgets.Label;
14 import org.eclipse.swt.widgets.ProgressBar;
15 import org.eclipse.swt.widgets.Text;
16 import org.eclipse.ui.part.ViewPart;
19 * @author Ali Echihabi
21 * To change the template for this generated type comment go to
22 * Window>Preferences>Java>Code Generation>Code and Comments
25 * Created on May 22, 2004
27 * To change the template for this generated file go to
28 * Window>Preferences>Java>Code Generation>Code and Comments
32 * @author Ali Echihabi (ali_echihabi@ieee.org)
34 * Plugin for PHP unit Testing.
37 * This the main view showing the progress and reports.
42 public class PHPUnitView extends ViewPart {
47 * The first level nodes are the test suites.
48 * children are nested test suites.
49 * leafs: test functions.
50 * hierarchy: package->testsuite1->testcase->test_function
54 private int numTests; // total number of tests
55 private int numTestsRun; // number of tests run so far
56 private int numFailures; // number of failures so far
57 private int numErrors; // number of errors so far
58 private int numPasses; // number of passes so far (they should add up)
61 private XMLReportHandler handler;
63 Label labelRuns, labelRunsVal; // Runs: 12
64 Label labelErrors, labelErrorsVal;
65 Label labelFailures, labelFailuresVal;
67 Text reportArea; // TODO: replace with Tree display like JUnit
71 public PHPUnitView() {
72 handler = new XMLReportHandler();
77 public void createPartControl(Composite parent) {
81 FillLayout fillLayout = new FillLayout(SWT.VERTICAL);
82 parent.setLayout(fillLayout);
84 Group progressInfoComposite = new Group(parent, SWT.SHADOW_ETCHED_IN);
85 Group resultsInfoComposite = new Group(parent, SWT.NONE);
88 //Build the progress info Composite
89 progressInfoComposite.setText("Progress:");
90 GridLayout gridLayout = new GridLayout();
91 gridLayout.numColumns = 1;
93 progressInfoComposite.setLayout(gridLayout);
96 ProgressBar progressBar = new ProgressBar(progressInfoComposite, SWT.HORIZONTAL);
97 progressBar.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL|GridData.FILL_HORIZONTAL));
99 Composite labelsComposite = new Composite(progressInfoComposite, SWT.NONE);
100 labelsComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL|GridData.FILL_HORIZONTAL));
102 labelsComposite.setLayout(new FillLayout(SWT.HORIZONTAL));
104 labelRuns = new Label(labelsComposite, SWT.NONE);
105 labelRuns.setText("Runs: ");
106 labelRunsVal = new Label(labelsComposite, SWT.NONE);
107 labelRunsVal.setText("0 / 0");
109 labelFailures = new Label(labelsComposite, SWT.NONE);
110 labelFailures.setText("Failures: ");
111 labelFailuresVal = new Label(labelsComposite, SWT.NONE);
112 labelFailuresVal.setText("0");
114 labelErrors = new Label(labelsComposite, SWT.NONE);
115 labelErrors.setText("Errors: ");
116 labelErrorsVal = new Label(labelsComposite, SWT.NONE);
117 labelErrorsVal.setText("0");
119 //Build the result info composite
120 resultsInfoComposite.setText("Results:");
121 resultsInfoComposite.setLayout(fillLayout);
123 reportArea = new Text(resultsInfoComposite, SWT.MULTI | SWT.BORDER |
124 SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY);
126 startButton = new Button(parent, SWT.CENTER);
127 startButton.setText("Start Tests");
128 startButton.addMouseListener( new MouseListener() {
130 public void mouseDoubleClick(MouseEvent arg0) {
131 // TODO Auto-generated method stub
135 public void mouseDown(MouseEvent arg0) {
136 // TODO Auto-generated method stub
140 public void mouseUp(MouseEvent arg0) {
141 // TODO Auto-generated method stub
148 }); // end add action listener.
153 * @see org.eclipse.ui.IWorkbenchPart#setFocus()
155 public void setFocus() {
156 //markTestPass("hello");
160 * mark the given test as passed in the GUI.
164 public void markTestPassed(String testID) {
166 // testid, use it in hashmap to retrieve tree item of test and
167 // change icon color, increment pass counter, etc...
171 reportArea.append("test : " + testID + " passed \n");
174 public void markTestStarted(String testID) {
176 reportArea.append("test started: " + testID + " \n");
179 public void createNewTest(String testName, String testID) {
181 reportArea.append("new test: " + testName + " - testID " + testID + " \n");
185 public void markTestFail(String testID) {
186 reportArea.append("test " + testID + " failed \n");
189 public void markTestingFinished() {
191 reportArea.append("end all tests \n");
195 // action to start tests:
196 private void startTests() {
199 // take the full test suite (could containt other test suites).
200 // create temp php file that starts that suite and uses socketTestReport
201 // as a test result reporter.
202 // add listener: localhost , port 13579
203 // start listening at port.
205 reportArea.append("Tests started \n");
215 private void listenForReports() {
219 ConnectionListener conListener = new ConnectionListener();
220 conListener.start(this);
225 * handle this report: test passed, faile, end of all.
228 public void handleReport(String report) {
230 //delegate to the XML report handler.
231 //reportArea.append("msg: " + report + "\n");
232 handler.handle(report, this);
243 public void handleCommand(String command, String testCount, String testID) {
245 if (command.equals("testStarted")) {
247 createNewTest("testName", testID);
248 markTestStarted(testID);
250 } else if (command.equals("testFinished")) {
253 // do nothing wait for verdict
254 } else if (command.equals("endAll")) {
256 markTestingFinished();
263 * @param currentTestID
266 public void setTestVerdict(String currentTestID, String verdict) {
268 if( verdict.equals("passed"))
269 markTestPassed(currentTestID);
271 markTestFail(currentTestID);
277 * @param currentTestID
280 public void addTestException(String currentTestID, String exception) {
282 //TODO: decide how to show exceptions. don't show them for now.
283 //reportArea.append(" test " + currentTestID + " exception: " + exception + "\n");