You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -255,7 +256,7 @@ class Inventory_model_test extends TestCase
255
256
}
256
257
~~~
257
258
258
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/models/Category_model_test.php).
259
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/models/Category_model_test.php).
259
260
260
261
#### Database Seeding
261
262
@@ -276,7 +277,7 @@ You can use them like below:
276
277
}
277
278
~~~
278
279
279
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/models/Category_model_test.php).
280
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/models/Category_model_test.php).
280
281
281
282
#### Using PHPUnit Mock Objects
282
283
@@ -341,7 +342,7 @@ If you don't know well about PHPUnit Mock Objects, see [Test Doubles](https://ph
341
342
}
342
343
~~~
343
344
344
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/models/Category_model_mocking_db_test.php).
345
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/models/Category_model_mocking_db_test.php).
345
346
346
347
### Libraries
347
348
@@ -383,7 +384,7 @@ You can use [$this->request()](FunctionAndClassReference.md#testcaserequestmetho
383
384
384
385
**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.
385
386
386
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/sub/Sub_test.php).
387
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/sub/Sub_test.php).
387
388
388
389
If you want to call a controller method directly, you can pass an array to the 2nd argument of `$this->request()`.
389
390
@@ -403,7 +404,7 @@ class Welcome_test extends TestCase
403
404
404
405
**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.
405
406
406
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/Welcome_test.php).
407
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/Welcome_test.php).
407
408
408
409
#### REST Request
409
410
@@ -441,7 +442,7 @@ You can set request header with [$this->request->setHeader()](FunctionAndClassRe
441
442
}
442
443
~~~
443
444
444
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/api/Example_test.php).
445
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/api/Example_test.php).
445
446
446
447
#### Ajax Request
447
448
@@ -456,7 +457,7 @@ You can use [$this->ajaxRequest()](FunctionAndClassReference.md#testcaseajaxrequ
456
457
}
457
458
~~~
458
459
459
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/Ajax_test.php).
460
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/Ajax_test.php).
460
461
461
462
#### Request and Use Mocks
462
463
@@ -486,7 +487,7 @@ You can use [$this->request->setCallable()](FunctionAndClassReference.md#request
486
487
487
488
**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.
488
489
489
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/Mock_phpunit_test.php).
490
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/Mock_phpunit_test.php).
490
491
491
492
The function you set by `$this->request->setCallable()` runs after controller instantiation. So you can't inject mocks into controller constructor.
492
493
@@ -536,7 +537,7 @@ In this case, You can use [$this->request->setCallablePreConstructor()](Function
536
537
}
537
538
~~~
538
539
539
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/Auth_check_in_construct_test.php).
540
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/Auth_check_in_construct_test.php).
540
541
541
542
**Note:** If you can't create mocks or it is too hard to create mocks, it may be better to use Monkey Patching.
542
543
@@ -600,7 +601,7 @@ I recommend using PHPUnit mock objects. [$this->getDouble()](FunctionAndClassRef
600
601
}
601
602
~~~
602
603
603
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/Auth_test.php).
604
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/Auth_test.php).
604
605
605
606
#### `redirect()`
606
607
@@ -620,7 +621,7 @@ If you use `redirect()` in ci-phpunit-test, you can write tests like this:
620
621
621
622
[$this->assertRedirect()](FunctionAndClassReference.md#testcaseassertredirecturi-code--null) is a method in ci-phpunit-test.
622
623
623
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/Redirect_test.php).
624
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/Redirect_test.php).
624
625
625
626
##### Upgrade Note for v0.4.0
626
627
@@ -662,7 +663,7 @@ You can use [$this->assertResponseCode()](FunctionAndClassReference.md#testcasea
662
663
}
663
664
~~~
664
665
665
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/Nocontroller_test.php).
666
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/Nocontroller_test.php).
666
667
667
668
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.
668
669
@@ -712,7 +713,7 @@ If you want to enable hooks, call [$this->request->enableHooks()](FunctionAndCla
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/Hook_test.php).
716
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/Hook_test.php).
716
717
717
718
#### Controller with Name Collision
718
719
@@ -738,7 +739,7 @@ class sub_Welcome_test extends TestCase
738
739
}
739
740
~~~
740
741
741
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/sub/Welcome_test.php).
742
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/sub/Welcome_test.php).
742
743
743
744
### Mock Libraries
744
745
@@ -876,15 +877,15 @@ A test case could be like this:
876
877
}
877
878
~~~
878
879
879
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/Exit_to_exception_test.php).
880
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/Exit_to_exception_test.php).
880
881
881
882
#### Patching Functions
882
883
883
884
This patcher allows replacement of global functions that can't be mocked by PHPUnit.
884
885
885
886
But it has a few limitations. Some functions can't be replaced and it might cause errors.
886
887
887
-
So by default we can replace only a dozen pre-defined functions in [FunctionPatcher](https://github.com/kenjis/ci-phpunit-test/blob/v0.12.2/application/tests/_ci_phpunit_test/patcher/Patcher/FunctionPatcher.php#L27).
888
+
So by default we can replace only a dozen pre-defined functions in [FunctionPatcher](https://github.com/kenjis/ci-phpunit-test/blob/v0.13.0/application/tests/_ci_phpunit_test/patcher/Patcher/FunctionPatcher.php#L27).
888
889
889
890
~~~php
890
891
public function test_index()
@@ -897,7 +898,7 @@ So by default we can replace only a dozen pre-defined functions in [FunctionPatc
897
898
898
899
[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.
899
900
900
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/Patching_on_function_test.php).
901
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/Patching_on_function_test.php).
901
902
902
903
**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.
903
904
@@ -930,11 +931,11 @@ You could change return value of patched function using PHP closure:
930
931
);
931
932
~~~
932
933
933
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/Patching_on_function_test.php#L59-L80).
934
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/Patching_on_function_test.php#L59-L80).
934
935
935
936
**Patch on Other Functions**
936
937
937
-
If you want to patch other functions, you can add them to [functions_to_patch](https://github.com/kenjis/ci-phpunit-test/blob/v0.12.2/application/tests/Bootstrap.php#L348) in `MonkeyPatchManager::init()`.
938
+
If you want to patch other functions, you can add them to [functions_to_patch](https://github.com/kenjis/ci-phpunit-test/blob/v0.13.0/application/tests/Bootstrap.php#L348) in `MonkeyPatchManager::init()`.
938
939
939
940
But there are a few known limitations:
940
941
@@ -959,7 +960,7 @@ This patcher allows replacement of methods in user-defined classes.
959
960
960
961
[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.
961
962
962
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.12.2/application/tests/controllers/Patching_on_method_test.php).
963
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/controllers/Patching_on_method_test.php).
963
964
964
965
#### Patching Constants
965
966
@@ -1016,7 +1017,7 @@ If you want to use the constant patcher, please add `ConstantPatcher` in the `pa
0 commit comments