Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #13486

Re: Mock HTTP servers for unit tests.

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.php
Subject Re: Mock HTTP servers for unit tests.
Date 2014-05-01 01:47 +0000
Organization A noiseless patient Spider
Message-ID <ljs934$p2j$1@dont-email.me> (permalink)
References (2 earlier) <MTT7v.470718$Va6.175861@fx21.iad> <ljp2mr$6l5$1@dont-email.me> <e%W7v.134328$1j7.17611@fx01.iad> <ljr1b0$mrd$1@dont-email.me> <ljr55i$vj7$1@dont-email.me>

Show all headers | View raw


On Wed, 30 Apr 2014 11:34:15 -0400, Jerry Stuckle wrote:

> On 4/30/2014 10: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. 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?

> Denis,
> Why bother, when it's so easy to set up an Apache test system?

Hey Jerry, the way he wants to do it isn't the way I'd do it - if I 
wanted to test my code against some web-server server-side functionality, 
I'd implement the server function in my server and then test my code 
against it.

But for unit test, I'd normally write a wrapper that delivered the dummy 
test http responses into the code that was expected to process them. If I 
was making calls to another webserver I'd probably be using curl which is 
generally mature code and in my experience tested well enough by its own 
developers that I can pretty reliably take it that it will accurately 
handle its part of the job.

That means I really don't need to worry about testing the curl / remote 
server / curl part of anything I develop, I just have to check that the 
request data that would go to curl is right, and that what I expect to 
come back from curl would get correctly processed, and for that purpose 
the boundary of the code I am testing would be the interface to the curl 
calls.

Of course it may be that he wants to test the remote server part of the 
application as well, but if he's trying to do that with a mock server 
he's screwing his tests over big time, because the only correct way to 
test the remote server part of the application is by running it as part 
of a full blown server, not using some pseudo server.

-- 
Denis McMahon, denismfmcmahon@gmail.com

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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