Using PHPUnit

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Using PHPUnit

Post by Jonah Bron »

¡Hola, mundo!

I'm trying to implement PHPUnit in a project of mine. Their site recommends installing in via PEAR. Does that mean any other developers that were to checkout the repository would have to install PHPUnit themselves on their own machine? If so, how does one include the right files for the tests?

¡Muchas gracias, señores!
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Using PHPUnit

Post by Darhazer »

This depends whether you want to ship your unit tests with your code or not. If you are building open source project and you want to ship the unit tests, the developers will need to install PHPUnit as well. If you are building a product you'll sell (or distribute free), usually it's shipped without the unit tests.

Or, in another way, if your users are supposed to modify the code, they will need to install PHPUnit to use the unit tests, otherwise you don't need to provide the tests.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Using PHPUnit

Post by Jonah Bron »

Okay, that's what I was looking for. How do I include the right path in the individual unit tests?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Using PHPUnit

Post by Weirdan »

Jonah Bron wrote:Okay, that's what I was looking for. How do I include the right path in the individual unit tests?
By referencing relative paths and relying on include_path (PEAR code repository is usually listed under include_path):

Code: Select all

require 'PHPUnit/Framework/TestCase.php';
class SomeTest extends PHPUnit_Framework_TestCase {
    // ..........
}
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Using PHPUnit

Post by Jonah Bron »

Aha, excellent. They ought to put that into the documentation :)

Thanks.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Using PHPUnit

Post by Jonah Bron »

Hm, /usr/share/php is in include_path, and it contains PHPUnit/. But it doesn't seem to contain the PHPUnit stuff. /usr/share/pear doesn't exist, and /usr/share/php/PEAR doesn't have any PHPUnit stuff either. Here's /usr/share/php/PHPUnit/:

[text] |-Extensions
|---Database
|-----Constraint
|-----DataSet
|-------Persistors
|-------Specs
|-----DB
|-------MetaData
|-----Operation
|-----UI
|-------Mediums
|-------Modes
|---------ExportDataSet
|---SeleniumTestCase
|---Story
|-Framework
|---MockObject
|-----Builder
|-----Generator
|-----Invocation
|-----Matcher
|-----Stub[/text]
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Using PHPUnit

Post by Weirdan »

But it doesn't seem to contain the PHPUnit stuff.
What kind of stuff you were expecting to see there? The directory structure you posted looks very much like PHPUnit's.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Using PHPUnit

Post by Jonah Bron »

Well, none of the classes are there that I was expecting. Where is TestCase.php normally in that structure?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Using PHPUnit

Post by Weirdan »

Jonah Bron wrote:Well, none of the classes are there that I was expecting. Where is TestCase.php normally in that structure?
/usr/share/php/PHPUnit/Framework/TestCase.php
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Using PHPUnit

Post by Jonah Bron »

But it's not there. Just the MockObject/ folder.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Using PHPUnit

Post by Weirdan »

Are you sure you have PHPUnit installed? What does

Code: Select all

sudo pear list
show?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Using PHPUnit

Post by Jonah Bron »

Strange, PHPUnit isn't listed. I tried running the install command again, and now it tells me that I need to upgrade from PEAR 1.9.1 to 1.9.2. But I have it installed via Ubuntu repository? Surely they haven't come out with a new version since I updated a few days ago. I'm updating now just in case. Do I have to download and install it manually?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Using PHPUnit

Post by Jonah Bron »

Never mind, found the solution on Superuser here: http://superuser.com/questions/55055/

Funny, you have to tell PEAR to update itself through it's own mechanism, and then it work. Ah, the infinite mysteries of software :)
Post Reply