![]() Verify invocations $ this-> verifyInvokedOnce( $db-> method( 'get')-> willReturn( $db_result) $db = $ this-> getMockBuilder( 'CI_DB_pdo_sqlite_driver') $db_result-> method( 'result')-> willReturn( $return) $db_result = $ this-> getMockBuilder( 'CI_DB_pdo_result') Create mock objects for CI_DB_pdo_result and CI_DB_pdo_sqlite_driver $return = [Ġ => ( object) ,ġ => ( object) ,Ģ => ( object) , $ this-> obj = $ this-> newModel( 'Category_model') To change the search paths, change the line CIPHPUnitTest::init() in tests/Bootstrap.php like below: AutoloaderĬi-phpunit-test has an autoloader for class files. If you use $this->request->enableHooks() and $this->request(), hook pre_controller, post_controller_constructor, post_controller and display_override are called on every $this->request() to a controller. If you enable CodeIgniter's hooks, hook pre_system is called once in PHPUnit bootstrap. After resetting, you can (and must) create a new your Controller instance with new state. Reset CodeIgniter objectĬodeIgniter has a function get_instance() to get the CodeIgniter object (CodeIgniter instance or CodeIgniter super object).Ĭi-phpunit-test has a new function reset_instance() which reset the current CodeIgniter object. ![]() ![]() ![]() Using it, you can easily test controllers that contain redirect(). I recommend you not using exit() or die() in your code.Ĭi-phpunit-test has functionality that makes all exit() and die() in your code throw CIPHPUnitTestExitException.Īnd ci-phpunit-test has special show_error() and show_404().Ĭi-phpunit-test replaces redirect() function in URL helper. When a test exercises code that contains exit() or die() statement, the execution of the whole test suite is aborted.įor example, if you write exit() in your controller code, your testing ends with it. If your MY_Output overrides the above methods, you have to take care of changes in the CI_Output of ci-phpunit-test. MY_OutputĬi-phpunit-test replaces CI_Output and modifies below method:īut if you place MY_Output, your MY_Output extends the CI_Output of ci-phpunit-test. If your MY_Input overrides the above methods, you have to take care of changes in the CI_Input of ci-phpunit-test. MY_InputĬi-phpunit-test replaces CI_Input and modifies below method:īut if you place MY_Input, your MY_Input extends the CI_Input of ci-phpunit-test. If your MY_Loader overrides the above methods, you have to take care of changes in the CI_Loader of ci-phpunit-test. MY_LoaderĬi-phpunit-test replaces CI_Loader and modifies below methods:īut if you place MY_Loader, your MY_Loader extends the loader of ci-phpunit-test. Note to Maintainer: If you modify another CodeIgniter file, update bin/check-diff.sh, bin/check-ci-diff.sh and bin/filelist.sh, too. function force_download() in Download helperĪll of them are placed in tests/_ci_phpunit_test/replacing folder.Ĭi-phpunit-test has a modified bootstrap file:.The core functions and classes which are modified: But I try to modify as little as possible. In fact, it uses modified classes and some functions. The more you modify them, the more you get difficulties when you update CodeIgniter. Can and Can'tĬi-phpunit-test does not want to modify CodeIgniter files. If you don't know well about config files and environments, see CodeIgniter User Guide. It is a beginners' guide to automated testing in PHP. If you are not familiar with testing, I recommend you read our book, CodeIgniter Testing Guide. You should read Writing Tests for PHPUnit. You should test models first, and test them well.Īnd PHPUnit has great documentation.You don't have to write your business logic in your controllers.Patching Methods in User-defined Classes.
0 Comments
Leave a Reply. |