duanhuoyao7011 2012-06-21 14:47
浏览 47
已采纳

Symfony2:在自定义环境中运行自动化测试

I'm trying to run Symfony 2 PHP unit tests for a REST API in a custom environment, other than the default 'test' environment.

The purpose is to be able to do a quick sanity check after deploying the rest API, in any environment (e.g. int, prod)

I managed to pass the environment to the WebTestCase class, when creating a new kernel/client. My problem is that I'm now getting the following error:

"The session id is too long or contains illegal characters, valid characters are a-z, A-Z, 0-9"

I can fix that by changing the session storage to filesystem in the config.[targetenvironment].yml, but I don't want to use filesystem storage when in prod for instance.

framework:
    test: ~
    session:
        storage_id: session.storage.filesystem

Is there any way around this issue?

Thanks

  • 写回答

1条回答 默认 最新

  • douya2007 2012-06-21 23:55
    关注

    In chapter 11 of the PHPUnit manual there is a section on mocking the filesystem. This basically intercepts all filesystem calls, so making sure the test you run has no side-effects. This should solve your problem if you're calling functions directly (i.e if the php instance running PHPUnit is also the one running your code).

    If, however, your calls are going through the web server then PHPUnit configuration cannot control the remote environment. In that case you could try a special Apache configuration that sets an environmental variable based on the clients IP address and/or user-agent string and then in your code use that environmental variable to override the default session storage, or anything else you need to.

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

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?