Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #13488
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!46.4.82.166.MISMATCH!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.php |
| Subject | Re: Mock HTTP servers for unit tests. |
| Date | Thu, 01 May 2014 13:54:48 +0200 |
| Organization | PointedEars Software (PES) |
| Lines | 63 |
| Message-ID | <1794559.l8OrteHiDd@PointedEars.de> (permalink) |
| References | <ceR7v.570156$GL.230158@fx12.iad> |
| Reply-To | Thomas 'PointedEars' Lahn <php@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1398945294 12226 eJwFwQkBwDAIA0BLpEDY5FAe/xJ650qwwug0X1+If//luMU0TXevJqFiMphsFsLQ2lknT+4DE4QRSg== (1 May 2014 11:54:54 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Thu, 1 May 2014 11:54:54 +0000 (UTC) |
| User-Agent | KNode/4.11.5 |
| X-User-ID | eJwNyMEBwCAIA8CVCkhsx5EE9h/B3vMyYOBeSKycHKfpjPXnEZIOvax5plCedLyTnGiHuJ8i7K+o2t0rTKoLipQW9w== |
| Face | iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8r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comp.lang.php:13488 |
Show key headers only | View raw
Daniel Pitts wrote:
> I'm developing some code which makes http requests from PHP. I'd like to
> be able to Unit Test my code as smoothly as possible.
> […]
> Things I need:
> * Ability to validate a specific request was made, with a specific
> set of Headers.
> * Ability to provide a "mock" response, and validate my code can
> handle it.
>
> Things I really want:
> * Ability to send parallel requests (think curl_multi), and validate
> the requests are made in parallel.
> * Ability to delay one response for a specific amount of time, but
> have another response return earlier.
PHP 5.4+ and “php -S $TEST_HOST:$PORT your_handler.php”, perhaps with the
“-c” and/or “-d” options, should suffice.
Depending on the header fields you need to read, and the PHP version you
have available, you might need to use a different server.
apache_request_headers() is available in the CLI server since PHP 5.5.7.
I have verified that the CLI server of PHP 5.5.11 can handle several
requests made at approximately the same time (as expected):
,----
| $ echo '<?php echo $_SERVER["REQUEST_URI"] . "\n";' > server.php
| $ php -S localhost:1337 server.php
| Listening on http://localhost:1337
| Document root is /home/****/scripts/php/test
| Press Ctrl-C to quit.
`----
In another terminal:
,----
| $ GET http://localhost:1337/foo & GET http://localhost:1337/bar
| [1] 19301
| /bar
| $ /foo
| [1]+ Done GET http://localhost:1337/foo
`----
[“GET” is symlinked to lwp-request(1p), a Perl-based command-line tool to
make HTTP requests. The “$” in-between is only the client's shell
interfering with the server output; you will not see it if you use a PHP
client like curl_multi(). Note that apparently reading the server script
from a FIFO is not possible; you need to create a real file.]
<http://php.net/manual/en/features.commandline.webserver.php>
<http://php.net/manual/en/reserved.variables.php>
<http://php.net/apache_request_headers>
<http://php.net/sleep>
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
Mock HTTP servers for unit tests. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2014-04-29 10:23 -0700
Re: Mock HTTP servers for unit tests. Jerry Stuckle <jstucklex@attglobal.net> - 2014-04-29 14:51 -0400
Re: Mock HTTP servers for unit tests. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2014-04-29 13:24 -0700
Re: Mock HTTP servers for unit tests. Jerry Stuckle <jstucklex@attglobal.net> - 2014-04-29 16:39 -0400
Re: Mock HTTP servers for unit tests. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2014-04-29 16:56 -0700
Re: Mock HTTP servers for unit tests. Jerry Stuckle <jstucklex@attglobal.net> - 2014-04-29 20:08 -0400
Re: Mock HTTP servers for unit tests. Jerry Stuckle <jstucklex@attglobal.net> - 2014-04-29 20:11 -0400
Re: Mock HTTP servers for unit tests. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2014-04-29 17:35 -0700
Re: Mock HTTP servers for unit tests. Jerry Stuckle <jstucklex@attglobal.net> - 2014-04-29 20:50 -0400
Re: Mock HTTP servers for unit tests. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2014-04-30 09:40 -0700
Re: Mock HTTP servers for unit tests. Jerry Stuckle <jstucklex@attglobal.net> - 2014-04-30 13:35 -0400
Re: Mock HTTP servers for unit tests. The Natural Philosopher <tnp@invalid.invalid> - 2014-04-30 20:46 +0100
Re: Mock HTTP servers for unit tests. Michael Vilain <vilain@NOspamcop.net> - 2014-04-30 00:00 -0700
Re: Mock HTTP servers for unit tests. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2014-04-30 09:46 -0700
Re: Mock HTTP servers for unit tests. Christoph Michael Becker <cmbecker69@arcor.de> - 2014-04-30 19:59 +0200
Re: Mock HTTP servers for unit tests. Denis McMahon <denismfmcmahon@gmail.com> - 2014-04-30 14:28 +0000
Re: Mock HTTP servers for unit tests. Jerry Stuckle <jstucklex@attglobal.net> - 2014-04-30 11:34 -0400
Re: Mock HTTP servers for unit tests. Denis McMahon <denismfmcmahon@gmail.com> - 2014-05-01 01:47 +0000
Re: Mock HTTP servers for unit tests. Jerry Stuckle <jstucklex@attglobal.net> - 2014-04-30 22:37 -0400
Re: Mock HTTP servers for unit tests. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2014-04-30 09:49 -0700
Re: Mock HTTP servers for unit tests. Jerry Stuckle <jstucklex@attglobal.net> - 2014-04-30 13:38 -0400
Re: Mock HTTP servers for unit tests. Christoph Michael Becker <cmbecker69@arcor.de> - 2014-04-30 19:41 +0200
Re: Mock HTTP servers for unit tests. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-05-01 13:54 +0200
csiph-web