how to load a model inside modules/../model
ayokay123 opened this issue · 15 comments
hey, when i try to load public
function setUp()
{
$this->resetInstance();
$this->CI->load->model(i want to acces model in modules/foo/models/foo_model);
$this->obj = $this->CI->???;
}
i can only find the models in application/models i can't find models in application/modules/.../models
CodeIgniter cannot load models not in application/models
.
should i copie the application/tests folder in each folder inside /modules ?? can that work
You have to dig into how do you load the model in the modules
folder.
And implement the logic into ci-phpunit-test.
I don't remember how CodeIgniter-HMVC does it.
do you have any links or resources i could use ?? because i have searched alot with no success
Read CodeIgniter-HMVC code to find out how it loads a model in the modules folder.
i have this method line 197 https://github.com/xttrust/codeigniter-modular-extensions-hmvc-fixed/blob/master/third_party/MX/Loader.php where exactly can i implement it in ci-phpunit-test
- https://github.com/xttrust/codeigniter-modular-extensions-hmvc-fixed/blob/6dcad78fec9c4afb233e7ecc3618dcd7cedda5cd/third_party/MX/Loader.php#L198
- https://github.com/xttrust/codeigniter-modular-extensions-hmvc-fixed/blob/6dcad78fec9c4afb233e7ecc3618dcd7cedda5cd/third_party/MX/Loader.php#L47
- https://github.com/xttrust/codeigniter-modular-extensions-hmvc-fixed/blob/6dcad78fec9c4afb233e7ecc3618dcd7cedda5cd/third_party/MX/Router.php#L40
How about setting MX_Router
property $module
?
$this->resetInstance();
CI::$APP->router->module = 'foo';
$this->CI->load->model('foo_model');
Error: Call to undefined method MY_Loader::get_details()
@ayokay123 What's your environment?
- OS
- PHP
- PHPUnit
- CodeIgniter
- HMVC
os: ubuntu (im using docker for the project)
php:7.2
phpunit:7
ci: 3.1.3
hmvc not sure
It seems there is no get_details()
method in MX_Loader
:
https://github.com/lemondropsarl/webase/blob/master/application/third_party/MX/Loader.php
from #34 (comment)
And also not in original HMVC's MX_Loader
:
https://github.com/kenjis/ci-hmvc-ci-phpunit-test/blob/master/application/third_party/MX/Loader.php
@ayokay123
I've updated my sample repository, and worked the following test case:
https://github.com/kenjis/ci-hmvc-ci-phpunit-test/blob/master/application/tests/modules/welcome/models/Foo_model_test.php
thank you very much, it works now
i have another question if you can help .Can i ignore a database when i do migration in TestCase?
@ayokay123 File another issue for another question.
And Please explain what you want to do as detailed as possible.