From f5ccdda22fba6165b6dc66927c7b2dfbffecaceb Mon Sep 17 00:00:00 2001 From: AntonyThorpe Date: Mon, 8 Sep 2014 17:13:36 +1200 Subject: [PATCH 1/3] 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) --- docs/en/topics/testing/index.md | 52 ++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/docs/en/topics/testing/index.md b/docs/en/topics/testing/index.md index 4aed3e7b8..a32e1c2b2 100644 --- a/docs/en/topics/testing/index.md +++ b/docs/en/topics/testing/index.md @@ -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 From da8cebaa6287eccb7160185ef5f95a58737c01b4 Mon Sep 17 00:00:00 2001 From: AntonyThorpe Date: Fri, 12 Sep 2014 17:02:04 +1200 Subject: [PATCH 2/3] Describe adding PHPUnit as a simple one line command - Removed the composer.json example - Removed comment about PHPUnit versions Signed-off-by: AntonyThorpe --- docs/en/topics/testing/index.md | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/docs/en/topics/testing/index.md b/docs/en/topics/testing/index.md index a32e1c2b2..37045309d 100644 --- a/docs/en/topics/testing/index.md +++ b/docs/en/topics/testing/index.md @@ -25,32 +25,12 @@ Unit tests are not included in the normal SilverStripe downloads so you need to ## 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" - } +Once you've got your project up and running, open a terminal and cd to your project root. -In the terminal cd to your project root and install the required components to run unit tests: + composer require --dev "phpunit/phpunit:3.7.*@stable" - 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. +This will install [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. Open a browser at `http://localhost/dev/tests` to see a list of available tests. Run a test to ensure the installation is complete. From 11187c56c06c70c523da85596903c4bfebfb2a27 Mon Sep 17 00:00:00 2001 From: AntonyThorpe Date: Wed, 17 Sep 2014 16:49:52 +1200 Subject: [PATCH 3/3] Updated for PHPUnit version clarification Updated Composer command to reference latest stable version as advised Removed testing installation via Browser step Added a note about the PHPUnit 3.7 requirement for running tests via the Browser --- docs/en/topics/testing/index.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/en/topics/testing/index.md b/docs/en/topics/testing/index.md index 37045309d..657a68d79 100644 --- a/docs/en/topics/testing/index.md +++ b/docs/en/topics/testing/index.md @@ -27,13 +27,11 @@ Unit tests are not included in the normal SilverStripe downloads so you need to Once you've got your project up and running, open a terminal and cd to your project root. - composer require --dev "phpunit/phpunit:3.7.*@stable" + composer require --dev "phpunit/phpunit:*@stable" This will install [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. -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: @@ -131,6 +129,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. However, you can also run tests through the browser: +test runs in any automated testing environments. However, you can also run tests through the browser (requires PHPUnit version 3.7.*@stable): http://localhost/dev/tests