From e1a73e006cf1216be04b41850136d0fc93a0cf36 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 9 Oct 2015 09:29:40 +0900 Subject: [PATCH] Update docs for release v0.8.2 --- docs/ChangeLog.md | 2 +- docs/FunctionAndClassReference.md | 2 +- docs/HowToWriteTests.md | 46 +++++++++++++++---------------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/ChangeLog.md b/docs/ChangeLog.md index 7b6d0a89..bf2a01ab 100644 --- a/docs/ChangeLog.md +++ b/docs/ChangeLog.md @@ -1,6 +1,6 @@ # Change Log for CI PHPUnit Test -## v0.8.2 (Not Released) +## v0.8.2 (2015/10/09) ### Fixed diff --git a/docs/FunctionAndClassReference.md b/docs/FunctionAndClassReference.md index ff36936e..54e39b1a 100644 --- a/docs/FunctionAndClassReference.md +++ b/docs/FunctionAndClassReference.md @@ -1,6 +1,6 @@ # CI PHPUnit Test for CodeIgniter 3.0 -version: **0.8.0** | +version: **0.8.2** | [v0.7.0](https://github.com/kenjis/ci-phpunit-test/blob/v0.7.0/docs/FunctionAndClassReference.md) | [v0.6.2](https://github.com/kenjis/ci-phpunit-test/blob/v0.6.2/docs/FunctionAndClassReference.md) | [v0.5.0](https://github.com/kenjis/ci-phpunit-test/blob/v0.5.0/docs/FunctionAndClassReference.md) | diff --git a/docs/HowToWriteTests.md b/docs/HowToWriteTests.md index 169b5fa1..58224a49 100644 --- a/docs/HowToWriteTests.md +++ b/docs/HowToWriteTests.md @@ -1,6 +1,6 @@ # CI PHPUnit Test for CodeIgniter 3.0 -version: **0.8.1** | +version: **0.8.2** | [v0.7.0](https://github.com/kenjis/ci-phpunit-test/blob/v0.7.0/docs/HowToWriteTests.md) | [v0.6.2](https://github.com/kenjis/ci-phpunit-test/blob/v0.6.2/docs/HowToWriteTests.md) | [v0.5.0](https://github.com/kenjis/ci-phpunit-test/blob/v0.5.0/docs/HowToWriteTests.md) | @@ -210,7 +210,7 @@ class Inventory_model_test extends TestCase } ~~~ -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/models/Category_model_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/models/Category_model_test.php). #### Database Seeding @@ -231,7 +231,7 @@ You can use them like below: } ~~~ -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/models/Category_model_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/models/Category_model_test.php). #### Using PHPUnit Mock Objects @@ -296,7 +296,7 @@ If you don't know well about PHPUnit Mock Objects, see [Test Doubles](https://ph } ~~~ -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/models/Category_model_mocking_db_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/models/Category_model_mocking_db_test.php). ### Libraries @@ -342,7 +342,7 @@ class Welcome_test extends TestCase } ~~~ -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/Welcome_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/Welcome_test.php). #### Request to URI string @@ -354,7 +354,7 @@ See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v } ~~~ -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/sub/Sub_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/sub/Sub_test.php). #### REST Request @@ -392,7 +392,7 @@ You can set request header with [$this->request->setHeader()](FunctionAndClassRe } ~~~ -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/api/Example_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/api/Example_test.php). #### Ajax Request @@ -407,7 +407,7 @@ You can use [$this->ajaxRequest()](FunctionAndClassReference.md#testcaseajaxrequ } ~~~ -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/Ajax_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/Ajax_test.php). #### Request and Use Mocks @@ -437,7 +437,7 @@ You can use [$this->request->setCallable()](FunctionAndClassReference.md#request **Note:** When you have never loaded a class with CodeIgniter loader, if you make mock object for the class, your application code may not work correclty. If you have got error, please try to load it before getting mock object. -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/Mock_phpunit_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/Mock_phpunit_test.php). The function you set by `$this->request->setCallable()` runs after controller instantiation. So you can't inject mocks into controller constructor. @@ -485,7 +485,7 @@ In this case, You can use [$this->request->setCallablePreConstructor()](Function **Note:** When you have never loaded a class with CodeIgniter loader, if you make mock object for the class, it may not work. If you have got error, please try to load it before getting mock object. -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/Auth_check_in_construct_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/Auth_check_in_construct_test.php). **Note:** If you can't create mocks or it is too hard to create mocks, it may be better to use Monkey Patching. @@ -549,7 +549,7 @@ I recommend using PHPUnit mock objects. [$this->getDouble()](FunctionAndClassRef } ~~~ -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/Auth_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/Auth_test.php). #### `redirect()` @@ -569,7 +569,7 @@ If you use `redirect()` in *CI PHPUnit Test*, you can write tests like this: [$this->assertRedirect()](FunctionAndClassReference.md#testcaseassertredirecturi-code--null) is a method in *CI PHPUnit Test*. -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/Redirect_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/Redirect_test.php). **Upgrade Note for v0.4.0** @@ -611,7 +611,7 @@ You can use [$this->assertResponseCode()](FunctionAndClassReference.md#testcasea } ~~~ -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/Nocontroller_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/Nocontroller_test.php). If you don't call `$this->request()` in your tests, `show_error()` throws `CIPHPUnitTestShowErrorException` and `show_404()` throws `CIPHPUnitTestShow404Exception`. So you must expect the exceptions. You can use `@expectedException` annotation in PHPUnit. @@ -661,7 +661,7 @@ If you want to enable hooks, call [$this->request->enableHooks()](FunctionAndCla $output = $this->request('GET', 'products/shoes/show/123'); ~~~ -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/Hook_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/Hook_test.php). #### Controller with Name Collision @@ -687,7 +687,7 @@ class sub_Welcome_test extends TestCase } ~~~ -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/sub/Welcome_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/sub/Welcome_test.php). ### Mock Libraries @@ -798,7 +798,7 @@ A test case could be like this: } ~~~ -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/Exit_to_exception_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/Exit_to_exception_test.php). #### Patching Functions @@ -806,7 +806,7 @@ This patcher allows replacement of global functions that can't be mocked by PHPU But it has a few limitations. Some functions can't be replaced and it might cause errors. -So by default we can replace only a dozen pre-defined functions in [FunctionPatcher](https://github.com/kenjis/ci-phpunit-test/blob/v0.8.0/application/tests/_ci_phpunit_test/patcher/Patcher/FunctionPatcher.php#L27). +So by default we can replace only a dozen pre-defined functions in [FunctionPatcher](https://github.com/kenjis/ci-phpunit-test/blob/v0.8.2/application/tests/_ci_phpunit_test/patcher/Patcher/FunctionPatcher.php#L27). ~~~php public function test_index() @@ -819,7 +819,7 @@ So by default we can replace only a dozen pre-defined functions in [FunctionPatc [MonkeyPatch::patchFunction()](FunctionAndClassReference.md#monkeypatchpatchfunctionfunction-return_value-class_method) replaces PHP native function `mt_rand()` in `Welcome::index` method, and it will return `100` in the test method. -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/Patching_on_function_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/Patching_on_function_test.php). **Note:** If you call `MonkeyPatch::patchFunction()` without 3rd argument, all the functions (located in `include_paths` and not in `exclude_paths`) called in the test method will be replaced. So, for example, a function in CodeIgniter code might be replaced and it results in unexpected outcome. @@ -852,11 +852,11 @@ You could change return value of patched function using PHP closure: ); ~~~ -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/Patching_on_function_test.php#L59-L80). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/Patching_on_function_test.php#L59-L80). **Patch on Other Functions** -If you want to patch other functions, you can add them to [functions_to_patch](https://github.com/kenjis/ci-phpunit-test/blob/v0.8.0/application/tests/Bootstrap.php#L319) in `MonkeyPatchManager::init()`. +If you want to patch other functions, you can add them to [functions_to_patch](https://github.com/kenjis/ci-phpunit-test/blob/v0.8.2/application/tests/Bootstrap.php#L319) in `MonkeyPatchManager::init()`. But there are a few known limitations: @@ -881,13 +881,13 @@ This patcher allows replacement of methods in user-defined classes. [MonkeyPatch::patchMethod()](FunctionAndClassReference.md#monkeypatchpatchmethodclassname-params) replaces `get_category_list()` method in `Category_model`, and it will return `[(object) ['name' => 'Nothing']]` in the test method. -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.0/application/tests/controllers/Patching_on_method_test.php). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.8.2/application/tests/controllers/Patching_on_method_test.php). ### More Samples Want to see more tests? -* https://github.com/kenjis/ci-app-for-ci-phpunit-test/tree/v0.8.0/application/tests +* https://github.com/kenjis/ci-app-for-ci-phpunit-test/tree/v0.8.2/application/tests * https://github.com/kenjis/codeigniter-tettei-apps/tree/develop/application/tests ### Third Party Libraries @@ -964,4 +964,4 @@ And if you copy sample api controllers, you must change `require` statement to ` If you require `REST_Controller.php` more than once, you get `Fatal error: Cannot redeclare class REST_Controller`. -See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/tree/v0.8.0/application/tests/controllers/api). +See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/tree/v0.8.2/application/tests/controllers/api).