Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #13466 > unrolled thread
| Started by | Daniel Pitts <newsgroup.nospam@virtualinfinity.net> |
|---|---|
| First post | 2014-04-29 10:23 -0700 |
| Last post | 2014-05-01 13:54 +0200 |
| Articles | 3 on this page of 23 — 7 participants |
Back to article view | Back to comp.lang.php
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
Page 2 of 2 — ← Prev page 1 [2]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2014-04-30 13:38 -0400 |
| Message-ID | <ljrcdu$ofg$2@dont-email.me> |
| In reply to | #13480 |
On 4/30/2014 12:49 PM, Daniel Pitts wrote: > On 4/30/14 7:28 AM, Denis McMahon wrote: >> On Tue, 29 Apr 2014 16:56:57 -0700, Daniel Pitts wrote: >> >>> I am very familiar with testing methodologies and technologies. Just >>> most of my recent experience was with Java, where it's relatively easy >>> to start a mock http server in a separate thread. Not as easy in PHP. >>> I'm asking about Mock HTTP servers. Not about testing. >> >> What do you want your mock http server to do? It probably isn't going to >> be able to sit on port 80 without privs, assuming nothing else is on port >> 80 already. > I don't need it to listen on port 80. I actually would prefer it didn't. > It probably would be best if it listened on some random port in > user-space. > Any of the existing servers out there can do that. >> Does it need to do more than open a listening port on >> localhost, listen for some packets, send responses depending on the >> requests? I believe php comes with a basic http server, perhaps you could >> adapt that to your needs? > > That actually might be a suitable solution for my immediate need. I'll > take a look at it. Thanks for the helpful suggestion! > > > The http server which comes with PHP is quite limited; good for quick code tests, but not something I would use for anything beyond short scripts. -- ================== Remove the "x" from my email address Jerry Stuckle jstucklex@attglobal.net ==================
[toc] | [prev] | [next] | [standalone]
| From | Christoph Michael Becker <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-04-30 19:41 +0200 |
| Message-ID | <536135d8$0$6702$9b4e6d93@newsspool3.arcor-online.net> |
| In reply to | #13480 |
Daniel Pitts wrote: > On 4/30/14 7:28 AM, Denis McMahon wrote: >> On Tue, 29 Apr 2014 16:56:57 -0700, Daniel Pitts wrote: >> >>> I am very familiar with testing methodologies and technologies. Just >>> most of my recent experience was with Java, where it's relatively easy >>> to start a mock http server in a separate thread. Not as easy in PHP. >>> I'm asking about Mock HTTP servers. Not about testing. >> >> What do you want your mock http server to do? It probably isn't going to >> be able to sit on port 80 without privs, assuming nothing else is on port >> 80 already. > I don't need it to listen on port 80. I actually would prefer it didn't. > It probably would be best if it listened on some random port in > user-space. > >> Does it need to do more than open a listening port on >> localhost, listen for some packets, send responses depending on the >> requests? I believe php comes with a basic http server, perhaps you could >> adapt that to your needs? > > That actually might be a suitable solution for my immediate need. I'll > take a look at it. Thanks for the helpful suggestion! The InterNations http-mock already uses PHP's internal webserver--so probably you can save yourself work by using the mocking functionality already built around it. -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-05-01 13:54 +0200 |
| Message-ID | <1794559.l8OrteHiDd@PointedEars.de> |
| In reply to | #13466 |
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
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.php
csiph-web