GithubHelp home page GithubHelp logo

kenjis / ci-hmvc-ci-phpunit-test Goto Github PK

View Code? Open in Web Editor NEW
7.0 7.0 13.0 645 KB

CodeIgniter HMVC and ci-phpunit-test

PHP 94.93% HTML 0.09% Shell 0.10% Roff 4.88%
ci-phpunit-test codeigniter3 codeigniter3-hmvc

ci-hmvc-ci-phpunit-test's People

Contributors

blormik avatar kenjis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ci-hmvc-ci-phpunit-test's Issues

Argument 2 passed to PHPUnit_Framework_TestResult::addError() must be an instance of Exception

After running below code

$ vendor/bin/phpunit -c application/tests/

I am getting below error

An uncaught Exception was encountered

Type: TypeError
Message: Argument 2 passed to PHPUnit_Framework_TestResult::addError() must be an instance of Exception, instance of Error given, called in /ci-hmvc-ci-phpunit-test/vendor/phpunit/phpunit/src/Framework/TestSuite.php on line 724
Filename: /ci-hmvc-ci-phpunit-test/vendor/phpunit/phpunit/src/Framework/TestResult.php
Line Number: 195

Backtrace:
File: /ci-hmvc-ci-phpunit-test/vendor/phpunit/phpunit/src/Framework/TestSuite.php
Line: 724
Function: addError

File: /ci-hmvc-ci-phpunit-test/vendor/phpunit/phpunit/src/Framework/TestSuite.php
Line: 747
Function: run

File: /ci-hmvc-ci-phpunit-test/vendor/phpunit/phpunit/src/TextUI/TestRunner.php
Line: 440
Function: run

File: /ci-hmvc-ci-phpunit-test/vendor/phpunit/phpunit/src/TextUI/Command.php
Line: 149
Function: doRun

File: /ci-hmvc-ci-phpunit-test/vendor/phpunit/phpunit/src/TextUI/Command.php
Line: 100
Function: run

File: /ci-hmvc-ci-phpunit-test/vendor/phpunit/phpunit/phpunit
Line: 47
Function: main

PHP Fatal error: Uncaught CIPHPUnitTestExitException: exit() called in exception_handler() function in /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php:665
Stack trace:
0 /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php(665): exit
_(1)
1 [internal function]: _exception_handler(Object(TypeError))
2 {main}
thrown in /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php on line 665

Fatal error: Uncaught CIPHPUnitTestExitException: exit() called in exception_handler() function in /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php:665
Stack trace:
0 /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php(665): exit
_(1)
1 [internal function]: _exception_handler(Object(TypeError))
2 {main}
thrown in /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php on line 665

A PHP Error was encountered

Severity: Error
Message: Uncaught CIPHPUnitTestExitException: exit() called in exception_handler() function in /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php:665
Stack trace:
0 /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php(665): exit
_(1)
1 [internal function]: _exception_handler(Object(TypeError))
2 {main}
thrown
Filename: /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php
Line Number: 665

Backtrace:

PHP Fatal error: Uncaught CIPHPUnitTestExitException: exit() called in error_handler() function in /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php:635
Stack trace:
0 /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php(635): exit
_(1)
1 /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php(692): _error_handler(1, 'Uncaught CIPHPU...', '/home/p...', 665)
2 [internal function]: _shutdown_handler()
3 {main}
thrown in /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php on line 635

Fatal error: Uncaught CIPHPUnitTestExitException: exit() called in error_handler() function in /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php:635
Stack trace:
0 /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php(635): exit
_(1)
1 /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php(692): _error_handler(1, 'Uncaught CIPHPU...', '/home/p...', 665)
2 [internal function]: _shutdown_handler()
3 {main}
thrown in /ci-hmvc-ci-phpunit-test/vendor/codeigniter/framework/system/core/Common.php on line 635

Unable to open database file - phpunit.phar/phpunit/Framework/TestSuite.php

Hi,

I have followed exact steps given in documentation but when I am running phpunit command then getting the following issue:

PHPUnit 5.5.0 by Sebastian Bergmann and contributors.


Database error: A Database Error Occurred

        SQLSTATE[HY000] [14] unable to open database file
        Filename: phar://D:/phpunit/phpunit.phar/phpunit/Framework/TestSuite.php
        Line Number: 753

Though if I run
phpunit .

from tests folder then it is not throwing any error but there is not test case is running.

Please suggest the solution.

How can I change the config file based on it's $_SERVER['REQUEST_URI'] or $_SERVER['argv']?

Hi,

I have the following problem or question,
How can I change the config file based on it's
$_SERVER['REQUEST_URI'] or $_SERVER['argv']?

I load the config file from the following site: application/testing/config.php
The modul hmvc changes, by the value the $_SERVER['REQUEST_URI'] or $_SERVER['argv'] get.

