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
Copy file name to clipboardExpand all lines: README.md
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,8 +19,9 @@ An easier way to use PHPUnit with [CodeIgniter](https://github.com/bcit-ci/CodeI
19
19
20
20
* PHP 5.4.0 or later (5.6 or later is recommended)
21
21
* CodeIgniter 3.x
22
-
* PHPUnit 4.3 or later (4.7 or later is recommended)
23
-
* If you use NetBeans 8.0.2, please use 4.7. 4.8 is not compatible yet. You can download old version of `phpunit.phar` from <https://phar.phpunit.de/>.
22
+
* PHPUnit 4.3 or later (4.8 or later is recommended)
23
+
* If you use PHPUnit 6.0, please use ci-phpunit-test v0.14.0 or later.
24
+
* You can download old version of `phpunit.phar` from <https://phar.phpunit.de/>.
Copy file name to clipboardExpand all lines: docs/HowToWriteTests.md
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -260,7 +260,7 @@ class Inventory_model_test extends TestCase
260
260
261
261
[$this->newModel()](FunctionAndClassReference.md#testcasenewmodelclassname) method in ci-phpunit-test is a helper method to reset CodeIgniter instance and create new model instance.
262
262
263
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/models/Category_model_test.php).
263
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/models/Category_model_test.php).
264
264
265
265
#### Database Seeding
266
266
@@ -281,7 +281,7 @@ You can use them like below:
281
281
}
282
282
~~~
283
283
284
-
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.13.0/application/tests/models/Category_model_test.php).
284
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/models/Category_model_test.php).
285
285
286
286
#### Using PHPUnit Mock Objects
287
287
@@ -344,7 +344,7 @@ If you don't know well about PHPUnit Mock Objects, see [Test Doubles](https://ph
344
344
}
345
345
~~~
346
346
347
-
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).
347
+
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).
348
348
349
349
### Libraries
350
350
@@ -384,7 +384,7 @@ You can use [$this->request()](FunctionAndClassReference.md#testcaserequestmetho
384
384
385
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.
386
386
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
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/sub/Sub_test.php).
388
388
389
389
If you want to call a controller method directly, you can pass an array to the 2nd argument of `$this->request()`.
390
390
@@ -404,7 +404,7 @@ class Welcome_test extends TestCase
404
404
405
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.
406
406
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
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/Welcome_test.php).
408
408
409
409
#### REST Request
410
410
@@ -442,7 +442,7 @@ You can set request header with [$this->request->setHeader()](FunctionAndClassRe
442
442
}
443
443
~~~
444
444
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
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/api/Example_test.php).
446
446
447
447
#### Ajax Request
448
448
@@ -457,7 +457,7 @@ You can use [$this->ajaxRequest()](FunctionAndClassReference.md#testcaseajaxrequ
457
457
}
458
458
~~~
459
459
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
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/Ajax_test.php).
461
461
462
462
#### Request and Use Mocks
463
463
@@ -487,7 +487,7 @@ You can use [$this->request->setCallable()](FunctionAndClassReference.md#request
487
487
488
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.
489
489
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
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/Mock_phpunit_test.php).
491
491
492
492
The function you set by `$this->request->setCallable()` runs after controller instantiation. So you can't inject mocks into controller constructor.
493
493
@@ -537,7 +537,7 @@ In this case, You can use [$this->request->setCallablePreConstructor()](Function
537
537
}
538
538
~~~
539
539
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
+
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).
541
541
542
542
**Note:** If you can't create mocks or it is too hard to create mocks, it may be better to use Monkey Patching.
543
543
@@ -601,7 +601,7 @@ I recommend using PHPUnit mock objects. [$this->getDouble()](FunctionAndClassRef
601
601
}
602
602
~~~
603
603
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
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/Auth_test.php).
605
605
606
606
#### `redirect()`
607
607
@@ -621,7 +621,7 @@ If you use `redirect()` in ci-phpunit-test, you can write tests like this:
621
621
622
622
[$this->assertRedirect()](FunctionAndClassReference.md#testcaseassertredirecturi-code--null) is a method in ci-phpunit-test.
623
623
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
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/Redirect_test.php).
625
625
626
626
##### Upgrade Note for v0.4.0
627
627
@@ -663,7 +663,7 @@ You can use [$this->assertResponseCode()](FunctionAndClassReference.md#testcasea
663
663
}
664
664
~~~
665
665
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
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/Nocontroller_test.php).
667
667
668
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.
669
669
@@ -713,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.13.0/application/tests/controllers/Hook_test.php).
716
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/Hook_test.php).
717
717
718
718
#### Controller with Name Collision
719
719
@@ -739,7 +739,7 @@ class sub_Welcome_test extends TestCase
739
739
}
740
740
~~~
741
741
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
+
See [working sample](https://github.com/kenjis/ci-app-for-ci-phpunit-test/blob/v0.14.0/application/tests/controllers/sub/Welcome_test.php).
743
743
744
744
### Mock Libraries
745
745
@@ -875,15 +875,15 @@ A test case could be like this:
875
875
}
876
876
~~~
877
877
878
-
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).
878
+
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).
879
879
880
880
#### Patching Functions
881
881
882
882
This patcher allows replacement of global functions that can't be mocked by PHPUnit.
883
883
884
884
But it has a few limitations. Some functions can't be replaced and it might cause errors.
885
885
886
-
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).
886
+
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).
887
887
888
888
~~~php
889
889
public function test_index()
@@ -896,7 +896,7 @@ So by default we can replace only a dozen pre-defined functions in [FunctionPatc
896
896
897
897
[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.
898
898
899
-
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).
899
+
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).
900
900
901
901
**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.
902
902
@@ -929,11 +929,11 @@ You could change return value of patched function using PHP closure:
929
929
);
930
930
~~~
931
931
932
-
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).
932
+
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).
933
933
934
934
**Patch on Other Functions**
935
935
936
-
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()`.
936
+
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()`.
937
937
938
938
But there are a few known limitations:
939
939
@@ -958,7 +958,7 @@ This patcher allows replacement of methods in user-defined classes.
958
958
959
959
[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.
960
960
961
-
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).
961
+
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).
962
962
963
963
#### Patching Constants
964
964
@@ -1015,7 +1015,7 @@ If you want to use the constant patcher, please add `ConstantPatcher` in the `pa
0 commit comments