Updated en/topics/testing/index.md for clearer PHPUnit installation instructions

Step by step Composer installation instructions, including a composer.json example.

In addition:
- Removed self-page reference to an introduction
- Removed reference to PEAR installation instructions due to end of life
- Removed reference to Ruby as doesn't add value
- Shortened testing via Web Browser section (as covered in Composer installation instructions)
This commit is contained in:
AntonyThorpe 2014-09-08 17:13:36 +12:00
parent 9f3506bf02
commit f5ccdda22f

View File

@ -13,39 +13,52 @@ If you're more familiar with unit testing, but want a refresher of some of the c
the [Testing Glossary](glossary). To get started now, follow the installation instructions below, and check
[Troubleshooting](testing-guide-troubleshooting) in case you run into any problems.
If you are familiar with PHP coding but new to unit testing, you should read the [Introduction](/topics/testing) and
check out Mark's presentation [Getting to Grips with SilverStripe Testing](http://www.slideshare.net/maetl/getting-to-grips-with-silverstripe-testing).
If you are familiar with PHP coding but new to unit testing then check out Mark's presentation [Getting to Grips with SilverStripe Testing](http://www.slideshare.net/maetl/getting-to-grips-with-silverstripe-testing).
[Why Unit Test?](why-should-i-test) will give you reasons why you should be testing your code.
You should also read over [the PHPUnit manual](http://www.phpunit.de/manual/current/en/). It provides a lot of
fundamental concepts that we build on in this documentation.
## Installation
### Via Composer
Unit tests are not included in the normal SilverStripe downloads, you are expected to work with local git repositories
Unit tests are not included in the normal SilverStripe downloads so you need to install them through git repositories
([installation instructions](/installation/composer)).
Once you've got the project up and running, check out the additional requirements to run unit tests:
## Install with Composer
Once you've got your project up and running, add PHPUnit to your composer.json (in your project root) as a package required for development (note that SilverStripe is not compatible with PHPUnit 4). Example below:
{
"name": "silverstripe/installer",
"description": "The SilverStripe Framework Installer",
"require": {
"php": ">=5.3.2",
"silverstripe/cms": "~3.1@stable",
"silverstripe/framework": "~3.1@stable",
"silverstripe-themes/simple": "*"
},
"require-dev": {
"phpunit/PHPUnit": "~3.5@stable"
},
"config": {
"process-timeout": 600
},
"minimum-stability": "dev"
}
In the terminal cd to your project root and install the required components to run unit tests:
composer update --dev
This will install (among other things) the [PHPUnit](http://www.phpunit.de/) dependency, which is the framework we're
building our unit tests on. Composer installs it alongside the required PHP classes into the `vendor/bin/` directory.
You can either use it through its full path (`vendor/bin/phpunit`), or symlink it into the root directory of your website:
Open a browser at `http://localhost/dev/tests` to see a list of available tests. Run a test to ensure the installation is complete.
### Symlinking the PHPUnit Binary
You can either use PHPUnit through its full path (`vendor/bin/phpunit`), or symlink it into the root directory of your website:
ln -s vendor/bin/phpunit phpunit
### Via PEAR
Alternatively, you can check out PHPUnit globally via the PEAR package manager
([instructions](https://github.com/sebastianbergmann/phpunit/)).
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit
## Configuration
### phpunit.xml
@ -83,8 +96,6 @@ You will generally write two different kinds of test classes.
* **Unit Test:** Test the behaviour of one of your DataObjects.
* **Functional Test:** Test the behaviour of one of your controllers.
Some people may note that we have used the same naming convention as Ruby on Rails.
Tutorials and recipes for creating tests using the SilverStripe framework:
* [Creating a SilverStripe test](creating-a-silverstripe-test): Writing tests to check core data objects
@ -140,7 +151,6 @@ particularly around formatting test output.
### Via Web Browser
Executing tests from the command line is recommended, since it most closely reflects
test runs in any automated testing environments. If for some reason you don't have
access to the command line, you can also run tests through the browser.
test runs in any automated testing environments. However, you can also run tests through the browser:
http://localhost/dev/tests