dtb81443 2014-11-27 05:18
浏览 39

PHPUnit错误未定义变量

I'm running PHPunit to test my ZF2 application. I tried it on my Windows machine (under xampp), and it worked fine. But when I moved it to a virtual Ubuntu 14.10 server, I keep getting the following error with every test:

Undefined variable: services

I went to /etc/php5/cli/php.ini and set error reporting as follows:

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE

The code the tests are pointing to is from one of my Module.php files

public function onBootstrap(MvcEvent $event)
{
    $sharedEventManager =  $event->getApplication()
        ->getEventManager()
        ->getSharedManager();

    $sharedEventManager->attach('user', 'log-fail', function($event) use ($services) {
        $username = $event->getParam('username');


        $log = $services->get('log');
        $log->warn("Error logging user [$username]");
    });
}

It's specifically complaining about the line $sharedEventManager->attach('user', 'log-fail', function($event) use ($services). Like I said, I tried editing the php.ini files to suppress warnings like this, but it isn't working. Is there something else I'm missing?

  • 写回答

1条回答 默认 最新

  • dtwupu6414 2014-11-28 00:21
    关注

    OK, I figured it out. It was just as Indrasinh Bihola said: I'd left a part out. Well, the book did. The snippet I borrowed is from an earlier section, but it skips crucial parts, and gives no indication of where the original part is (37 pages back!). Also, not to make excuses, but I've never used closures in PHP and I had no idea what use($services) actually did. Now I do. I won't make the same mistake again.

    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题