简体   繁体   English

如何制作一个模拟服务器进行PHPUnit流测试?

[英]How to make a mock server for PHPUnit stream testing?

A part of my project does HTTP interaction with another server, ie, it uses fopen() with a URL. 我项目的一部分与另一台服务器进行HTTP交互,即它使用带有URL的fopen()。 As a part of that, stream contexts are used to trigger TLS authentication. 作为其一部分,流上下文用于触发TLS身份验证。 I'd like to have unit tests test this to make sure TLS verification occurs properly. 我想让单元测试对此进行测试,以确保TLS验证正确进行。

So basically is there any way to create a mock server in PHP or PHPUnit so that I can purposely inject a fake TLS certificate during the fopen() call and test to make sure an error is thrown? 因此,基本上有什么方法可以在PHP或PHPUnit中创建模拟服务器,以便我可以有目的地在fopen()调用期间注入伪造的TLS证书,并进行测试以确保抛出错误?

您可以使用GuzzlePHP,有关更多详细信息,请参见http://www.sitepoint.com/unit-testing-guzzlephp/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM