【发布时间】:2016-10-29 00:34:07
【问题描述】:
我正在尝试为我正在构建但无法启动的电子邮件解析器编写一些测试。
对于正常操作,电子邮件将通过管道传输到脚本,但对于测试,我想模拟管道操作:)
我的测试是这样开始的:
#!/opt/php70/bin/php
<?php
define('INC_ROOT', dirname(__DIR__));
$script = INC_ROOT . '/app/email_parser.php';
//$email = file_get_contents(INC_ROOT . '/tests/test_emails/test.email');
$email = INC_ROOT . '/tests/test_emails/test.email';
passthru("{$script}<<<{$email}");
使用原样的脚本,传递给标准输入的唯一内容是测试电子邮件的路径。当使用 file_get_contents 我得到:
sh: -c: line 0: syntax error near unexpected token '('
sh: -c: line 0: /myscriptpath/app/email_parser.php<<<TestEmailContents
其中 TestEmailContents 是原始电子邮件文件的内容。我觉得我过去曾以这种方式执行脚本,使用 heredoc 运算符将数据传递到标准输入。但是在过去的几天里,我一直找不到任何信息来帮助我克服这个绊脚石。任何建议都会非常感激!
【问题讨论】:
-
执行脚本时似乎不需要使用heredoc运算符(