Page 1 of 1
Using PHPUnit
Posted: Mon Mar 28, 2011 7:44 pm
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!
Re: Using PHPUnit
Posted: Tue Mar 29, 2011 2:14 am
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.
Re: Using PHPUnit
Posted: Tue Mar 29, 2011 10:38 am
by Jonah Bron
Okay, that's what I was looking for. How do I include the right path in the individual unit tests?
Re: Using PHPUnit
Posted: Tue Mar 29, 2011 11:14 am
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 {
// ..........
}
Re: Using PHPUnit
Posted: Tue Mar 29, 2011 12:26 pm
by Jonah Bron
Aha, excellent. They ought to put that into the documentation
Thanks.
Re: Using PHPUnit
Posted: Tue Mar 29, 2011 12:42 pm
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]
Re: Using PHPUnit
Posted: Wed Mar 30, 2011 3:02 am
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.
Re: Using PHPUnit
Posted: Wed Mar 30, 2011 10:50 am
by Jonah Bron
Well, none of the classes are there that I was expecting. Where is TestCase.php normally in that structure?
Re: Using PHPUnit
Posted: Wed Mar 30, 2011 11:48 am
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
Re: Using PHPUnit
Posted: Wed Mar 30, 2011 12:33 pm
by Jonah Bron
But it's not there. Just the MockObject/ folder.
Re: Using PHPUnit
Posted: Wed Mar 30, 2011 4:41 pm
by Weirdan
Are you sure you have PHPUnit installed? What does
show?
Re: Using PHPUnit
Posted: Wed Mar 30, 2011 7:23 pm
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?
Re: Using PHPUnit
Posted: Wed Mar 30, 2011 7:29 pm
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
