• Hi was wondering if you could help with integrating phpunit into fuelcms we can get it working with codeigniter but are struggling to get it to work with fuelcms. Any advice or help would be greatly apprciated
  • How are you currently implementing it with both FUEL where it's not working and CodeIgniter where it is working.
  • It works fine in all of codeigniter but can't get it to work with fuel I'm guessing the fuel changes the system paths
  • What system paths are you referring to?
  • sorry wasnt clear the codeigniter path. we used this on a codeigniter site version 3
    https://github.com/kenjis/ci-phpunit-test. And it worked but trying to add this to fuel does not work. we get errors all over the place. We are using the dev version of fuelcms
  • What are some of the errors you are seeing?
  • sorry for this large error file below but you did ask :)

    PHP Notice: Use of undefined constant BASE_URL - assumed 'BASE_URL' in /Users/keithpowers/Sites/StoneacreNew/fuel/application/config/config.php on line 26


    Notice: Use of undefined constant BASE_URL - assumed 'BASE_URL' in /Users/keithpowers/Sites/StoneacreNew/fuel/application/config/config.php on line 26


    A PHP Error was encountered

    Severity: NoticeMessage: Undefined index: SERVER_NAMEFilename: /Users/keithpowers/Sites/StoneacreNew/fuel/modules/fuel/config/fuel_constants.phpLine Number: 18

    Backtrace:
    File: /Users/keithpowers/Sites/StoneacreNew/fuel/modules/fuel/config/fuel_constants.php Line: 18 Function: _error_handler
    File: /Users/keithpowers/Sites/StoneacreNew/fuel/application/config/constants.php Line: 201 Function: include_once
    File: /Users/keithpowers/Sites/StoneacreNew/fuel/application/tests/_ci_phpunit_test/replacing/core/CodeIgniter.php Line: 72 Function: require_once
    File: /Users/keithpowers/Sites/StoneacreNew/fuel/application/tests/_ci_phpunit_test/CIPHPUnitTest.php Line: 71 Function: require
    File: /Users/keithpowers/Sites/StoneacreNew/fuel/application/tests/Bootstrap.php Line: 361 Function: init
    File: phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php Line: 56 Function: include_once
    File: phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php Line: 38 Function: load
    File: phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php Line: 917 Function: checkAndLoad
    File: phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php Line: 742 Function: handleBootstrap
    File: phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php Line: 129 Function: handleArguments
    File: phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php Line: 118 Function: run
    File: /usr/local/bin/phpunit Line: 583 Function: main
    A PHP Error was encountered
    Severity: NoticeMessage: Undefined index: SERVER_NAMEFilename: /Users/keithpowers/Sites/StoneacreNew/fuel/modules/fuel/config/fuel.phpLine Number: 49
    Backtrace:
    File: /Users/keithpowers/Sites/StoneacreNew/fuel/modules/fuel/config/fuel.php Line: 49 Function: _error_handler
    File: /Users/keithpowers/Sites/StoneacreNew/fuel/modules/fuel/config/fuel_constants.php Line: 34 Function: include
    File: /Users/keithpowers/Sites/StoneacreNew/fuel/application/config/constants.php Line: 201 Function: include_once
    File: /Users/keithpowers/Sites/StoneacreNew/fuel/application/tests/_ci_phpunit_test/replacing/core/CodeIgniter.php Line: 72 Function: require_once
    File: /Users/keithpowers/Sites/StoneacreNew/fuel/application/tests/_ci_phpunit_test/CIPHPUnitTest.php Line: 71 Function: require
    File: /Users/keithpowers/Sites/StoneacreNew/fuel/application/tests/Bootstrap.php Line: 361 Function: init
    File: phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php Line: 56 Function: include_once
    File: phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php Line: 38 Function: load
    File: phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php Line: 917 Function: checkAndLoad
    File: phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php Line: 742 Function: handleBootstrap
    File: phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php Line: 129 Function: handleArguments
    File: phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php Line: 118 Function: run
    File: /usr/local/bin/phpunit Line: 583 Function: main
    PHP Fatal error: Class 'CI' not found in /Users/keithpowers/Sites/StoneacreNew/fuel/application/tests/_ci_phpunit_test/replacing/core/CodeIgniter.php on line 387
    PHP Stack trace:
    PHP 1. {main}() /usr/local/bin/phpunit:0
    PHP 2. PHPUnit_TextUI_Command::main() /usr/local/bin/phpunit:583
    PHP 3. PHPUnit_TextUI_Command->run() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:118
    PHP 4. PHPUnit_TextUI_Command->handleArguments() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:129
    PHP 5. PHPUnit_TextUI_Command->handleBootstrap() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:742
    PHP 6. PHPUnit_Util_Fileloader::checkAndLoad() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:917
    PHP 7. PHPUnit_Util_Fileloader::load() phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php:38
    PHP 8. include_once() phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php:56
    PHP 9. CIPHPUnitTest::init() /Users/keithpowers/Sites/StoneacreNew/fuel/application/tests/Bootstrap.php:361
    PHP 10. require() /Users/keithpowers/Sites/StoneacreNew/fuel/application/tests/_ci_phpunit_test/CIPHPUnitTest.php:71
    PHP 11. require_once() /Users/keithpowers/Sites/StoneacreNew/fuel/application/tests/_ci_phpunit_test/replacing/core/CodeIgniter.php:72
    PHP 12. include_once() /Users/keithpowers/Sites/StoneacreNew/fuel/application/config/constants.php:201
    PHP 13. include() /Users/keithpowers/Sites/StoneacreNew/fuel/modules/fuel/config/fuel_constants.php:34
    PHP 14. lang() /Users/keithpowers/Sites/StoneacreNew/fuel/modules/fuel/config/fuel.php:304
    PHP 15. get_instance() /Users/keithpowers/Sites/StoneacreNew/fuel/modules/fuel/helpers/MY_language_helper.php:52

    Fatal error: Class 'CI' not found in /Users/keithpowers/Sites/StoneacreNew/fuel/application/tests/_ci_phpunit_test/replacing/core/CodeIgniter.php on line 387

  • BASE_URL is defined in the fuel/modules/fuel/config/fuel_constants.php file which is included in from the fuel/application/config/constants.php. This file is one of the first things included upon initialization (see fuel/codeigniter/core/CodeIgniter.php).

    This library appears to replace some of the main cores libraries including the CodeIgniter file. This replacement is using a call to the function config_item near the top before the constants are run.
    https://github.com/kenjis/ci-phpunit-test/blob/master/application/tests/_ci_phpunit_test/replacing/core/CodeIgniter.php

    That said, the BASE_URL constant does not need to be used in the config and can be changed to whatever you need.

    For the $_SERVER['SERVER_NAME'] error, this may be related to the Bootstrap file they are using https://github.com/kenjis/ci-phpunit-test/blob/master/application/tests/Bootstrap.php which appears to replicate the index.php CI bootstrap file. FUEL has modified to set those variables if they don't exist.
  • Hi, at the end it is any way of integrating phpunit into fuelcms?

    I tried to use ci-phpunit-test and I got the same errors like kpjpowers. I eliminated the first errors BASE_URL and SERVER_NAME by setting them to an empty string. However I still get:

    Fatal error: Uncaught Error: Class 'CI' not found in /var/www/webapp/fuel/application/tests/_ci_phpunit_test/replacing/core/CodeIgniter.php:387

    PHPUnit is really useful tool and would be great if we can integrate it into fuelcms.
  • What version of FUEL are you using (check fuel/modules/fuel/config/fuel_constants.php)?

    Also, FUEL has it's module that leverages the built in testing CI library:
    https://www.getfuelcms.com/developers
    http://docs.getfuelcms.com/modules/tester
  • I used already Tester module in a previous project. However, I would like this time to succeed by integrating it with phpunit.

    I'm using the last version of fuelcms that is Fuelcms 1.4.
  • I debugged and observed the the main issue was the lang() function that is present in the configuration files. To prevent this I just created my own function lang() where I assigned the corresponding variables from fuel_lang.php file.

    Now I can unit test files with phpunit but only if they are pure Codeigniter. What I mean is for instance, if I want to test a simple model for instance:

    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');<br />require_once(FUEL_PATH.'models/Base_module_model.php');
    /**
    * @package Website\No_Module\Models
    */
    class Mymodel_model extends Base_module_model {
    function __construct(){
    //parent::__construct();
    }

    public function firstTest(){
    return 123;
    }
    }
    ?>

    it will work fine and get:

    Testing started at 15:44 ...
    PHPUnit 6.4.4 by Sebastian Bergmann and contributors.

    Time: 424 ms, Memory: 12.00MB

    OK (2 tests, 2 assertions)


    However, if I uncomment the line parent::__construct(); from the constructor I get the following error:

    Testing started at 15:46 ...
    PHPUnit 6.4.4 by Sebastian Bergmann and contributors.

    Call to undefined method CI_Config::module_load()
    /var/www/webapp/fuel/modules/fuel/models/Base_module_model.php:161
    /var/www/webapp/fuel/application/models/Mymodel_model.php:12
    /var/www/webapp/fuel/application/tests-tu/_ci_phpunit_test/replacing/core/Loader.php:363
    /var/www/webapp/fuel/modules/fuel/core/Loader.php:237
    /var/www/webapp/fuel/application/tests-tu/application/models/Mymodel_test.php:10


    Time: 215 ms, Memory: 12.00MB


    ERRORS!
    Tests: 2, Assertions: 1, Errors: 1.

    Process finished with exit code 2


    I used the configuration as it is described in ci-phpunit-test but I tried also to use as bootstrap the index.php file from fuelcms. In both cases I get the same error.
    admin, do you have any idea if will this be possible to make it work ? What else do I need to load to have $CI->config->module_load(FUEL_FOLDER, 'fuel', TRUE) available?
  • This line causes suspicion for me:
    /var/www/webapp/fuel/application/tests-tu/_ci_phpunit_test/replacing/core/Loader.php:363

    Fuel has it's own version of the Loader class that has the module_load methods in it. It seems that CI PHP unit is replacing that for testing.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!