-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any luck with ci-phpunit-test working with HMVC? #34
Comments
ci-phpunit-test does not support HMVC. And probably you use WireDesignz's HMVC, but it seems it's hard to make it work with ci-phpunit-test. I'm not sure, but I think https://github.com/jenssegers/codeigniter-hmvc-modules is simple, so it is more clean. So it must be easier to integrate with ci-phpunit-test. Here is quick hack to work. I don't know it works correctly, but at least no errors output. --- a/application/tests/_ci_phpunit_test/CIPHPUnitTest.php
+++ b/application/tests/_ci_phpunit_test/CIPHPUnitTest.php
@@ -31,7 +31,9 @@ class CIPHPUnitTest
// Load new functions of CIPHPUnitTest
require __DIR__ . '/functions.php';
- self::replaceLoader();
+ // Load ci-phpunit-test CI_Loader
+ require __DIR__ . '/replacing/core/Loader.php';
+
self::replaceHelpers();
// Load autoloader for CIPHPUnitTest
@@ -61,6 +63,8 @@ class CIPHPUnitTest
new CI_Controller();
}
+ self::replaceLoader();
+
require APPPATH . '/tests/TestCase.php';
// Restore $_SERVER
@@ -74,12 +78,14 @@ class CIPHPUnitTest
protected static function replaceLoader()
{
- require __DIR__ . '/replacing/core/Loader.php';
$my_loader_file = APPPATH . 'core/' . config_item('subclass_prefix') . 'Loader.php';
if (file_exists($my_loader_file))
{
self::$loader_class = config_item('subclass_prefix') . 'Loader';
- require $my_loader_file;
+ if ( ! class_exists(self::$loader_class))
+ {
+ require $my_loader_file;
+ }
}
self::loadLoader();
}
diff --git a/application/third_party/MX/Modules.php b/application/third_party/MX/Modules.php
index e85ba8f..a91c66d 100644
--- a/application/third_party/MX/Modules.php
+++ b/application/third_party/MX/Modules.php
@@ -2,7 +2,7 @@
(defined('EXT')) OR define('EXT', '.php');
-global $CFG;
+$CFG =& load_class('Config');
/* get module locations from config settings or use the default module location and offset */
is_array(Modules::$locations = $CFG->item('modules_locations')) OR Modules::$locations = array( |
Guideline to debug the problem is: to read CIPHPUnitTest::init() and understand what is done. The problem is how to load core classes and our classes (ci-phpunit-test and hmvc), which one should be loaded earlier, and which one should be used. and see https://github.com/kenjis/ci-phpunit-test/blob/master/docs/HowToWriteTests.md#my_loader |
Thanks, I'll try that or disable HMVC in testing environment and test the modules separately. |
I merged the changes of --- a/application/third_party/MX/Modules.php
+++ b/application/third_party/MX/Modules.php
@@ -2,7 +2,7 @@
(defined('EXT')) OR define('EXT', '.php');
-global $CFG;
+$CFG =& load_class('Config');
/* get module locations from config settings or use the default module location and offset */
is_array(Modules::$locations = $CFG->item('modules_locations')) OR Modules::$locations = array( If there is someone who wants to try HMVC and ci-phpunit-test, please try it. This is just the beginning. I don't know this works fine or not. |
Now you have to apply the patch below: --- a/application/third_party/MX/Loader.php
+++ b/application/third_party/MX/Loader.php
@@ -43,6 +43,12 @@ class MX_Loader extends CI_Loader
/** Initialize the loader variables **/
public function initialize($controller = NULL)
{
+ if (ENVIRONMENT === 'testing')
+ {
+ // Rest CI::$APP
+ CI::$APP = CI_Controller::get_instance();
+ }
+
/* set the module name */
$this->_module = CI::$APP->router->fetch_module();
--- a/application/third_party/MX/Modules.php
+++ b/application/third_party/MX/Modules.php
@@ -4,6 +4,11 @@
global $CFG;
+if (ENVIRONMENT === 'testing')
+{
+ $CFG =& load_class('Config');
+}
+
/* get module locations from config settings or use the default module location and offset */
is_array(Modules::$locations = $CFG->item('modules_locations')) OR Modules::$locations = array(
APPPATH.'modules/' => '../modules/', |
any update? |
If you use --- a/application/third_party/MX/Loader.php
+++ b/application/third_party/MX/Loader.php
@@ -43,6 +43,12 @@ class MX_Loader extends CI_Loader
/** Initialize the loader variables **/
public function initialize($controller = NULL)
{
+ if (ENVIRONMENT === 'testing')
+ {
+ // Rest CI::$APP
+ CI::$APP = CI_Controller::get_instance();
+ }
+
/* set the module name */
$this->_module = CI::$APP->router->fetch_module();
But I don't know you can write tests without problem. If there is someone who wants to use HMVC and ci-phpunit-test, please try it. |
If you use the latest |
Update This week the compatibility of ci-phpunit-test with WireDesignz's HMVC has been greatly increased. If there is someone who wants to use HMVC and ci-phpunit-test, please try the latest |
Hello, so I was going through your repositories. |
No, you need not. The repository is just my sample or testing.
Yes, you can. And my codeigniter-composer-installer is just an installer. Someone who don't like Composer or CLI, he/she does not have to use it. In that case, just install CI, HMVC and ci-phpunit-test from Zip files. |
So you implemented your fixes in the installer ? You said :
Now, by simply using the installer, HMVC will be compatible with phpUnit through some fixes you did ? |
The installer does not matter. I fixed ci-phpunit-test. So the compatibility with HMVC and ci-phpunit-test has been increased. Now you can run simple tests without problems as you can see in https://github.com/kenjis/ci-hmvc-ci-phpunit-test. But I'm not sure ci-phpunit-test fully supports HMVC. Actually I'm not a real user of HMVC. |
I'm using CI 3.0.4 with wiredesignzHmvcInstalled and REST_Controller. This is my controller Ping.php:
This is Ping_model.php:
This is my test class Ping_test.php:
When I run phpunit, I got this error:
The error is raised because the controller cannot load ping_model this line: But when I check the log file: The ping model was initialized and loaded to CI object. But not available if called from CIPHPUnitTestRequest.php function createAndCallController() Can you point me some directions? |
@ivankristianto Thank you for your reporting. |
@kenjis The problem lies in the REST_Controller.php, it extends CI_Controller, I it should be MX_Controller. |
@ivankristianto Yes! I also just think of it now. I put sample: https://github.com/kenjis/ci-hmvc-ci-phpunit-test/blob/master/application/tests/controllers/Ping_test.php |
@kenjis First I did use |
@ivankristianto I don't know why Anyway, it is the parameter value of |
Getting un expected error
|
@rockers007 Error message is Migrations has been loaded but is disabled or set up incorrectly. |
I replaced application/config/migration.php from latest codeigniter3.0.6 config folder,but still same error |
The default config file sets CodeIgniter migration disabled. Before running tests, I recommend you run migrations only with CodeIgniter. In our book, CodeIgniter Testing Guide, Database Migration is explaned on P.56-. |
Just wanted to say, I was worried when I saw this issue that it would be a hassle to work with the HMVC extension. I am using WireDesignz's HMVC and writing tests for it is going flawlessly. I didn't have to apply any diffs or other modifications (except for whitelisting the modules folder in phpunit.xml). Thanks for your hard work! |
@AlbinoDrought Thank you for your information. Yes, now HMVC works fine mostly. To everyone: |
PHP Fatal error: Class 'PhpParser\NodeAbstract' not found in /.../ci-hmvc-ci-phpunit-test/application/tests/_ci_phpunit_test/patcher/third_party/PHP-Parser/test/PhpParser/NodeAbstractTest.php on line 5 |
Hi, I am getting session.php file error. I have posted the error log. Can any one please guide me. Time: 2.92 seconds, Memory: 12.00Mb
/home/lsystem/projects/ciframework/application/admin/tests/_ci_phpunit_test/replacing/core/Common.php:103 |
hello @kenjis i used HMVC from waifung0207/ci_bootstrap_3 |
look like cross module load resource is not working
always return
|
Does this work with PHPUnit 8? |
I'm having the same issue. So far (as I couldn't test the application completely) it happens with config files. Any insight to help solve this issue? |
Yesss people! I got this working! Didn't test it very much, but the error disapeared. I'm making a PR soon enough. |
Here: #311. I had to add |
Actually it didn't work for me this , so i had to add in functions.php |
Hi guys, it seems the HMVC does not work with the current CodeIgniter 3.1. Do you use CodeIgniter 3.0 with HMVC?
|
I do! |
I actually have another problem:
|
I checked and CI::$_ci_Model_paths is private (or protected, don't remember, but I couldn't access it - I could access public properties). |
What is It is no wonder that private properties can't be accessible from outside of the object. |
@kenjis back again at this issue ? I'm getting your errors... |
@diegosolo please show me your welcome controller test |
Wanted to say not getting errors |
My setup codeigniter 3.1.11, and I use ci-phpunit-test in a opensource project, webase https://github.com/lemondropsarl/webase Check this repo to see what's up |
@cedriclange
|
@kenjis, okay that is great |
Hi! The error I had was either because I was using CI v3.1.10 (not v3.1.11) or because I was using an old version of the HMVC framework. I updated CI to v3.1.11 and replaced my HMVC with what @cedriclange has in the webbase project (https://github.com/lemondropsarl/webase) and now it runs fine. I stopped getting errors after that, yet requests were returning empty results ( Thank you all! |
@cedriclange I've updated https://github.com/kenjis/ci-hmvc-ci-phpunit-test with your HMVC code.
|
Just for your info.
|
I've tried every possible solution i can think of, but nothing seems to work. I keep getting the CI_Lang class not found since its extended by MX/Lang.
I'd appreciate any guidelines to help understand how to debug the problem.
The text was updated successfully, but these errors were encountered: