phpunit-skeleton
phpunit-skeleton copied to clipboard
PHPUnit skeleton with built-in class autoloading and namespacing for your projects
PHPUnit Skeleton 
Get up and running with PHPUnit testing easily for your project with this skeleton
- Are you frustrated with trying to install and configure PHPUnit?
- Are you wishing you could use just one command and BANG it was all done for you and you could get on with writing your beautiful unit tests?
- Are you having sleepless nights or sleepy afternoons?
Well, I'm happy to let you know that you just need to clone this repo and all your problems will be whisked away (apart from the last one, perhaps).
We have also included a sample PHP class so you can learn a few tricks in how to use PHPUnit in your projects!
Simple-tastic 3 Step Installation
- Open a Terminal. Download the repo with
git clone https://github.com/jasdeepkhalsa/phpunit-skeleton.git cdinto where you downloaded your repo and runphp composer.phar self-update- Now, run
php composer.phar install --dev
Note: php refers to the location of your php executable, if its not on your system's path
Run PHPUnit
- Open a Terminal
cdto your project root- Type
./vendor/bin/phpunitand...magic! Tests (should) now be running!
You should see something like...
PHPUnit 3.7.19 by Sebastian Bergmann.
Configuration read from /(directory)/phpunit-skeleton/phpunit.xml
....
Time: 0 seconds, Memory: 3.00Mb
OK (4 tests, 4 assertions)
Customizing PHPUnit Skeleton
Once you've successfully installed PHPUnit Skeleton, you'll probably want to customize it to your application.
How do I change the name of the application?
Once you have the name of your application which we shall refer to as YourApp, then do the following:
- First you have to change the entry
Applicationin thecomposer.jsonfile toYourAppunder the objectpsr-0:
{ "require-dev": { "phpunit/phpunit": "3.7.*", "phpunit/dbunit": ">=1.2", "phpunit/phpunit-selenium": ">=1.2" }, "autoload": { "psr-0": { "YourApp": "lib/" } } }
- Next, rename the following two directories from
ApplicationtoYourApp:- Rename
/lib/Application/to/lib/YourApp/ - Rename
/tests/Application/to/tests/YourApp/
- Rename
- Finally update the
namespaceinside the following php files:- Inside
/lib/YourApp/Example.phpupdatenamespace Application;tonamespace YourApp; - Inside
/tests/YourApp/ExampleTest.phpupdate$this->obj = new Application\Example;to$this->obj = new YourApp\Example;
- Inside
- Run
php composer.phar updateagain to update the sources - Run
./vendor/bin/phpunitagain to make sure all tests are passing again
Credits
- To the wonderful people on Stack Overflow for helping me understand PHPUnit better
- Constant support from PHP Guru Jujhar Singh from Buto who also inspired the test case style used in the examples
- Class examples inspired from video by Jeffrey Way from Nettuts+
Contact
- Email: jasdeep {at} simplyspiritdesign {dot} com
- Twitter: @JasdeepKhalsa1