diff --git a/docs/en/02_Developer_Guides/06_Testing/00_Unit_Testing.md b/docs/en/02_Developer_Guides/06_Testing/00_Unit_Testing.md index 9a520f6e7..a9ccfa755 100644 --- a/docs/en/02_Developer_Guides/06_Testing/00_Unit_Testing.md +++ b/docs/en/02_Developer_Guides/06_Testing/00_Unit_Testing.md @@ -11,9 +11,12 @@ to ensure that it works as it should. A simple example would be to test the resu :::php assertEquals(2, Page::MyMethod()); } } @@ -34,7 +41,9 @@ to ensure that it works as it should. A simple example would be to test the resu Tests for your application should be stored in the `mysite/tests` directory. Test cases for add-ons should be stored in the `(modulename)/tests` directory. -Test case classes should end with `Test` (e.g PageTest) and test methods must start with `test` (e.g testMyMethod). +Test case classes should end with `Test` (e.g `PageTest`) and test methods must start with `test` (e.g `testMyMethod`). + +Ensure you [import](http://php.net/manual/en/language.namespaces.importing.php#example-252) any classes you need for the test, including `SilverStripe\Dev\SapphireTest` or `SilverStripe\Dev\FunctionalTest`. A SilverStripe unit test is created by extending one of two classes, [api:SapphireTest] or [api:FunctionalTest]. @@ -103,13 +112,17 @@ end of each test. :::php "Page $i")); $page->write(); $page->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); @@ -119,11 +132,13 @@ end of each test. Config::inst()->update('Foo', 'bar', 'Hello!'); } - public function testMyMethod() { + public function testMyMethod() + { // .. } - public function testMySecondMethod() { + public function testMySecondMethod() + { // .. } } @@ -134,15 +149,19 @@ individual test case. :::php update('ClassName', 'var_name', 'var_value'); } - function testFeatureDoesAsExpected() { + public function testFeatureDoesAsExpected() + { //this will be reset to 'var_value' at the end of this test function Config::inst()->update('ClassName', 'var_name', 'new_var_value'); } - function testAnotherFeatureDoesAsExpected() { + public function testAnotherFeatureDoesAsExpected() + { Config::inst()->get('ClassName', 'var_name'); // this will be 'var_value' }