Skip to content

Commit

Permalink
Update docs for release
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Apr 22, 2017
1 parent 01f3939 commit 799b5ee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion application/tests/_ci_phpunit_test/ChangeLog.md
@@ -1,6 +1,6 @@
# Change Log for ci-phpunit-test

## v0.15.0 (Not Released)
## v0.15.0 (2017/04/23)

### Added

Expand Down
40 changes: 20 additions & 20 deletions docs/HowToWriteTests.md
Expand Up @@ -260,7 +260,7 @@ class Inventory_model_test extends TestCase

[$this->newModel()](FunctionAndClassReference.md#testcasenewmodelclassname) method in ci-phpunit-test is a helper method to reset CodeIgniter instance and create new model instance.

See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/models/Category_model_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/application/tests/models/Category_model_test.php).

#### Database Seeding

Expand All @@ -281,7 +281,7 @@ You can use them like below:
}
~~~

See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/models/Category_model_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/application/tests/models/Category_model_test.php).

#### Using PHPUnit Mock Objects

Expand Down Expand Up @@ -344,7 +344,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.14.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.15.0/application/tests/models/Category_model_mocking_db_test.php).

### Libraries

Expand Down Expand Up @@ -384,7 +384,7 @@ You can use [$this->request()](FunctionAndClassReference.md#testcaserequestmetho

**Note:** If you pass URI string to the 2nd argument of `$this->request()`, it invokes the routing. If the resolved controller has `_remap()` and/or `_output()` methods, they will be invoked, too.

See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/sub/Sub_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/application/tests/controllers/sub/Sub_test.php).

If you want to call a controller method directly, you can pass an array to the 2nd argument of `$this->request()`.

Expand All @@ -404,7 +404,7 @@ class Welcome_test extends TestCase

**Note:** If you pass an array to the 2nd argument of `$this->request()`, it does not invokes the routing. The `_remap()` and/or `_output()` methods in a controller are not invoked, too.

See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/Welcome_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/application/tests/controllers/Welcome_test.php).

#### REST Request

Expand Down Expand Up @@ -442,7 +442,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.14.0/application/tests/controllers/api/Example_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/application/tests/controllers/api/Example_test.php).

#### Ajax Request

Expand All @@ -457,7 +457,7 @@ You can use [$this->ajaxRequest()](FunctionAndClassReference.md#testcaseajaxrequ
}
~~~

See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/Ajax_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/application/tests/controllers/Ajax_test.php).

#### Request and Use Mocks

Expand Down Expand Up @@ -487,7 +487,7 @@ You can use [$this->request->setCallable()](FunctionAndClassReference.md#request

**Note:** When you have not loaded a class with CodeIgniter loader, if you make a mock object for the class, your application code may not work correclty. If you have got an error, please try to load it with CodeIgniter loader, before getting the mock object.

See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/Mock_phpunit_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/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.

Expand Down Expand Up @@ -537,7 +537,7 @@ In this case, You can use [$this->request->setCallablePreConstructor()](Function
}
~~~

See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.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.15.0/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.

Expand Down Expand Up @@ -601,7 +601,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.14.0/application/tests/controllers/Auth_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/application/tests/controllers/Auth_test.php).

#### `redirect()`

Expand All @@ -621,7 +621,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.14.0/application/tests/controllers/Redirect_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/application/tests/controllers/Redirect_test.php).

##### Upgrade Note for v0.4.0

Expand Down Expand Up @@ -663,7 +663,7 @@ You can use [$this->assertResponseCode()](FunctionAndClassReference.md#testcasea
}
~~~

See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/Nocontroller_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/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.

Expand Down Expand Up @@ -713,7 +713,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.14.0/application/tests/controllers/Hook_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/application/tests/controllers/Hook_test.php).

#### Controller with Name Collision

Expand All @@ -739,7 +739,7 @@ class sub_Welcome_test extends TestCase
}
~~~

See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/sub/Welcome_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/application/tests/controllers/sub/Welcome_test.php).

### Mock Libraries

Expand Down Expand Up @@ -875,15 +875,15 @@ A test case could be like this:
}
~~~

See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/Exit_to_exception_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/application/tests/controllers/Exit_to_exception_test.php).

#### Patching Functions

This patcher allows replacement of global functions that can't be mocked by PHPUnit.

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.14.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.15.0/application/tests/_ci_phpunit_test/patcher/Patcher/FunctionPatcher.php#L27).

~~~php
public function test_index()
Expand All @@ -896,7 +896,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.14.0/application/tests/controllers/Patching_on_function_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/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.

Expand Down Expand Up @@ -929,11 +929,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.14.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.15.0/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.14.0/application/tests/Bootstrap.php#L348) 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.15.0/application/tests/Bootstrap.php#L348) in `MonkeyPatchManager::init()`.

But there are a few known limitations:

Expand All @@ -958,7 +958,7 @@ 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.14.0/application/tests/controllers/Patching_on_method_test.php).
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.15.0/application/tests/controllers/Patching_on_method_test.php).

#### Patching Constants

Expand Down

0 comments on commit 799b5ee

Please sign in to comment.