How to: CI - PHPUNIT - DATAMAPPER |
[eluser]insert_hilarity_here[/eluser]
Firstly this is not the ideal way to setup unit testing, I have been using this approach and it seems to be working well for me, however the my-ciunit project by kenjis is a much more professional approach (http://d.hatena.ne.jp/Kenji_s/20120117/1326763908) However because I use Datamapper this bug https://bitbucket.org/kenjis/my-ciunit/i...21-in-test caused me too may difficulties so this is why I am not using my-ciunit. This is my approach: 1) Download https://github.com/reggi/cidip/tree/mast...hird_party 2) Modify the $system_path and $application_folder to be relative if needed 3) Above where the code is commented out (//require_once BASEPATH.'core/CodeIgniter.php' ![]() Code: /* 4) Modify the routing setion from this: Code: /* Code: $RTR =& load_class('Router', 'core'); 5) create a tests folder and in it your phpunit bootstrap file should contain a require_once path to the dip file you have just editted Code: <?php 6) Create a controller called cdip (you can all it anything you want really just make sure it matches $alt_default_controller), the controller should look like Code: <?php its just a dummy controller that does nothing. 7) Say you have a library called "test_library" so in the setup function you can now use $ci =& get_instance(); to load that library so you would have something like: Code: <?php 8) You can now start writing your unit tests for your library or model and so on. But be aware you are testing CI as well. 9) Using the environment setting http://ellislab.com/codeigniter/user-gui...vironments you will probably want to use this to load a test version of your database in the dip.php file, so your create, update, delete tests are done on test data. 10) For testing controllers can use an autoloader or add in include_once(APPPATH."controllers/".strtolower($class).EXT); where $class is the class name of the controller into the setUp function, for everything else you can load using $ci variable. |
Welcome Guest, Not a member yet? Register Sign In |