我已经在我的项目中安装了 Codeigniter 3 Release,然后我在 config/autolad.php 中启用了会话库,但是当我运行我的测试时,我总是收到错误“无法找到指定的类:Session.php”。
这是我的 phpunit.xml
<?xml version="1.0" encoding="UTF-8" ?>
<phpunit bootstrap="application/tests/bootstrap.php">
<testsuites>
<testsuite name="TestSuite">
<directory>application/tests</directory>
</testsuite>
</testsuites>
<php>
<const name="PHPUNIT_TEST" value="1" />
<const name="PHPUNIT_CHARSET" value="UTF-8" />
<server name="REMOTE_ADDR" value="0.0.0.0" />
</php>
<filter>
<blacklist>
<directory suffix=".php">system</directory>
<!--directory suffix=".php">application/libraries</directory-->
</blacklist>
</filter>
</phpunit>
这是我的 application/test/bootstrap.php 来集成 codeigniter & phpunit
<?php
/*
*---------------------------------------------------------------
* OVERRIDE FUNCTIONS
*---------------------------------------------------------------
*
* This will "override" later functions meant to be defined
* in core\Common.php, so they throw erros instead of output strings
*/
function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
{
throw new PHPUnit_Framework_Exception($message, $status_code);
}
function show_404($page = '', $log_error = TRUE)
{
throw new PHPUnit_Framework_Exception($page, 404);
}
/*
*---------------------------------------------------------------
* BOOTSTRAP
*---------------------------------------------------------------
*
* Bootstrap CodeIgniter from index.php as usual
*/
require_once dirname(__FILE__) . '/../../index.php';
/*
* This will autoload controllers inside subfolders
*/
spl_autoload_register(function ($class) {
foreach (glob(APPPATH.'controllers/**/'.ucfirst(strtolower($class).'.php')) as $controller) {
require_once $controller;
}
//kreasi sendiri
foreach (glob(APPPATH.'controllers/'.ucfirst(strtolower($class).'.php')) as $controller) {
require_once $controller;
}
});
有人可以帮助我吗?
@gopakumar-gopalan,我照你说的做了,这就是我所拥有的:
<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
INFO - 2015-02-03 04:52:10 --> Config Class Initialized
INFO - 2015-02-03 04:52:10 --> Hooks Class Initialized
DEBUG - 2015-02-03 04:52:10 --> UTF-8 Support Enabled
INFO - 2015-02-03 04:52:10 --> Utf8 Class Initialized
INFO - 2015-02-03 04:52:10 --> URI Class Initialized
DEBUG - 2015-02-03 04:52:10 --> No URI present. Default controller set.
INFO - 2015-02-03 04:52:10 --> Router Class Initialized
INFO - 2015-02-03 04:52:10 --> Output Class Initialized
INFO - 2015-02-03 04:52:10 --> Security Class Initialized
DEBUG - 2015-02-03 04:52:10 --> Global POST, GET and COOKIE data sanitized
INFO - 2015-02-03 04:52:10 --> Input Class Initialized
INFO - 2015-02-03 04:52:10 --> Language Class Initialized
INFO - 2015-02-03 04:52:10 --> Loader Class Initialized
INFO - 2015-02-03 04:52:10 --> Helper loaded: url_helper
INFO - 2015-02-03 04:52:10 --> Helper loaded: date_helper
DEBUG - 2015-02-03 04:52:10 --> Session: Initialization under CLI aborted.
INFO - 2015-02-03 04:52:10 --> Database Driver Class Initialized
INFO - 2015-02-03 04:52:10 --> Controller Class Initialized
INFO - 2015-02-03 04:52:10 --> Model Class Initialized
INFO - 2015-02-03 04:52:10 --> Model Class Initialized
INFO - 2015-02-03 04:52:10 --> Helper loaded: form_helper
INFO - 2015-02-03 04:52:10 --> File loaded: /var/www/sitahta.local/public_html/application/views/core/header.php
INFO - 2015-02-03 04:52:10 --> File loaded: /var/www/sitahta.local/public_html/application/views/core/footer.php
INFO - 2015-02-03 04:52:10 --> File loaded: /var/www/sitahta.local/public_html/application/views/core/alert.php
INFO - 2015-02-03 04:52:10 --> File loaded: /var/www/sitahta.local/public_html/application/views/login/index.php
INFO - 2015-02-03 04:52:10 --> Final output sent to browser
DEBUG - 2015-02-03 04:52:10 --> Total execution time: 0.0990
我看到有调试日志说“会话:CLI 下的初始化中止。”,这是错误的原因吗?