SimpleTest与CodeIgniter - 不会识别文件 - 变量死吗? [英] SimpleTest with CodeIgniter -- won't identify file -- variables die?

查看:126
本文介绍了SimpleTest与CodeIgniter - 不会识别文件 - 变量死吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用CodeIgniter使用SimpleTest,使用由 maroonbytes 提供的代码。 a>。我使用LAMP和NetBeans 6.9。



test.php页面在我的浏览器中加载。我有一个存根测试,它显示在下拉选择。当我尝试运行它,我得到2 PHP错误:


消息:
include_once(/ var / www / sparts3 / main / tests / basic_test_v.php):
无法打开流:无此类文件或
目录



消息:include_once $ b无法打开
'/var/www/sparts3/main/tests/basic_test_v.php'
包含
(include_path ='。:/ usr / share / php:/ usr / share / pear')


路径错误 - basic_test_v.php 位于子文件夹

调试器在 test.php 中指向此目录:

  function add_test($ file,& $ test)


b $ b

由于某种原因,NetBeans在此时不公开$ file的值。这是否意味着它是空的?



我已经jimmied一行代码,因为它让我通过代码404页面未找到。看起来调试器GET导致验证器失败。所以我添加了一个标准,以我的无知的方式(我确定它应该是一个处理的异常或某事):

  if ($ this-> uri-> uri_string ==''|| $ this-> uri-> uri_string =='XDEBUG_SESSION_START')
{...}

我如何解决这个问题? BTW,尝试解决,我将更新;似乎最好使这是一个离散的问题。






更新1:我一直在使用Web开发人员加载项来实验POST条目。我相信这些都在代码中处理不当。仍然出现NetBeans正在调试时显示一些字符串变量;这是令人沮丧的。



更新2:在我看来,有效的代码处理停止在同一点NetBeans停止显示变量。我正在逐步通过 test.php 。我通过一个函数, add_test($ file,& $ test)。这个函数打开一个if语句;完成得很好,我可以看到变量。然后新的if语句:

  if(file_exists($ implementation))
{
require_once实施); ...

一旦我在这条线上,就会发生2件事:


  1. 除了SuperGlobals,NetBeans中的变量显示为空白

  2. 代码的行为与
    $ implementation 是一个空变量

我在上面添加了一个语句:

  $ implementation ='http://var/www/sparts3/main/tests/views/basic_test_view.php'; 

这不会改变任何东西。无论我使用NetBeans / Xdebug,浏览器输出都是相同的。



所以它开始看起来像一个PHP处理故障。那些存在吗?我可以尝试上传和尝试从主机服务 - 仅诊断线索,和无忧无虑,因为CI没有调试的能力是对我没有兴趣。






更新3:我在WAMP电脑上尝试了一切。相同的浏览器结果(以及一些已弃用的错误,与PHP 4与5有关)。我想我可以在这台PC上调试(如果Xdebug正常工作),但似乎没有什么意义。

解决方案

您是否已将basic_test_v.php重命名为basic_test_view.php?



UPDATE 1 (是无聊的)


我已经默认了一行代码
,因为它让我通过代码404
找不到页面。看起来调试器
GET导致验证器失败。
所以我添加了一个标准,在我的无知的
方式(我相信它应该是一个处理的
异常或某事):




  if($ this-> uri-> uri_string ==''|| $ this-> uri-> uri_string ==' XDEBUG_SESSION_START'){...} 




如何解决? BTW,这是尝试解决我的
其他职位,我会更新;
似乎最好使这个离散的
问题。


这个问题的正确解决方案是:
set $ config ['uri_protocol'] =AUTO; $ config ['uri_protocol'] =PATH_INFO / code>
$ config ['enable_query_strings'] = FALSE; $ config ['enable_query_strings'] = TRUE ;在config.php中读取
(阅读上面的注释,这些设置非常有帮助)



.php我可以告诉你,你的测试文件应该命名为这样:



%name%_%type%_test.php(其中%type%是单数) / p>

这里更清楚一个例子:



我们有一个控制器欢迎放在文件welcome .php
此控制器的测试应命名为 welcome_controller _test.php并存储在tests / controllers /



下。 php脚本尝试自动加载测试文件和测试文件。
但是在我看来它需要更正。



我改变了函数get_loader_id和add_test,如下所示

  function get_loader_id($ file,$ type){
$ loader_id = str_replace(_ {$ type} _test.php,,basename ));
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。 '楷模/' 。 $ model。 '_model.php';
} elseif(preg_match('/ _ view /',$ file)){
$ view = get_loader_id($ file,'view');
$ implementation = APPLICATION。 'views /'。 $视图。 '.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);
}

如果您遵循文件名规则, b(我已经测试了它在zend服务器ce,xdebug,simpletest和netbeans的一个macbook 6.9)


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:

  1. The Variables display in NetBeans goes blank except for SuperGlobals
  2. 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.

解决方案

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)

这篇关于SimpleTest与CodeIgniter - 不会识别文件 - 变量死吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