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 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line