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