问题
I am trying to use SimpleTest with CodeIgniter, using code supplied by maroonbytes. I am using LAMP and NetBeans 6.9.
The test.php page loads up in my browser. I have a stub test in place and it shows in the drop-down selections. When I try to run it, I get 2 PHP errors:
Message: include_once(/var/www/sparts3/main/tests/basic_test_v.php): failed to open stream: No such file or directory
Message: include_once(): Failed opening '/var/www/sparts3/main/tests/basic_test_v.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear')
The path is wrong -- basic_test_v.php is in a subfolder /tests/views.
The debugger points to this in test.php:
function add_test($file, &$test)
For some reason NetBeans does not expose the value of $file at this point. Does this mean it's empty?
I've already jimmied a line of code because it gets me past a Code 404 Page Not Found. it seemed the debugger GET was causing the validator to fail. So I added a criteria, in my ignorant way (I'm sure it should be a handled exception or something):
if ($this->uri->uri_string == '' || $this->uri->uri_string == 'XDEBUG_SESSION_START')
{ ... }
How can I solve this? BTW, this is attempted to solve my other post, which I will update; seemed best to make this a discrete question.
UPDATE 1: I've been using the Web Developer add-in (Firefox) to experiment with the POST entries. I believe these are being mishandled in the code. It still appears NetBeans is balking on showing some string variables while debugging; this is frustrating.
UPDATE 2: It seems to me that valid code processing stops at the same point NetBeans stops displaying variables. I am stepping through test.php. I am partway through a function, add_test($file, &$test). This functions opens with an if statement; that finishes well, and I can see the variables. Then a new if statement:
if (file_exists($implementation))
{
require_once ($implementation); ...
As soon as I'm on that line, 2 things happen:
- The Variables display in NetBeans goes blank except for SuperGlobals
- The code behaves as if $implementation is an empty variable
I added a statement just above these lines:
$implementation = 'http://var/www/sparts3/main/tests/views/basic_test_view.php';
This doesn't change anything. The browser output is the same whether I'm using NetBeans/Xdebug or not.
So it's starting to look like a PHP processing glitch. Do those exist? I may try uploading and trying from host service -- for diagnostic clues only, and cheerlessly, because CI without the ability to debug is of no interest to me.
UPDATE 3: I tried everything out on a WAMP PC. Same browser results (plus some "deprecated" errors, something to do with PHP 4 vs. 5). I think I can debug on that PC (if Xdebug is functioning), but there seems little point.
回答1:
Did you renamed basic_test_v.php to basic_test_view.php? the code expects your files to be named and stored right.
UPDATE 1 (yes im bored)
I've already jimmied a line of code because it gets me past a Code 404 Page Not Found. it seemed the debugger GET was causing the validator to fail. So I added a criteria, in my ignorant way (I'm sure it should be a handled exception or something):
if ($this->uri->uri_string == '' || $this->uri->uri_string == 'XDEBUG_SESSION_START') { ... }
How can I solve this? BTW, this is attempted to solve my other post, which I will update; seemed best to make this a discrete question.
The "right" solution to this issue is:
set $config['uri_protocol'] = "AUTO";
to $config['uri_protocol'] = "PATH_INFO";
and $config['enable_query_strings'] = FALSE;
to $config['enable_query_strings'] = TRUE;
in the config.php (read the comment above those settings, they very helpful)
After a deeper look at test.php i can tell you that your test files should be named like this:
%name%_%type%_test.php (where %type% is singular)
to make it more clear here an example:
we've got a controller welcome placed in the file welcome.php the test for this controller should be named welcome_controller_test.php and stored under tests/controllers/
the test.php script tries to load the test file and the tested file automatically. But in my opinion it needs to be corrected.
I've changed function get_loader_id and add_test like follows
function get_loader_id($file, $type) {
$loader_id = str_replace("_{$type}_test.php", "", basename($file));
return $loader_id;
}
function add_test($file, &$test) {
$implementation = '';
if (preg_match('/_controller/', $file)) {
$controller = get_loader_id($file, 'controller');
$implementation = APPLICATION . 'controllers/' . $controller . '.php';
} elseif (preg_match('/_model/', $file)) {
$model = get_loader_id($file, 'model');
$implementation = APPLICATION . 'models/' . $model . '_model.php';
} elseif (preg_match('/_view/', $file)) {
$view = get_loader_id($file, 'view');
$implementation = APPLICATION . 'views/' . $view . '.php';
} elseif (preg_match('/_helper/', $file)) {
$helper = get_loader_id($file, 'helper');
$implementation = APPLICATION . 'helpers/' . $helper . '.php';
} elseif (preg_match('/_library/', $file)) {
$library = get_loader_id($file, 'library');
$implementation = APPLICATION . 'libraries/' . $library . '.php';
}
if (file_exists($implementation)) {
require_once ($implementation);
}
$test->addFile($file);
}
if you're following the filename conventions all should run just fine (i've tested it on an macbook with zend server ce, xdebug, simpletest and netbeans 6.9)
回答2:
If what you're trying to load is a view, have you tried to use $this->load->view('basic_test_view');
?
来源:https://stackoverflow.com/questions/3327832/simpletest-with-codeigniter-wont-identify-file-variables-die