ZS 7.0.1 and PHPUnit

General discussion on Zend Studio
bleak
Posts: 21
Joined: Sun May 03, 2009 8:27 pm

ZS 7.0.1 and PHPUnit

Post by bleak » Wed Oct 07, 2009 5:47 am

I'm having a couple of problems related to ZS' built-in PHPUnit capabilities. I've tried searching the docs, and Internet at large, for answers; but, so far, no luck.

1. I have a project set up with a directory structure that conforms to that recommended for use with the Zend Framework, and includes a '/tests' directory. When attempting to create new unit test cases for my files, I follow the instructions given in the docs: right-click the file->New->PHPUnit Test Case. The wizard dialog sets the source folder correctly and lists PHPUnit_Framework_TestCase as the superclass. However, under "Element to test:" there is nothing available for either 'Class' or 'Function'. After ticking the radio button for either, clicking the 'Browse...' button brings up a new dialog box which is completely empty in both cases. That means that ZS cannot correctly construct testing skeletons for me, so I'm having to do it all by hand.

2. Even when I create test cases by hand, ZS won't run them. All I get is an error message that says:
Unable to run PHPUnit session. Only PHPUnit classes can be run as PHPUnit tests.

Reason:
No tests found in ClassTest.php
However, my test cases ARE PHPUnit classes (or extensions of PHPUnit_Framework_TestCase, anyway) and DO contain test methods. Here's a short example:

Code: Select all

<?php

require_once 'Fs/Model/Entry.php';

class Fs_Model_EntryTest extends PHPUnit_Framework_TestCase
{
	
	public function test_setAllowedObjectProperty()
	{
		$entry = new Fs_Model_Entry;
		$entry->title = 'My Title';
		
		$this->assertEquals('My Title', $entry-title);
	}
	
	public function test_constructorInjectionOfProperties()
	{
		$data = array(
			'title'				=>	'My Title',
			'content'			=>	'My Content',
			'published_date'	=>	'2009-10-06T10:58:00Z',
			'author'			=>	new Fs_Model_Author
		);
		$entry = new Fs_Model_Entry($data);
		$expected = $data;
		$expected['id'] = null;
		
		$this->assertEquals($expected, $entry->toArray());
	}

        ...
The tests reside in /tests/Fs/Model/ and /library/Fs is in my include_path. Running ZS 7.0.1 on Mac OSX 10.6.1.

Are there any fixes out there for these problems?

User avatar
ganoro
Posts: 409
Joined: Wed Jan 21, 2009 5:00 pm

Re: ZS 7.0.1 and PHPUnit

Post by ganoro » Wed Oct 07, 2009 7:53 am

Two questions:
1. can you try to include the PHPUnit test case file?
2. Do you have the PHPUnit library in your include path?

Roy

bleak
Posts: 21
Joined: Sun May 03, 2009 8:27 pm

Re: ZS 7.0.1 and PHPUnit

Post by bleak » Wed Oct 07, 2009 3:12 pm

ganoro wrote:Two questions:
1. can you try to include the PHPUnit test case file?
2. Do you have the PHPUnit library in your include path?

Roy
1. I added a 'require_once' statement for TestCase.php, but still get the same error.
2. No. Since PHPUnit is built in to ZS, I assumed the latter would handle path resolutions for it.

User avatar
ganoro
Posts: 409
Joined: Wed Jan 21, 2009 5:00 pm

Re: ZS 7.0.1 and PHPUnit

Post by ganoro » Wed Oct 07, 2009 9:43 pm

bleak wrote: 2. No. Since PHPUnit is built in to ZS, I assumed the latter would handle path resolutions for it.
It is built in but you need to include it so the PHPUnit test case will be recognized.
Right-click on the project and select PHP include path, add the PHPUnit library.

Roy

bleak
Posts: 21
Joined: Sun May 03, 2009 8:27 pm

Re: ZS 7.0.1 and PHPUnit

Post by bleak » Thu Oct 08, 2009 1:58 pm

ganoro wrote:
bleak wrote: 2. No. Since PHPUnit is built in to ZS, I assumed the latter would handle path resolutions for it.
It is built in but you need to include it so the PHPUnit test case will be recognized.
Right-click on the project and select PHP include path, add the PHPUnit library.

Roy
I right-clicked on the project, navigated to Properties->PHP Include Path and added the PHPUnit library (/Applications/Zend/Zend Studio - 7.0.1/plugins/com.zend.php.phpunit_7.0.0.v20090831-0030/resources/library) to no effect. I'm still getting the same error message and refusal to run tests.

frenck
Posts: 3
Joined: Sat Oct 10, 2009 11:01 pm
Location: Enschede, The Netherlands
Contact:

Re: ZS 7.0.1 and PHPUnit

Post by frenck » Sun Oct 11, 2009 6:22 pm

I'm having the same problems.

I've tried ZS7.0.2 & 7.1Beta... Suggested solutions have no effect.

katat
Posts: 2
Joined: Wed Oct 21, 2009 7:05 am

Re: ZS 7.0.1 and PHPUnit

Post by katat » Wed Oct 21, 2009 7:06 am

same problem as I have

katat
Posts: 2
Joined: Wed Oct 21, 2009 7:05 am

Re: ZS 7.0.1 and PHPUnit

Post by katat » Wed Oct 21, 2009 7:24 am

I have just tried to add the source folders of a project into the project's php build/include path to see if the phpunit zend studio can recognize the elements, and it works! Although the element dialog is still nothing available, it automatically add the source file I want to test into the "element to test" text field after opening the test case wizard dialog by right clicking the source file I want to test.

jon_bauer
Posts: 1
Joined: Thu Nov 05, 2009 9:22 pm

Re: ZS 7.0.1 and PHPUnit

Post by jon_bauer » Thu Nov 05, 2009 9:31 pm

I'm having the same problem. Everything worked great at first. Then I added another project and it stopped working and displayed the same errors listed here. The editor resolves the PHPUnit library fine, but it does not recognize the tests.

The only way I was able to get it to work was to go to: Run->Run Configurations->PHPUnit and select "Run all tests in the selected project, source folder or file", and enter the path to my tests directory in the new project.

Now, I can trigger the tests to run by highlighting the main project folder in my Navigator, then clicking on Run As -> PHPUnit Test

This runs my tests in my tests folder fine, however I need to "Clean" the project before it will even show me that option.

I still can not control-click on the actual testsSuite.php file and run that as PHPUnit test like I used to. That action still gives me the "Unable to run PHPUnit session" error.

hope that helps.

nsdhami
Posts: 1
Joined: Tue Feb 10, 2009 2:11 am

Re: ZS 7.0.1 and PHPUnit

Post by nsdhami » Tue Dec 01, 2009 6:42 am

I am also having the same problem and I modified settings in buildpath and include_path, tried running "Run all" but failed to execute. Any additional help will be appreciable.

Post Reply