Can't acces method in Controller
I have this function in Welcome Controller
public function format_tanggal($tanggal)
{
return date('d-m-Y',strtotime($tanggal));
}
But when i write test in WelcomeTest
public function testFormatTanggal(){
$this->requireController('Welcome');
$this->CIC = new Welcome();
$this->assertInstanceOf('CI_Controller', $this->CIC, 'Controller was called correctly');
$this->assertEquals($this->CIC->format_tanggal('02-05-2015'),'05-02-2015');
}
I get this error
Should be easy to XDebug it.
Your $this->CIC must not have been initialized with the Welcome Controller you want.
I also checked CI docs for your method name (that underscore raised some flags for me), but it doesn't seem to be a reserved word since it doesn't actually begins with an underscore.
Thank's, it solved. But i have another question, is it support HMVC?
@zahidmuhammadzaki you mean HHVM? Yes it does. I have a Travis CI on it: https://travis-ci.org/fmalk/codeigniter-phpunit/jobs/99513092
No, I mean Hierarchical Model View Controller, it's modular method in CI.
Oh, sorry. No idea. It puts files in core folder so it'd have to be tested. I honestly don't know if it is a popular extension.
Yeah, it is popular extension.. I hope it can be included in the next development.. Thanks for your response..
I'll consider compatibility within a next minor release, so I'll reopen this issue as a "feature request"
@zahidmuhammadzaki don't forget to comment here if you find any success or bugs trying HMVC with this project
Yes, i will..
I found a hack solution for this HMVC problem..
But firstly, i want to describe what i use and i do:
- I use wiredesignz HMVC
The folders structure looks like this
- I add this function to CITestCase.php to get controller from modules folders
public function requireModuleController($module_path, $prefix = null)
{
list($module,$class) = explode('/', $module_path);
$filepath = APPPATH.'modules'.DIRECTORY_SEPARATOR.$module.DIRECTORY_SEPARATOR.'controllers'.DIRECTORY_SEPARATOR.$prefix.DIRECTORY_SEPARATOR.$class.'.php';
if (file_exists($filepath))
{
require_once($filepath);
}
}
The problem is when i use this function i get this error
So, i debug the function in the Modules.php
And i get NULL value in phpunit
But i get CI_Config Instance when i run in browser
It seem global $CFG is not work in phpunit, i have no idea..
I found some solution to prevent phpunit backups all global variables.
So, I try to disable php backupGlobals to "false"
But it does not work, and i still get null value in phpunit
Then i add few of code to Modules.php
And, It's works!
I want to make it works without hack the HMVC source file. Can anyone help?