Example:

  • admin/-> modules/admin
  • / -> modules/sites
  • webshop/ -> modules/webshop

The reason why it changes is that in case of similar moduls the moduls do not update each other.

testing/config.php - module loading script:

/*
|--------------------------------------------------------------------------
| Modules locations
|--------------------------------------------------------------------------
|
| These are the folders where your modules are located. You may define an
| absolute path to the location or a relative path starting from the root
| directory.
|
*/

$modules_locations = array();
if (!isset($_SERVER['REMOTE_ADDR'])){ //CLI 
    //print_r($_SERVER['argv'][1]);
   // exit;
    if(isset($_SERVER['argv'])) {
        switch (true) {
            //case strstr($_SERVER['QUERY_STRING'], 'admin/'):
            case strstr($_SERVER['argv'][1], 'admin/'):
                $modules_locations[] = 'admin_modules';
                //$modules_locations[] = 'other_modules';
                if (!defined('APPLICATION')) define('APPLICATION', 'admin_website');
                break;
            //default module template public site
            default:
                $modules_locations[] = 'site_modules';
                if (!defined('APPLICATION')) define('APPLICATION', 'public_website');

        }
    }
}else{
    if(isset($_SERVER['REQUEST_URI'])) {
        switch (true) {
            //case strstr($_SERVER['QUERY_STRING'], 'admin/'):
            case strstr($_SERVER['REQUEST_URI'], 'admin/'):
                $modules_locations[] = 'admin_modules';
                //$modules_locations[] = 'other_modules';
                if (!defined('APPLICATION')) define('APPLICATION', 'admin_website');
                break;
            //default module template public site
            default:
                $modules_locations[] = 'site_modules';
                if (!defined('APPLICATION')) define('APPLICATION', 'public_website');

        }
    }
}

$append_modules = array();
foreach($modules_locations as $modules){
    $append_modules[APPPATH.'modules/'.($modules!=''?$modules.'/':'')] = '../modules/'.($modules!=''?$modules.'/':'');
}

$config['modules_locations'] = array(
    //other modules
    APPPATH.'modules/default_modules/' => '../modules/default_modules/',
    //used website application modules
    //APPPATH.'modules/'.($modules_locations!=''?$modules_locations.'/':'') => '../modules/'.($modules_locations!=''?$modules_locations.'/':''),
    //APPPATH.'modules/site_modules/' => '../modules/site_modules/',
) + $append_modules;

I would load the routings belong to moduls, as moduls.

routes.php

$route['default_controller'] = 'Welcome';
$route['404_override'] = 'show_404';
$route['translate_uri_dashes'] = FALSE;

//print_r(config_item('modules_locations'));
//exit;

// Include routes every modules
$modules_locations = config_item('modules_locations') ? config_item('modules_locations') : FALSE;
if(!$modules_locations)
{
    if(is_dir($modules_locations))
    {
        $modules_locations = array($modules_locations => '../modules/');
    }
    else
    {
        show_error('Modules directory not found');
    }
}

foreach ($modules_locations as $key => $value)
{
    if(is_dir($key)) {
        if ($handle = opendir($key)) {
            while (false !== ($entry = readdir($handle))) {
                if ($entry != "." && $entry != "..") {
                    if (is_dir($key . $entry)) {
                        $rfile = Modules::find('routes' . EXT, $entry, '/');
                        if ($rfile[0]) {
                            //echo $rfile[0].$rfile[1];
                            include($rfile[0] . $rfile[1]);
                        }
                    }
                }
            }
            closedir($handle);
        }
    }else{
        show_error('Modules directory not found');
    }
}

Here is my problem:For some reason while the phpunit is running for the first time into the config file $_SERVER['argv'], it has been recognized˛/ percepted by the default controller and the default method.
(index.php/welcome/index)
The config.php is loaded twice by the phpunit but it runs like the HMVC moduls should only for the thrid time.

image

It will be loaded later with the settings it should operate with but by that time the hmvc (thirdpary library) has already been loaded and runs with wrong settings. Can I change the config settings based on what's like the request or the argv to operate in the phpunit?

Thanks for the answer.

request method return empty string

I am trying to integrate phpunit-test on our project upon testing

this code return empty string on my end
$output = $this->request('GET','home/index');

here is my controller code

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class Home extends MY_Controller {

	public $page_title = "Home";
	private $promo;

	function __construct() {
		parent::__construct();
		$this->load->helper('promos/promo');
		$this->promo = $this->session->userdata('promo');
    }

	public function index() {
		if (user_login()) {
			$this->middle = 'public/home';
			$this->public_layout();
		} else {
			$page_option = array('page_title' => $this->page_title, 'page' => 'home');

			$this->data['page'] = $page_option;
			page_init($page_option);

			$this->middle = 'public/home';
			$this->public_layout();
		}
	}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.