dream543211 2014-12-13 17:38
浏览 41
已采纳

PHPUnit可以在运行之前临时重置系统路径吗?

I'm using phpunit-spiderling alongside PHPUnit to run browser/functional tests on PhantomJS, installed via jonnyw/php-phantomjs, which in turn installs the phantomjs binary in <project>/bin. Since that folder is not in the system path, I need to start tests thus:

PATH=$PATH:`pwd`/bin ./phpunit test/browser/tests

This works fine, but I expect I'll need to condense it into the raw command when I set this up on hosted CI, without the environment prefix:

./phpunit test/browser/tests

I've tried a --bootstrap command to run a system() command to reset the system path, to no avail, and I can't see anything in the manual that describes how to do this via phpunit.xml. Unfortunately Spiderling hard-wires the Phantom command, and it is expected to be visible in the system path.

I've also tried doing this is a setUp() test method, but that's too late - Spiderling will already have tried, and failed, to start up PhantomJS on a random port.

(The command ./phpunit is just a symlink to vendor/phpunit/phpunit/phpunit, which is PHPUnit installed via Composer.)

  • 写回答

1条回答 默认 最新

  • doudao5287 2014-12-15 20:27
    关注

    Further to this question, it turns out that:

    • hosted CI tools offer ways of achieving this outside of PHPUnit
    • Travis, which I am using, offers phantomjs in the standard path anyway

    Thus, whilst it turns out I don't need this, there seems to be two ways to achieve it. Since my approach requires the execution of the backticks, I wonder if the env approach might not work. However, for completeness, here is both:

    • The env approach is an entry in the .travis.yml file.
    • You could also try a before_script key with a value thus:

      before_script:
        - export PATH=`pwd`/bin:$PATH
      

      Since the working directory should be set to the root of the project, the pwd plus the subdirectory should add in the new path to the system path.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)