【发布时间】:2016-09-23 00:43:24
【问题描述】:
我正在 Ubuntu 14.04 上试用 Mink (PHP);我基本上做了以下事情:
$ apt-show-versions nodejs
nodejs:amd64/trusty 0.10.45-1nodesource1~trusty1 uptodate
$ npm -v
2.15.1
$ sudo npm install -g zombie
npm WARN engine zombie@4.2.1: wanted: {"node":"^4.0.0"} (current: {"node":"0.10.45","npm":"2.15.1"})
...
zombie@4.2.1 /usr/lib/node_modules/zombie
├── ms@0.7.1
├── debug@2.2.0
...
$ ls /usr/lib/node_modules/zombie/node_modules/
babel-runtime bluebird debug eventsource iconv-lite jsdom lodash mime ms request tough-cookie ws
所以,基本上,即使我收到警告,模块也会构建,并且应该在目录/usr/lib/node_modules 中。
然后我做:
mkdir test_php_mink
cd test_php_mink/
composer require behat/mink
composer require behat/mink-zombie-driver
作为检查:
test_php_mink$ ls
composer.json composer.lock vendor
...似乎所有composer 文件都在那里。
最后,根据http://mink.behat.org/en/latest/drivers/zombie.html(以及Cannot find module 'zombie' · Issue #84 · assaf/zombie · GitHub),我正在尝试这个脚本:
<?php
# composer autoload:
require_once __DIR__ . '/vendor/autoload.php';
echo "safe_mode: '" . ini_get("safe_mode") ."'\n"; # have PHP 5.5.9, safe_mode is removed
putenv("NODE_PATH=/usr/lib/node_modules");
echo "NODE_PATH is: '" . getenv ( "NODE_PATH" ) . "'\n"; # OK, is there
# NOPE:
#$driver = new \Behat\Mink\Driver\ZombieDriver();
$driver = new \Behat\Mink\Driver\ZombieDriver(
new \Behat\Mink\Driver\NodeJS\Server\ZombieServer()
);
$session = new \Behat\Mink\Session($driver);
// start the session
$session->start();
?>
不幸的是,这个脚本仍然失败:
$ php test_php_mink.php
safe_mode: ''
NODE_PATH is: '/usr/lib/node_modules'
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Server process has been terminated: (8) [
module.js:340
throw err;
^
Error: Cannot find module 'zombie'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/path/to/test_php_mink/vendor/behat/mink-zombie-driver/bin/mink-zombie-server.js:3:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
]' in /path/to/test_php_mink/vendor/behat/mink-zombie-driver/src/NodeJS/Server.php:413
Stack trace:
#0 /path/to/test_php_mink/vendor/behat/mink-zombie-driver/src/NodeJS/Server.php(306): Behat\Mink\Driv in /path/to/test_php_mink/vendor/behat/mink-zombie-driver/src/NodeJS/Server.php on line 413
如何让这个基本示例运行?
编辑:对此进行了更多尝试,发现当我在命令行上指定环境变量时:
$ NODE_PATH=/usr/lib/node_modules php test_php_mink.php
safe_mode: ''
NODE_PATH is: '/usr/lib/node_modules'
PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Server process has been terminated: (8) [
/usr/lib/node_modules/zombie/node_modules/jsdom/lib/jsdom/level2/html.js:238
var nonInheritedTags = new Set([
^
ReferenceError: Set is not defined
...
...然后模块似乎找到了!所以我的问题基本上可以归结为:如何从我的 php 脚本中更改 NODE_PATH 环境变量,所以我不必在 shell 上指定它 - 因为显然 putenv("NODE_PATH=/usr/lib/node_modules"); 对我不起作用......
至于新错误,有Installing Zombie.js Error: ReferenceError: Set is not defined. What am I doing wrong? - 显然这是由于版本不匹配,我收到了警告(npm WARN engine zombie@4.2.1: wanted: {"node":"^4.0.0"} (current: {"node":"0.10.45","npm":"2.15.1"})),所以我想我必须安装nvm 这样我才能安装正确的 nodejs 版本;我也注意到/usr/lib/node_modules/zombie/README.md:
Zombie 4.x 经测试可与 io.js 1.6 or later 一起使用。
如果您需要使用 Node 0.12 或更早版本,请考虑使用 Zombie 2.x。 ...
要安装 Zombie.js,您需要 io.js:
```bash
$ npm 安装僵尸 --save-dev
```
...我认为也可以用nvm安装;那我试试看……
【问题讨论】:
标签: php node.js mink zombie.js