Open sampoyigi opened 9 years ago
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 thought it was easier, but I was wrong. Its code is not clean.
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 CIPHPUnitTest.php
above into mater
branch.
Now you can test ci-phpunit-test if you apply the change below:
--- 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. And if there is something wrong, report it, please.
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 dev-master
, probably you could run test for Welcome controller with only 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();
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. And if there is something wrong, report it, please.
If you use the latest dev-master
, you can run tests for Welcome controller without modifications.
See https://github.com/kenjis/ci-hmvc-ci-phpunit-test
Update
This week the compatibility of ci-phpunit-test with WireDesignz's HMVC has been greatly increased. Now you don't have to modify HMVC code at all. See https://github.com/kenjis/ci-hmvc-ci-phpunit-test.
If there is someone who wants to use HMVC and ci-phpunit-test, please try the latest dev-master
.
And if there is something wrong, report it, please.
Hello, so I was going through your repositories. Do we need to use the ci-hmvc-phpunit-test to ensure compatibility or can we use your codeigniter-composer-install and install WireDesignz's HMVC and CI PHPUnit Test with the cli ? That would ease our development process, by using a single composer.json instead of cloning multiple repositories. Thanks.
Do we need to use the ci-hmvc-phpunit-test to ensure compatibility
No, you need not. The repository is just my sample or testing.
can we use your codeigniter-composer-install and install WireDesignz's HMVC and CI PHPUnit Test with the cli
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 :
ci-phpunit-test does not support HMVC.
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. I've managed to get it working for some tests. But when the controller need to load a library or a model, it doesn't load properly.
This is my controller Ping.php:
class Ping extends REST_Controller {
function __construct(){
parent::__construct();
$this->load->model('ping_model');
}
public function index_get(){
$user = $this->ping_model->get( ); //this will cause error if called from phpunit
$this->response(
array(
'response' => REST_Controller::HTTP_OK,
'status' => true,
'message' => "Pong",
'data' => '',
), REST_Controller::HTTP_OK);
}
}
This is Ping_model.php:
class Ping_model extends MY_Model {
public $table_name = 'keys';
function __construct(){
parent::__construct();
log_message('info', 'Ping_model Class Initialized');
}
}
This is my test class Ping_test.php:
class Ping_test extends TestCase{
public function test_ping(){
$api_key = '1234567890aaaabbbbb';
try{
$this->warningOff();
$output = $this->request(
'GET', '/ping', ['apikey' => $api_key]
);
$this->warningOn();
} catch (CIPHPUnitTestExitException $e) {
$output = $e->exit_status;
ob_get_clean();
}
$this->assertResponseCode(200);
$output = json_decode($output);
$this->assertNotNull($output);
$message = $output->message;
$this->assertEquals('Pong', $message);
}
}
When I run phpunit, I got this error:
Starting test 'Ping_test::test_ping'.
PHP Fatal error: Call to a member function get() on a non-object in /var/www/myproject/v3/application/controllers/Ping.php on line 11
Fatal error: Call to a member function get() on a non-object in /var/www/myproject/v3/application/controllers/Ping.php on line 11
A PHP Error was encountered
Severity: Error
Message: Call to a member function get() on a non-object
Filename: /var/www/myproject/v3/application/controllers/Ping.php
Line Number: 11
The error is raised because the controller cannot load ping_model this line:
$user = $this->ping_model->get( );
But when I check the log file: INFO - 2016-02-14 11:55:12 --> Ping_model Class Initialized
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. I've confirmed the bug that you reported. This is because of incompatibility between ci-phpunit-test and HMVC. It seems that fixing the bug is not easy.
@kenjis Finally after 2 days of struggling, I got it WORKING! Yuhuuuuu...... :)
The problem lies in the REST_Controller.php, it extends CI_Controller, I it should be MX_Controller. I realize this after talking to you. Thank you so much my friend :)
@ivankristianto Yes! I also just think of it now. https://github.com/kenjis/ci-hmvc-ci-phpunit-test/commit/92b3c0ee9c68c422401539a297c7054d6c867541 It is not perfect solution, but workaround for HMVC and ci-phpunit-test.
I put sample: https://github.com/kenjis/ci-hmvc-ci-phpunit-test/blob/master/application/tests/controllers/Ping_test.php
Your test code above was a bit wrong. The rest controller calls exit()
, so to get the output, you must use the code: $output = ob_get_clean();
.
@kenjis First I did use $output = ob_get_clean();
but it return empty string.
So i did some debugging dive to CIPHPUnitTestExitException.php and doc for RuntimeException.
And I got this $output = $e->exit_status;
working.
@ivankristianto I don't know why $e->exit_status
is working. If I change my test case https://github.com/kenjis/ci-hmvc-ci-phpunit-test/blob/master/application/tests/controllers/Ping_test.php like that, it fails.
Anyway, it is the parameter value of exit()
. I mean if exit('abc')
is called, $e->exit_status
is abc
.
Getting un expected error
# phpunit.sh models/home_model_test.php
Welcome to Git (version 1.9.5-preview20150319)
Run 'git help git' to display the help index.
Run 'git help <command>' to display help for specific commands.
PHPUnit 4.8.21 by Sebastian Bergmann and contributors.
Warning: The Xdebug extension is not loaded
No code coverage will be generated.
EE
Time: 2.34 seconds, Memory: 7.25Mb
There were 2 errors:
1) Homemodel_test
exception 'CIPHPUnitTestShowErrorException' with message 'Migrations has been lo
aded but is disabled or set up incorrectly.' in E:\xampp\htdocs\donation-script\
application\tests\_ci_phpunit_test\replacing\core\Common.php:178
Stack trace:
#0 E:\xampp\htdocs\donation-script\vendor\codeigniter\framework\system\libraries
\Migration.php(134): show_error('Migrations has ...')
#1 E:\xampp\htdocs\donation-script\application\tests\_ci_phpunit_test\replacing\
core\Loader.php(1282): CI_Migration->__construct(Array)
#2 E:\xampp\htdocs\donation-script\application\tests\_ci_phpunit_test\replacing\
core\Loader.php(1176): CI_Loader->_ci_init_library('Migration', 'CI_', NULL, NUL
L)
#3 E:\xampp\htdocs\donation-script\application\tests\_ci_phpunit_test\replacing\
core\Loader.php(1037): CI_Loader->_ci_load_stock_library('Migration', '', NULL,
NULL)
#4 E:\xampp\htdocs\donation-script\application\third_party\MX\Loader.php(173): C
I_Loader->_ci_load_library('migration', NULL, NULL)
#5 E:\xampp\htdocs\donation-script\application\tests\TestCase.php(16): MX_Loader
->library('migration')
#6 [internal function]: TestCase::setUpBeforeClass()
#7 E:\xampp\htdocs\donation-script\vendor\phpunit\phpunit\src\Framework\TestSuit
e.php(697): call_user_func(Array)
#8 E:\xampp\htdocs\donation-script\vendor\phpunit\phpunit\src\TextUI\TestRunner.
php(440): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#9 E:\xampp\htdocs\donation-script\vendor\phpunit\phpunit\src\TextUI\Command.php
(149): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Arr
ay)
#10 E:\xampp\htdocs\donation-script\vendor\phpunit\phpunit\src\TextUI\Command.ph
p(100): PHPUnit_TextUI_Command->run(Array, true)
#11 E:\xampp\htdocs\donation-script\vendor\phpunit\phpunit\phpunit(47): PHPUnit_
TextUI_Command::main()
#12 {main}
2) Homemodel_test
exception 'CIPHPUnitTestShowErrorException' with message 'Migrations has been lo
aded but is disabled or set up incorrectly.' in E:\xampp\htdocs\donation-script\
application\tests\_ci_phpunit_test\replacing\core\Common.php:178
Stack trace:
#0 E:\xampp\htdocs\donation-script\vendor\codeigniter\framework\system\libraries
\Migration.php(134): show_error('Migrations has ...')
#1 E:\xampp\htdocs\donation-script\application\tests\_ci_phpunit_test\replacing\
core\Loader.php(1282): CI_Migration->__construct(Array)
#2 E:\xampp\htdocs\donation-script\application\tests\_ci_phpunit_test\replacing\
core\Loader.php(1176): CI_Loader->_ci_init_library('Migration', 'CI_', NULL, NUL
L)
#3 E:\xampp\htdocs\donation-script\application\tests\_ci_phpunit_test\replacing\
core\Loader.php(1037): CI_Loader->_ci_load_stock_library('Migration', '', NULL,
NULL)
#4 E:\xampp\htdocs\donation-script\application\third_party\MX\Loader.php(173): C
I_Loader->_ci_load_library('migration', NULL, NULL)
#5 E:\xampp\htdocs\donation-script\application\tests\TestCase.php(16): MX_Loader
->library('migration')
#6 [internal function]: TestCase::setUpBeforeClass()
#7 E:\xampp\htdocs\donation-script\vendor\phpunit\phpunit\src\Framework\TestSuit
e.php(697): call_user_func(Array)
#8 E:\xampp\htdocs\donation-script\vendor\phpunit\phpunit\src\TextUI\TestRunner.
php(440): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#9 E:\xampp\htdocs\donation-script\vendor\phpunit\phpunit\src\TextUI\Command.php
(149): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Arr
ay)
#10 E:\xampp\htdocs\donation-script\vendor\phpunit\phpunit\src\TextUI\Command.ph
p(100): PHPUnit_TextUI_Command->run(Array, true)
#11 E:\xampp\htdocs\donation-script\vendor\phpunit\phpunit\phpunit(47): PHPUnit_
TextUI_Command::main()
#12 {main}
FAILURES!
Tests: 4, Assertions: 0, Errors: 2.
@rockers007 Error message is Migrations has been loaded but is disabled or set up incorrectly. It is an error from CodeIgniter's migration library. Fix your application/config/migration.php.
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. If you use migration, you must configure the config file correctly.
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: All you have to know is in the official documentation. See https://github.com/kenjis/ci-phpunit-test/blob/master/docs/HowToWriteTests.md#modular-extensions---hmvc, please.
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 There was 1 error: 1) Welcome_test::test_index CIPHPUnitTestExitException: Unable to locate the specified class: Session.php
/home/lsystem/projects/ciframework/application/admin/tests/_ci_phpunit_test/replacing/core/Common.php:103 /home/lsystem/projects/ciframework/system/core/Controller.php:75 /home/lsystem/projects/ciframework/application/admin/core/CMS_Controller.php:24 /home/lsystem/projects/ciframework/application/admin/controllers/Welcome.php:11 /home/lsystem/projects/ciframework/application/admin/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:311 /home/lsystem/projects/ciframework/application/admin/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:226 /home/lsystem/projects/ciframework/application/admin/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:135 /home/lsystem/projects/ciframework/application/admin/tests/_ci_phpunit_test/CIPHPUnitTestCase.php:106 /home/lsystem/projects/ciframework/application/admin/tests/controllers/Welcome_test.php:15
hello @kenjis i used HMVC from waifung0207/ci_bootstrap_3 can the repo above use this ci-phpunit-test? or ci-hmvc-ci-phpunit-test? or can't? i'm looking for phpunit test that is compatible for this repo :(
look like cross module load resource is not working
$this->load->config('another_module/my_config')
always return
The configuration file another_module/my_config does not exist.
Does this work with PHPUnit 8?
look like cross module load resource is not working
$this->load->config('another_module/my_config')
always return
The configuration file another_module/my_config does not exist.
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?
look like cross module load resource is not working
$this->load->config('another_module/my_config')
always return
The configuration file another_module/my_config does not exist.
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: https://github.com/kenjis/ci-phpunit-test/pull/311. I had to add MY_Config.php
to application/core
. Maybe there's a better way to do this but it works.
Here: #311. I had to add
MY_Config.php
toapplication/core
. Maybe there's a better way to do this but it works.
Actually it didn't work for me this , so i had to add in functions.php CIPHPUnitTest::loadConig(); just at the end then it worked
Hi guys, it seems the HMVC does not work with the current CodeIgniter 3.1.
Because CI_Loader::_ci_object_to_array()
has been removed since 3.1.3.
Do you use CodeIgniter 3.0 with HMVC?
$ vendor/bin/phpunit -c application/tests/
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.
Warning: The Xdebug extension is not loaded
No code coverage will be generated.
...E.
Time: 126 ms, Memory: 8.00MB
There was 1 error:
1) welcome_Welcome_test::test_index
Error: Call to undefined method MY_Loader::_ci_object_to_array()
/home/kenji/work/codeigniter/ci-hmvc-ci-phpunit-test/application/third_party/MX/Loader.php:300
/home/kenji/work/codeigniter/ci-hmvc-ci-phpunit-test/application/modules/welcome/controllers/Welcome.php:23
/home/kenji/work/codeigniter/ci-hmvc-ci-phpunit-test/vendor/kenjis/ci-phpunit-test/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:368
/home/kenji/work/codeigniter/ci-hmvc-ci-phpunit-test/vendor/kenjis/ci-phpunit-test/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:297
/home/kenji/work/codeigniter/ci-hmvc-ci-phpunit-test/vendor/kenjis/ci-phpunit-test/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php:160
/home/kenji/work/codeigniter/ci-hmvc-ci-phpunit-test/vendor/kenjis/ci-phpunit-test/application/tests/_ci_phpunit_test/CIPHPUnitTestCase.php:151
/home/kenji/work/codeigniter/ci-hmvc-ci-phpunit-test/application/tests/modules/welcome/controllers/Welcome_test.php:15
/home/kenji/work/codeigniter/ci-hmvc-ci-phpunit-test/vendor/phpunit/phpunit/phpunit:52
FAILURES!
Tests: 5, Assertions: 8, Errors: 1.
I do!
I actually have another problem:
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.
Runtime: PHP 5.6.40 with Xdebug 2.5.5
Configuration: /var/www/html/application/tests/phpunit.xml
F.. 3 / 3 (100%)
Time: 1.5 seconds, Memory: 22.75MB
There was 1 failure:
1) Welcome_test::test_index
Failed asserting that '
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI::$_ci_Model_paths
Filename: /var/www/html/application/third_party/MX/Loader.php
Line Number: 315
Backtrace:
File: /var/www/html/application/third_party/MX/Loader.php
Line: 315
Function: _error_handler
File: /var/www/html/application/third_party/MX/Loader.php
Line: 83
Function: __get
File: /var/www/html/application/third_party/MX/Loader.php
Line: 72
Function: _add_module_paths
File: /var/www/html/application/third_party/MX/Base.php
Line: 55
Function: __construct
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 341
Function: __construct
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 297
Function: createAndCallController
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 160
Function: requestUri
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestCase.php
Line: 151
Function: request
File: /var/www/html/application/tests/controllers/Welcome_test.php
Line: 15
Function: request
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 1062
Function: invokeArgs
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 913
Function: runTest
File: phar:///usr/bin/phpunit/phpunit/Framework/TestResult.php
Line: 686
Function: runBare
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 868
Function: run
File: phar:///usr/bin/phpunit/phpunit/Framework/TestSuite.php
Line: 733
Function: run
File: phar:///usr/bin/phpunit/phpunit/Framework/TestSuite.php
Line: 733
Function: run
File: phar:///usr/bin/phpunit/phpunit/TextUI/TestRunner.php
Line: 517
Function: run
File: phar:///usr/bin/phpunit/phpunit/TextUI/Command.php
Line: 186
Function: doRun
File: phar:///usr/bin/phpunit/phpunit/TextUI/Command.php
Line: 116
Function: run
File: /usr/bin/phpunit
Line: 598
Function: main
A PHP Error was encountered
Severity: Warning
Message: in_array() expects parameter 2 to be array, null given
Filename: /var/www/html/application/third_party/MX/Loader.php
Line Number: 83
Backtrace:
File: /var/www/html/application/third_party/MX/Loader.php
Line: 83
Function: in_array
File: /var/www/html/application/third_party/MX/Loader.php
Line: 72
Function: _add_module_paths
File: /var/www/html/application/third_party/MX/Base.php
Line: 55
Function: __construct
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 341
Function: __construct
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 297
Function: createAndCallController
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 160
Function: requestUri
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestCase.php
Line: 151
Function: request
File: /var/www/html/application/tests/controllers/Welcome_test.php
Line: 15
Function: request
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 1062
Function: invokeArgs
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 913
Function: runTest
File: phar:///usr/bin/phpunit/phpunit/Framework/TestResult.php
Line: 686
Function: runBare
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 868
Function: run
File: phar:///usr/bin/phpunit/phpunit/Framework/TestSuite.php
Line: 733
Function: run
File: phar:///usr/bin/phpunit/phpunit/Framework/TestSuite.php
Line: 733
Function: run
File: phar:///usr/bin/phpunit/phpunit/TextUI/TestRunner.php
Line: 517
Function: run
File: phar:///usr/bin/phpunit/phpunit/TextUI/Command.php
Line: 186
Function: doRun
File: phar:///usr/bin/phpunit/phpunit/TextUI/Command.php
Line: 116
Function: run
File: /usr/bin/phpunit
Line: 598
Function: main
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI::$_ci_Model_paths
Filename: /var/www/html/application/third_party/MX/Loader.php
Line Number: 315
Backtrace:
File: /var/www/html/application/third_party/MX/Loader.php
Line: 315
Function: _error_handler
File: /var/www/html/application/third_party/MX/Loader.php
Line: 85
Function: __get
File: /var/www/html/application/third_party/MX/Loader.php
Line: 72
Function: _add_module_paths
File: /var/www/html/application/third_party/MX/Base.php
Line: 55
Function: __construct
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 341
Function: __construct
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 297
Function: createAndCallController
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 160
Function: requestUri
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestCase.php
Line: 151
Function: request
File: /var/www/html/application/tests/controllers/Welcome_test.php
Line: 15
Function: request
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 1062
Function: invokeArgs
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 913
Function: runTest
File: phar:///usr/bin/phpunit/phpunit/Framework/TestResult.php
Line: 686
Function: runBare
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 868
Function: run
File: phar:///usr/bin/phpunit/phpunit/Framework/TestSuite.php
Line: 733
Function: run
File: phar:///usr/bin/phpunit/phpunit/Framework/TestSuite.php
Line: 733
Function: run
File: phar:///usr/bin/phpunit/phpunit/TextUI/TestRunner.php
Line: 517
Function: run
File: phar:///usr/bin/phpunit/phpunit/TextUI/Command.php
Line: 186
Function: doRun
File: phar:///usr/bin/phpunit/phpunit/TextUI/Command.php
Line: 116
Function: run
File: /usr/bin/phpunit
Line: 598
Function: main
A PHP Error was encountered
Severity: Notice
Message: Indirect modification of overloaded property MY_Loader::$_ci_Model_paths has no effect
Filename: /var/www/html/application/third_party/MX/Loader.php
Line Number: 85
Backtrace:
File: /var/www/html/application/third_party/MX/Loader.php
Line: 85
Function: _error_handler
File: /var/www/html/application/third_party/MX/Loader.php
Line: 72
Function: _add_module_paths
File: /var/www/html/application/third_party/MX/Base.php
Line: 55
Function: __construct
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 341
Function: __construct
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 297
Function: createAndCallController
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 160
Function: requestUri
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestCase.php
Line: 151
Function: request
File: /var/www/html/application/tests/controllers/Welcome_test.php
Line: 15
Function: request
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 1062
Function: invokeArgs
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 913
Function: runTest
File: phar:///usr/bin/phpunit/phpunit/Framework/TestResult.php
Line: 686
Function: runBare
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 868
Function: run
File: phar:///usr/bin/phpunit/phpunit/Framework/TestSuite.php
Line: 733
Function: run
File: phar:///usr/bin/phpunit/phpunit/Framework/TestSuite.php
Line: 733
Function: run
File: phar:///usr/bin/phpunit/phpunit/TextUI/TestRunner.php
Line: 517
Function: run
File: phar:///usr/bin/phpunit/phpunit/TextUI/Command.php
Line: 186
Function: doRun
File: phar:///usr/bin/phpunit/phpunit/TextUI/Command.php
Line: 116
Function: run
File: /usr/bin/phpunit
Line: 598
Function: main
A PHP Error was encountered
Severity: Warning
Message: array_unshift() expects parameter 1 to be array, null given
Filename: /var/www/html/application/third_party/MX/Loader.php
Line Number: 85
Backtrace:
File: /var/www/html/application/third_party/MX/Loader.php
Line: 85
Function: array_unshift
File: /var/www/html/application/third_party/MX/Loader.php
Line: 72
Function: _add_module_paths
File: /var/www/html/application/third_party/MX/Base.php
Line: 55
Function: __construct
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 341
Function: __construct
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 297
Function: createAndCallController
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestRequest.php
Line: 160
Function: requestUri
File: /var/www/html/application/tests/_ci_phpunit_test/CIPHPUnitTestCase.php
Line: 151
Function: request
File: /var/www/html/application/tests/controllers/Welcome_test.php
Line: 15
Function: request
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 1062
Function: invokeArgs
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 913
Function: runTest
File: phar:///usr/bin/phpunit/phpunit/Framework/TestResult.php
Line: 686
Function: runBare
File: phar:///usr/bin/phpunit/phpunit/Framework/TestCase.php
Line: 868
Function: run
File: phar:///usr/bin/phpunit/phpunit/Framework/TestSuite.php
Line: 733
Function: run
File: phar:///usr/bin/phpunit/phpunit/Framework/TestSuite.php
Line: 733
Function: run
File: phar:///usr/bin/phpunit/phpunit/TextUI/TestRunner.php
Line: 517
Function: run
File: phar:///usr/bin/phpunit/phpunit/TextUI/Command.php
Line: 186
Function: doRun
File: phar:///usr/bin/phpunit/phpunit/TextUI/Command.php
Line: 116
Function: run
File: /usr/bin/phpunit
Line: 598
Function: main
' contains "<title>Welcome to CodeIgniter</title>".
/var/www/html/application/tests/controllers/Welcome_test.php:16
FAILURES!
Tests: 3, Assertions: 3, Failures: 1.
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 CI::$_ci_Model_paths
?
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 I've checked your repo, and I have no problems.
$ git clone git@github.com:lemondropsarl/webase.git
$ cd webase/
$ composer install
$ vendor/bin/phpunit -c application/tests/
PHPUnit 5.7.27 by Sebastian Bergmann and contributors.
Error: No code coverage driver is available
.... 4 / 4 (100%)
Time: 48 ms, Memory: 6.00MB
OK (4 tests, 3 assertions)
$ php -v
PHP 7.2.24-0ubuntu0.18.04.3 (cli) (built: Feb 11 2020 15:55:52) ( NTS )
Copyright (c) 1997-2018 The PHP Group
$ composer install
Deprecation warning: require-dev.mikey179/vfsStream is invalid, it should not contain uppercase characters. Please use mikey179/vfsstream instead. Make sure you fix this as Composer 2.0 will error.
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 30 installs, 0 updates, 0 removals
- Installing mikey179/vfsstream (v1.1.0): Downloading (100%)
- Installing nikic/php-parser (v4.4.0): Loading from cache
- Installing kenjis/ci-phpunit-test (v0.17.3): Downloading (100%)
- Installing cedriclange/ci-phpunit (v0.17.5): Downloading (100%)
- Installing myclabs/deep-copy (1.9.5): Loading from cache
- Installing sebastian/version (2.0.1): Downloading (100%)
- Installing sebastian/resource-operations (1.0.0): Downloading (connecting...Downloading (100%)
- Installing sebastian/recursion-context (2.0.0): Downloading (100%)
- Installing sebastian/object-enumerator (2.0.1): Downloading (100%)
- Installing sebastian/global-state (1.1.1): Downloading (100%)
- Installing sebastian/exporter (2.0.0): Downloading (100%)
- Installing sebastian/environment (2.0.0): Downloading (100%)
- Installing sebastian/diff (1.4.3): Loading from cache
- Installing sebastian/comparator (1.2.4): Downloading (100%)
- Installing symfony/polyfill-ctype (v1.15.0): Loading from cache
- Installing symfony/yaml (v4.4.7): Loading from cache
- Installing doctrine/instantiator (1.3.0): Loading from cache
- Installing webmozart/assert (1.7.0): Loading from cache
- Installing phpdocumentor/reflection-common (2.0.0): Downloading (connecting.Downloading (100%)
- Installing phpdocumentor/type-resolver (1.1.0): Loading from cache
- Installing phpdocumentor/reflection-docblock (5.1.0): Loading from cache
- Installing phpspec/prophecy (v1.10.3): Loading from cache
- Installing phpunit/php-text-template (1.2.1): Loading from cache
- Installing phpunit/phpunit-mock-objects (3.4.4):Downloading (100%) )
- Installing phpunit/php-timer (1.0.9): Loading from cache
- Installing sebastian/code-unit-reverse-lookup (1.0.1): Downloading (connectiDownloading (100%)
- Installing phpunit/php-token-stream (2.0.2): Downloading (100%)
- Installing phpunit/php-file-iterator (1.4.5): Loading from cache
- Installing phpunit/php-code-coverage (4.0.8): Downloading (100%)
- Installing phpunit/phpunit (5.7.27): Downloading (100%)
sebastian/global-state suggests installing ext-uopz (*)
symfony/yaml suggests installing symfony/console (For validating YAML files using the lint command)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/php-code-coverage suggests installing ext-xdebug (^2.5.1)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
phpunit/phpunit suggests installing ext-xdebug (*)
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating autoload files
2 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
@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 (Failed asserting that '' contains "<title>Welcome to CodeIgniter</title>"
). The problem was that I had my controllers inherit from CI_Controller class and that is conflictive. I replaced CI_Controller by MX_controller and now everything's working as expected.
Thank you all!
@cedriclange I've updated https://github.com/kenjis/ci-hmvc-ci-phpunit-test with your HMVC code. Thank you!
Just for your info.
The configuration file foo/default_modules.php does not exist.
https://github.com/kenjis/ci-phpunit-test/issues/358#issuecomment-772363598 and https://github.com/diegosolo/ci-phpunit-test/commit/ed92001dbd0669cd6b827c012c7668b4d4216a7a
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.