1 package net.sourceforge.phpeclipse.phpunit;
3 import java.io.IOException;
5 import org.eclipse.jface.action.Action;
6 import org.eclipse.jface.action.IToolBarManager;
7 import org.eclipse.swt.SWT;
8 import org.eclipse.swt.events.MouseEvent;
9 import org.eclipse.swt.events.MouseListener;
10 import org.eclipse.swt.layout.FillLayout;
11 import org.eclipse.swt.widgets.Button;
12 import org.eclipse.swt.widgets.Composite;
13 import org.eclipse.swt.widgets.Group;
14 import org.eclipse.ui.IActionBars;
15 import org.eclipse.ui.ISharedImages;
16 import org.eclipse.ui.PlatformUI;
17 import org.eclipse.ui.part.ViewPart;
20 * @author Ali Echihabi
22 * To change the template for this generated type comment go to
23 * Window>Preferences>Java>Code Generation>Code and Comments
26 * Created on May 22, 2004
28 * To change the template for this generated file go to
29 * Window>Preferences>Java>Code Generation>Code and Comments
33 * @author Ali Echihabi (ali_echihabi@ieee.org)
35 * Plugin for PHP unit Testing.
38 * 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
53 private int numTests; // total number of tests
54 private int numTestsRun; // number of tests run so far
55 private int numFailures; // number of failures so far
56 private int numErrors; // number of errors so far
57 private int numPasses; // number of passes so far (they should add up)
59 private XMLReportHandler handler;
63 private TestPool testPool;
65 private Button startButton;
67 private ProgressInfoComposite progressInfoComposite;
68 private ResultsInfoComposite resultsInfoComposite;
69 private Group settingsInfoComposite; //TODO: move somewhere else, launcher, wizard or preferences.
73 public PHPUnitView() {
74 handler = new XMLReportHandler();
75 testPool = new TestPool();
80 public void createPartControl(Composite parent) {
82 parent.setLayout(new FillLayout(SWT.VERTICAL));
87 //Build the progress info Composite s
88 progressInfoComposite = new ProgressInfoComposite(parent);
91 //Build the result info composite
92 resultsInfoComposite = new ResultsInfoComposite(parent);
94 //build the settings composite
95 buildSettingsComposite(parent);
97 startButton = new Button(parent, SWT.CENTER);
98 startButton.setText("Start Tests");
99 startButton.addMouseListener(new MouseListener() {
101 public void mouseDoubleClick(MouseEvent arg0) {
105 public void mouseDown(MouseEvent arg0) {
111 public void mouseUp(MouseEvent arg0) {
115 }); // end add action listener.
122 private void buildSettingsComposite(Composite parent) {
125 settingsInfoComposite = new Group(parent, SWT.NONE);
126 // settingsInfoComposite.setText("Settings");
127 // settingsInfoComposite.setLayout(new GridLayout(2,false));
130 // //the test suite to launch
131 // Label testSuiteLabel = new Label(settingsInfoComposite, SWT.NONE);
132 // testSuiteLabel.setText("Test suite to run:");
133 // //testSuiteLabel.setLayoutData(new GridData())
134 // Text testSuiteText = new Text(settingsInfoComposite, SWT.NONE);
137 // Label phpPathLabel = new Label(settingsInfoComposite, SWT.NONE);
138 // phpPathLabel.setText("php Path:");
139 // //testSuiteLabel.setLayoutData(new GridData())
140 // Text phpPathText = new Text(settingsInfoComposite, SWT.NONE);
146 private void setActions() {
147 final IActionBars actionBars = getViewSite().getActionBars();
148 IToolBarManager toolBarManager = actionBars.getToolBarManager();
149 Action action1 = new Action() {};
150 action1.setText("Action 1");
151 action1.setToolTipText("Start the testing");
152 //final URL installUrl = PaintPlugin.getDefault().getDescriptor().getInstallURL();
153 //final URL imageUrl = new URL(installUrl, PaintPlugin.getResourceString(id + ".image"));
154 // URL imageUrl = null;
157 // new URL("C:\\sample.gif");
158 // } catch (MalformedURLException e) {
159 // // TODO Auto-generated catch block
160 // e.printStackTrace();
162 // action1.setImageDescriptor(ImageDescriptor.createFromURL(imageUrl));
164 action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
165 getImageDescriptor(ISharedImages.IMG_OBJS_TASK_TSK));
166 toolBarManager.add(action1);
172 * @see org.eclipse.ui.IWorkbenchPart#setFocus()
174 public void setFocus() {
179 * mark the given test as passed in the GUI.
183 public void markTestPassed(String testID) {
185 // testid, use it in hashmap to retrieve tree item of test and
186 // change icon color, increment pass counter, etc...
188 testPool.getTest(testID).setVerdict(Test.PASS);
193 public void markTestStarted(String testID) {
199 public void createNewTest(String testName, String testID) {
201 testPool.addTest(new Test(testName, testID));
204 public void markTestFail(String testID) {
206 testPool.getTest(testID).setVerdict(Test.FAIL);
210 public void markTestingStarted(int numTestsToBeRun) {
212 this.numTests = numTestsToBeRun;
213 //reportArea.append("Tests started expecting: " + numTests + " \n");
217 public void markTestingFinished() {
220 //reportArea.append("end all tests \n");
224 // action to start tests:
225 private void startTests() {
228 // take the full test suite (could containt other test suites).
229 // create temp php file that starts that suite and uses socketTestReport
230 // as a test result reporter.
231 // add listener: localhost , port 13579
232 // start listening at port.
238 Runtime.getRuntime().exec("php.exe \"C:/Program Files/Apache Group/Apache2/htdocs/phpUnit/suite.php\"");
239 } catch (IOException e) {
240 // TODO Auto-generated catch block
249 private void listenForReports() {
251 ConnectionListener conListener = new ConnectionListener();
252 conListener.start(this);
257 * handle this report: test passed, faile, end of all.
260 public void handleReport(String report) {
262 //delegate to the XML report handler.
263 handler.handle(report, this);
273 public void handleCommand(
279 if (command.equals("startAll")) {
281 markTestingStarted(new Integer(testCount).intValue());
284 }else if (command.equals("testStarted")) {
286 createNewTest("testName", testID);
287 markTestStarted(testID);
289 } else if (command.equals("testFINISHED")) {
293 } else if (command.equals("endAll")) {
295 markTestingFinished();
299 progressInfoComposite.updateInfo(numTests, numTestsRun, numFailures, numErrors);
300 resultsInfoComposite.updateInfo(testPool);
307 private void markTestFinished() {
316 private void updateResultsInfo() {
317 // TODO Auto-generated method stub
322 * @param currentTestID
325 public void setTestVerdict(String currentTestID, String verdict) {
327 if (verdict.equals("passed"))
328 markTestPassed(currentTestID);
330 markTestFail(currentTestID);
335 * @param currentTestID
338 public void addTestException(String currentTestID, String exception) {
340 //TODO: decide how to show exceptions. don't show them for now.
341 //reportArea.append(" test " + currentTestID + " exception: " + exception + "\n");