FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Mock HTTP servers for unit tests.
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Mock HTTP servers for unit tests. [message #185668] Tue, 29 April 2014 17:23 Go to next message
Daniel Pitts is currently offline  Daniel Pitts
Messages: 68
Registered: May 2012
Karma: 0
Member
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.

I've searched Google, and I see there is more than one solution
available. I like the look of InterNations[1], but I wanted to ask this
community if they've had experience with any of them, and whether that
experience was positive or negative.

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.

Thanks,
Daniel.

[1] https://github.com/InterNations/http-mock
Re: Mock HTTP servers for unit tests. [message #185669 is a reply to message #185668] Tue, 29 April 2014 18:51 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/29/2014 1:23 PM, 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.
>
> I've searched Google, and I see there is more than one solution
> available. I like the look of InterNations[1], but I wanted to ask this
> community if they've had experience with any of them, and whether that
> experience was positive or negative.
>
> 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.
>
> Thanks,
> Daniel.
>
> [1] https://github.com/InterNations/http-mock

Daniel,

Normally when testing, I test against the site the code is written for.
If that's not possible (or I need further information than is supplied
by the server, as you seem to need), I create my own test site and write
server-side code to provide the appropriate information.

You can see if the requests were made in parallel from the server logs.
Other information can be validated by the pages being requested.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: Mock HTTP servers for unit tests. [message #185670 is a reply to message #185669] Tue, 29 April 2014 20:24 Go to previous messageGo to next message
Daniel Pitts is currently offline  Daniel Pitts
Messages: 68
Registered: May 2012
Karma: 0
Member
On 4/29/14 11:51 AM, Jerry Stuckle wrote:
> On 4/29/2014 1:23 PM, 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.
>>
>> I've searched Google, and I see there is more than one solution
>> available. I like the look of InterNations[1], but I wanted to ask this
>> community if they've had experience with any of them, and whether that
>> experience was positive or negative.
>>
>> 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.
>>
>> Thanks,
>> Daniel.
>>
>> [1] https://github.com/InterNations/http-mock
>
> Daniel,
>
> Normally when testing, I test against the site the code is written for.
> If that's not possible (or I need further information than is supplied
> by the server, as you seem to need), I create my own test site and write
> server-side code to provide the appropriate information.
I'm talking about Unit Tests... I need to be able to run them while
offline, for instance. Integration tests would in theory be feasible
against a site. Note that I support multiple sites and I'm wanting to
unit-test some core functionality, not validate integration with any
other sites.
>
> You can see if the requests were made in parallel from the server logs.
> Other information can be validated by the pages being requested.
This doesn't solve my underlying problem. I want to write a Unit Test,
not an Integration Test. My Unit Test should take a few seconds at most
to run, and should not depend on an external service which may be
unavailable.

Thanks,
Daniel.
Re: Mock HTTP servers for unit tests. [message #185671 is a reply to message #185670] Tue, 29 April 2014 20:39 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/29/2014 4:24 PM, Daniel Pitts wrote:
> On 4/29/14 11:51 AM, Jerry Stuckle wrote:
>> On 4/29/2014 1:23 PM, 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.
>>>
>>> I've searched Google, and I see there is more than one solution
>>> available. I like the look of InterNations[1], but I wanted to ask this
>>> community if they've had experience with any of them, and whether that
>>> experience was positive or negative.
>>>
>>> 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.
>>>
>>> Thanks,
>>> Daniel.
>>>
>>> [1] https://github.com/InterNations/http-mock
>>
>> Daniel,
>>
>> Normally when testing, I test against the site the code is written for.
>> If that's not possible (or I need further information than is supplied
>> by the server, as you seem to need), I create my own test site and write
>> server-side code to provide the appropriate information.
> I'm talking about Unit Tests... I need to be able to run them while
> offline, for instance. Integration tests would in theory be feasible
> against a site. Note that I support multiple sites and I'm wanting to
> unit-test some core functionality, not validate integration with any
> other sites.

Good unit tests are always custom written, and are written against the
design specs (not the code).

>>
>> You can see if the requests were made in parallel from the server logs.
>> Other information can be validated by the pages being requested.
> This doesn't solve my underlying problem. I want to write a Unit Test,
> not an Integration Test. My Unit Test should take a few seconds at most
> to run, and should not depend on an external service which may be
> unavailable.
>
> Thanks,
> Daniel.
>

OK, then you need to write the unit test. Every one I have written in
many years of programming has been unique, because the code it's testing
is unique. I've seen drivers out there - but they really don't do much
more than run a series of tests in sequence; you still have to write the
individual tests. And I can do the same with a bash shell script (or
even a PHP or other scripting language script).

And remember to test both valid and invalid values in your unit test.

It's also important to log all of the output for future retrogression tests.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: Mock HTTP servers for unit tests. [message #185673 is a reply to message #185671] Tue, 29 April 2014 23:56 Go to previous messageGo to next message
Daniel Pitts is currently offline  Daniel Pitts
Messages: 68
Registered: May 2012
Karma: 0
Member
On 4/29/14 1:39 PM, Jerry Stuckle wrote:
> On 4/29/2014 4:24 PM, Daniel Pitts wrote:
>> On 4/29/14 11:51 AM, Jerry Stuckle wrote:
>>> On 4/29/2014 1:23 PM, 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.
>>>>
>>>> I've searched Google, and I see there is more than one solution
>>>> available. I like the look of InterNations[1], but I wanted to ask
>>>> this
>>>> community if they've had experience with any of them, and whether that
>>>> experience was positive or negative.
>>>>
>>>> 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.
>>>>
>>>> Thanks,
>>>> Daniel.
>>>>
>>>> [1] https://github.com/InterNations/http-mock
>>>
>>> Daniel,
>>>
>>> Normally when testing, I test against the site the code is written for.
>>> If that's not possible (or I need further information than is supplied
>>> by the server, as you seem to need), I create my own test site and write
>>> server-side code to provide the appropriate information.
>> I'm talking about Unit Tests... I need to be able to run them while
>> offline, for instance. Integration tests would in theory be feasible
>> against a site. Note that I support multiple sites and I'm wanting to
>> unit-test some core functionality, not validate integration with any
>> other sites.
>
> Good unit tests are always custom written, and are written against the
> design specs (not the code).
>
>>>
>>> You can see if the requests were made in parallel from the server logs.
>>> Other information can be validated by the pages being requested.
>> This doesn't solve my underlying problem. I want to write a Unit Test,
>> not an Integration Test. My Unit Test should take a few seconds at most
>> to run, and should not depend on an external service which may be
>> unavailable.
>>
>> Thanks,
>> Daniel.
>>
>
> OK, then you need to write the unit test. Every one I have written in
> many years of programming has been unique, because the code it's testing
> is unique. I've seen drivers out there - but they really don't do much
> more than run a series of tests in sequence; you still have to write the
> individual tests. And I can do the same with a bash shell script (or
> even a PHP or other scripting language script).
>
> And remember to test both valid and invalid values in your unit test.
Very good advice, though it doesn't answer the question nor address the
actual post I made in any way.

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.

Thanks,
Daniel.
Re: Mock HTTP servers for unit tests. [message #185674 is a reply to message #185673] Wed, 30 April 2014 00:08 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/29/2014 7:56 PM, Daniel Pitts wrote:
> On 4/29/14 1:39 PM, Jerry Stuckle wrote:
>> On 4/29/2014 4:24 PM, Daniel Pitts wrote:
>>> On 4/29/14 11:51 AM, Jerry Stuckle wrote:
>>>> On 4/29/2014 1:23 PM, 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.
>>>> >
>>>> > I've searched Google, and I see there is more than one solution
>>>> > available. I like the look of InterNations[1], but I wanted to ask
>>>> > this
>>>> > community if they've had experience with any of them, and whether that
>>>> > experience was positive or negative.
>>>> >
>>>> > 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.
>>>> >
>>>> > Thanks,
>>>> > Daniel.
>>>> >
>>>> > [1] https://github.com/InterNations/http-mock
>>>>
>>>> Daniel,
>>>>
>>>> Normally when testing, I test against the site the code is written for.
>>>> If that's not possible (or I need further information than is
>>>> supplied
>>>> by the server, as you seem to need), I create my own test site and
>>>> write
>>>> server-side code to provide the appropriate information.
>>> I'm talking about Unit Tests... I need to be able to run them while
>>> offline, for instance. Integration tests would in theory be feasible
>>> against a site. Note that I support multiple sites and I'm wanting to
>>> unit-test some core functionality, not validate integration with any
>>> other sites.
>>
>> Good unit tests are always custom written, and are written against the
>> design specs (not the code).
>>
>>>>
>>>> You can see if the requests were made in parallel from the server logs.
>>>> Other information can be validated by the pages being requested.
>>> This doesn't solve my underlying problem. I want to write a Unit Test,
>>> not an Integration Test. My Unit Test should take a few seconds at most
>>> to run, and should not depend on an external service which may be
>>> unavailable.
>>>
>>> Thanks,
>>> Daniel.
>>>
>>
>> OK, then you need to write the unit test. Every one I have written in
>> many years of programming has been unique, because the code it's testing
>> is unique. I've seen drivers out there - but they really don't do much
>> more than run a series of tests in sequence; you still have to write the
>> individual tests. And I can do the same with a bash shell script (or
>> even a PHP or other scripting language script).
>>
>> And remember to test both valid and invalid values in your unit test.
> Very good advice, though it doesn't answer the question nor address the
> actual post I made in any way.
>
> 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.
>
> Thanks,
> Daniel.

Make up your mind. Are you talking about mock http servers, or are you
talking about unit test? Unit test does NOT normally require an HTTP
server.

If it does, I create a test server as noted above.


--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: Mock HTTP servers for unit tests. [message #185675 is a reply to message #185673] Wed, 30 April 2014 00:11 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/29/2014 7:56 PM, Daniel Pitts wrote:
> On 4/29/14 1:39 PM, Jerry Stuckle wrote:
>> On 4/29/2014 4:24 PM, Daniel Pitts wrote:
>>> On 4/29/14 11:51 AM, Jerry Stuckle wrote:
>>>> On 4/29/2014 1:23 PM, 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.
>>>> >
>>>> > I've searched Google, and I see there is more than one solution
>>>> > available. I like the look of InterNations[1], but I wanted to ask
>>>> > this
>>>> > community if they've had experience with any of them, and whether that
>>>> > experience was positive or negative.
>>>> >
>>>> > 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.
>>>> >
>>>> > Thanks,
>>>> > Daniel.
>>>> >
>>>> > [1] https://github.com/InterNations/http-mock
>>>>
>>>> Daniel,
>>>>
>>>> Normally when testing, I test against the site the code is written for.
>>>> If that's not possible (or I need further information than is
>>>> supplied
>>>> by the server, as you seem to need), I create my own test site and
>>>> write
>>>> server-side code to provide the appropriate information.
>>> I'm talking about Unit Tests... I need to be able to run them while
>>> offline, for instance. Integration tests would in theory be feasible
>>> against a site. Note that I support multiple sites and I'm wanting to
>>> unit-test some core functionality, not validate integration with any
>>> other sites.
>>
>> Good unit tests are always custom written, and are written against the
>> design specs (not the code).
>>
>>>>
>>>> You can see if the requests were made in parallel from the server logs.
>>>> Other information can be validated by the pages being requested.
>>> This doesn't solve my underlying problem. I want to write a Unit Test,
>>> not an Integration Test. My Unit Test should take a few seconds at most
>>> to run, and should not depend on an external service which may be
>>> unavailable.
>>>
>>> Thanks,
>>> Daniel.
>>>
>>
>> OK, then you need to write the unit test. Every one I have written in
>> many years of programming has been unique, because the code it's testing
>> is unique. I've seen drivers out there - but they really don't do much
>> more than run a series of tests in sequence; you still have to write the
>> individual tests. And I can do the same with a bash shell script (or
>> even a PHP or other scripting language script).
>>
>> And remember to test both valid and invalid values in your unit test.
> Very good advice, though it doesn't answer the question nor address the
> actual post I made in any way.
>
> 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.
>
> Thanks,
> Daniel.

P.S. I create a test server no matter whether the test is for java, php,
..net, python or any other web scripting language.

But what you're looking for does not sound much like unit test. It
sounds more like module test - which requires a test server for the
client side of client-server scripts.


--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: Mock HTTP servers for unit tests. [message #185676 is a reply to message #185675] Wed, 30 April 2014 00:35 Go to previous messageGo to next message
Daniel Pitts is currently offline  Daniel Pitts
Messages: 68
Registered: May 2012
Karma: 0
Member
On 4/29/14 5:11 PM, Jerry Stuckle wrote:
> On 4/29/2014 7:56 PM, Daniel Pitts wrote:
>> On 4/29/14 1:39 PM, Jerry Stuckle wrote:
>>> On 4/29/2014 4:24 PM, Daniel Pitts wrote:
>>>> On 4/29/14 11:51 AM, Jerry Stuckle wrote:
>>>> > On 4/29/2014 1:23 PM, 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.
>>>> >>
>>>> >> I've searched Google, and I see there is more than one solution
>>>> >> available. I like the look of InterNations[1], but I wanted to ask
>>>> >> this
>>>> >> community if they've had experience with any of them, and whether
>>>> >> that
>>>> >> experience was positive or negative.
>>>> >>
>>>> >> 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.
>>>> >>
>>>> >> Thanks,
>>>> >> Daniel.
>>>> >>
>>>> >> [1] https://github.com/InterNations/http-mock
>>>> >
>>>> > Daniel,
>>>> >
>>>> > Normally when testing, I test against the site the code is written
>>>> > for.
>>>> > If that's not possible (or I need further information than is
>>>> > supplied
>>>> > by the server, as you seem to need), I create my own test site and
>>>> > write
>>>> > server-side code to provide the appropriate information.
>>>> I'm talking about Unit Tests... I need to be able to run them while
>>>> offline, for instance. Integration tests would in theory be feasible
>>>> against a site. Note that I support multiple sites and I'm wanting to
>>>> unit-test some core functionality, not validate integration with any
>>>> other sites.
>>>
>>> Good unit tests are always custom written, and are written against the
>>> design specs (not the code).
>>>
>>>> >
>>>> > You can see if the requests were made in parallel from the server
>>>> > logs.
>>>> > Other information can be validated by the pages being requested.
>>>> This doesn't solve my underlying problem. I want to write a Unit Test,
>>>> not an Integration Test. My Unit Test should take a few seconds at
>>>> most
>>>> to run, and should not depend on an external service which may be
>>>> unavailable.
>>>>
>>>> Thanks,
>>>> Daniel.
>>>>
>>>
>>> OK, then you need to write the unit test. Every one I have written in
>>> many years of programming has been unique, because the code it's testing
>>> is unique. I've seen drivers out there - but they really don't do much
>>> more than run a series of tests in sequence; you still have to write the
>>> individual tests. And I can do the same with a bash shell script (or
>>> even a PHP or other scripting language script).
>>>
>>> And remember to test both valid and invalid values in your unit test.
>> Very good advice, though it doesn't answer the question nor address the
>> actual post I made in any way.
>>
>> 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.
>>
>> Thanks,
>> Daniel.
>
> P.S. I create a test server no matter whether the test is for java, php,
> .net, python or any other web scripting language.
>
> But what you're looking for does not sound much like unit test. It
> sounds more like module test - which requires a test server for the
> client side of client-server scripts.

You do this nearly every single time I post to this newsgroup. You
don't understand my requirements, and I do. Stop trying to read into
it. I asked about Mock server, and provide an example that looks like
it should work. I have asked for experience with said mock server, or
other similar systems.
Re: Mock HTTP servers for unit tests. [message #185677 is a reply to message #185676] Wed, 30 April 2014 00:50 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/29/2014 8:35 PM, Daniel Pitts wrote:
> On 4/29/14 5:11 PM, Jerry Stuckle wrote:
>> On 4/29/2014 7:56 PM, Daniel Pitts wrote:
>>> On 4/29/14 1:39 PM, Jerry Stuckle wrote:
>>>> On 4/29/2014 4:24 PM, Daniel Pitts wrote:
>>>> > On 4/29/14 11:51 AM, Jerry Stuckle wrote:
>>>> >> On 4/29/2014 1:23 PM, 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.
>>>> >>>
>>>> >>> I've searched Google, and I see there is more than one solution
>>>> >>> available. I like the look of InterNations[1], but I wanted to ask
>>>> >>> this
>>>> >>> community if they've had experience with any of them, and whether
>>>> >>> that
>>>> >>> experience was positive or negative.
>>>> >>>
>>>> >>> 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.
>>>> >>>
>>>> >>> Thanks,
>>>> >>> Daniel.
>>>> >>>
>>>> >>> [1] https://github.com/InterNations/http-mock
>>>> >>
>>>> >> Daniel,
>>>> >>
>>>> >> Normally when testing, I test against the site the code is written
>>>> >> for.
>>>> >> If that's not possible (or I need further information than is
>>>> >> supplied
>>>> >> by the server, as you seem to need), I create my own test site and
>>>> >> write
>>>> >> server-side code to provide the appropriate information.
>>>> > I'm talking about Unit Tests... I need to be able to run them while
>>>> > offline, for instance. Integration tests would in theory be feasible
>>>> > against a site. Note that I support multiple sites and I'm wanting to
>>>> > unit-test some core functionality, not validate integration with any
>>>> > other sites.
>>>>
>>>> Good unit tests are always custom written, and are written against the
>>>> design specs (not the code).
>>>>
>>>> >>
>>>> >> You can see if the requests were made in parallel from the server
>>>> >> logs.
>>>> >> Other information can be validated by the pages being requested.
>>>> > This doesn't solve my underlying problem. I want to write a Unit
>>>> > Test,
>>>> > not an Integration Test. My Unit Test should take a few seconds at
>>>> > most
>>>> > to run, and should not depend on an external service which may be
>>>> > unavailable.
>>>> >
>>>> > Thanks,
>>>> > Daniel.
>>>> >
>>>>
>>>> OK, then you need to write the unit test. Every one I have written in
>>>> many years of programming has been unique, because the code it's
>>>> testing
>>>> is unique. I've seen drivers out there - but they really don't do much
>>>> more than run a series of tests in sequence; you still have to write
>>>> the
>>>> individual tests. And I can do the same with a bash shell script (or
>>>> even a PHP or other scripting language script).
>>>>
>>>> And remember to test both valid and invalid values in your unit test.
>>> Very good advice, though it doesn't answer the question nor address the
>>> actual post I made in any way.
>>>
>>> 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.
>>>
>>> Thanks,
>>> Daniel.
>>
>> P.S. I create a test server no matter whether the test is for java, php,
>> .net, python or any other web scripting language.
>>
>> But what you're looking for does not sound much like unit test. It
>> sounds more like module test - which requires a test server for the
>> client side of client-server scripts.
>
> You do this nearly every single time I post to this newsgroup. You
> don't understand my requirements, and I do. Stop trying to read into
> it. I asked about Mock server, and provide an example that looks like
> it should work. I have asked for experience with said mock server, or
> other similar systems.
>
>

I understand WHAT YOU SAY. I told you how EXPERIENCED PROGRAMMERS do
it. And I probably have more programming experience (going on 47 years
now) than you've been alive. And I've probably worked on more projects,
from one programmer to a couple of hundred programmers, than you will
ever dream of.

And I've seen more people like you who don't know what they're doing -
but want someone to validate it. It ain't gonna happen here.

And if you don't like the answer, don't ask the question.

Another option wold be for you to listen to experience - but I know that
won't happen. You already have the answers.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: Mock HTTP servers for unit tests. [message #185679 is a reply to message #185676] Wed, 30 April 2014 07:00 Go to previous messageGo to next message
Michael Vilain is currently offline  Michael Vilain
Messages: 88
Registered: September 2010
Karma: 0
Member
In article <MzX7v.346104$2N5(dot)318310(at)fx05(dot)iad>,
Daniel Pitts <newsgroup(dot)nospam(at)virtualinfinity(dot)net> wrote:

> On 4/29/14 5:11 PM, Jerry Stuckle wrote:
>> On 4/29/2014 7:56 PM, Daniel Pitts wrote:
>>> On 4/29/14 1:39 PM, Jerry Stuckle wrote:
>>>> On 4/29/2014 4:24 PM, Daniel Pitts wrote:
>>>> > On 4/29/14 11:51 AM, Jerry Stuckle wrote:
>>>> >> On 4/29/2014 1:23 PM, 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.
>>>> >>>
>>>> >>> I've searched Google, and I see there is more than one solution
>>>> >>> available. I like the look of InterNations[1], but I wanted to ask
>>>> >>> this
>>>> >>> community if they've had experience with any of them, and whether
>>>> >>> that
>>>> >>> experience was positive or negative.
>>>> >>>
>>>> >>> 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.
>>>> >>>
>>>> >>> Thanks,
>>>> >>> Daniel.
>>>> >>>
>>>> >>> [1] https://github.com/InterNations/http-mock
>>>> >>
>>>> >> Daniel,
>>>> >>
>>>> >> Normally when testing, I test against the site the code is written
>>>> >> for.
>>>> >> If that's not possible (or I need further information than is
>>>> >> supplied
>>>> >> by the server, as you seem to need), I create my own test site and
>>>> >> write
>>>> >> server-side code to provide the appropriate information.
>>>> > I'm talking about Unit Tests... I need to be able to run them while
>>>> > offline, for instance. Integration tests would in theory be feasible
>>>> > against a site. Note that I support multiple sites and I'm wanting to
>>>> > unit-test some core functionality, not validate integration with any
>>>> > other sites.
>>>>
>>>> Good unit tests are always custom written, and are written against the
>>>> design specs (not the code).
>>>>
>>>> >>
>>>> >> You can see if the requests were made in parallel from the server
>>>> >> logs.
>>>> >> Other information can be validated by the pages being requested.
>>>> > This doesn't solve my underlying problem. I want to write a Unit Test,
>>>> > not an Integration Test. My Unit Test should take a few seconds at
>>>> > most
>>>> > to run, and should not depend on an external service which may be
>>>> > unavailable.
>>>> >
>>>> > Thanks,
>>>> > Daniel.
>>>> >
>>>>
>>>> OK, then you need to write the unit test. Every one I have written in
>>>> many years of programming has been unique, because the code it's testing
>>>> is unique. I've seen drivers out there - but they really don't do much
>>>> more than run a series of tests in sequence; you still have to write the
>>>> individual tests. And I can do the same with a bash shell script (or
>>>> even a PHP or other scripting language script).
>>>>
>>>> And remember to test both valid and invalid values in your unit test.
>>> Very good advice, though it doesn't answer the question nor address the
>>> actual post I made in any way.
>>>
>>> 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.
>>>
>>> Thanks,
>>> Daniel.
>>
>> P.S. I create a test server no matter whether the test is for java, php,
>> .net, python or any other web scripting language.
>>
>> But what you're looking for does not sound much like unit test. It
>> sounds more like module test - which requires a test server for the
>> client side of client-server scripts.
>
> You do this nearly every single time I post to this newsgroup. You
> don't understand my requirements, and I do. Stop trying to read into
> it. I asked about Mock server, and provide an example that looks like
> it should work. I have asked for experience with said mock server, or
> other similar systems.

Well, seems you've been here before and gotten the same answer to your
question. You pose a very specific question. You got no answer other
than "here's what I do. Why are you doing that instead?"

Not what you're looking for? Time to look elsewhere. If all you want
is confirmation (or applause) then you're come to the wrong place. Try
contacting the developer of the tool you have questions about. They'll
probably have more info than us. You want to re-invent the wheel or do
testing your way, fine. Ask the developer for help would probably be a
better use of your time (and ours).

--
DeeDee, don't press that button! DeeDee! NO! Dee...
[I filter all Goggle Groups posts, so any reply may be automatically ignored]
Re: Mock HTTP servers for unit tests. [message #185681 is a reply to message #185673] Wed, 30 April 2014 14:28 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
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 McMahon, denismfmcmahon(at)gmail(dot)com
Re: Mock HTTP servers for unit tests. [message #185683 is a reply to message #185681] Wed, 30 April 2014 15:34 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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?


--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: Mock HTTP servers for unit tests. [message #185686 is a reply to message #185677] Wed, 30 April 2014 16:40 Go to previous messageGo to next message
Daniel Pitts is currently offline  Daniel Pitts
Messages: 68
Registered: May 2012
Karma: 0
Member
On 4/29/14 5:50 PM, Jerry Stuckle wrote:
> On 4/29/2014 8:35 PM, Daniel Pitts wrote:
>> You do this nearly every single time I post to this newsgroup. You
>> don't understand my requirements, and I do. Stop trying to read into
>> it. I asked about Mock server, and provide an example that looks like
>> it should work. I have asked for experience with said mock server, or
>> other similar systems.
>>
>>
>
> I understand WHAT YOU SAY. I told you how EXPERIENCED PROGRAMMERS do
> it. And I probably have more programming experience (going on 47 years
> now) than you've been alive. And I've probably worked on more projects,
> from one programmer to a couple of hundred programmers, than you will
> ever dream of.
You might have more years under your belt, that doesn't mean you're
better than me. I've got 24 years of programming experience. I've
developed many things from scratch, alone and in teams, including
enterprise applications, large scale websites, graphics drivers, physics
simulators, ray tracers, CPU emulators. I've had successful projects,
and I've had failed projects. I've written complete applications in C,
C++, Java, Assembly, PHP.

I tell you none of this to receive validation or kudos. Only to let you
know the context of my question. I'm not budding young programmer; I'm
an experienced veteran. When I say I want a Mock HTTP server, I know
that's exactly what I want, and it will do what I want.

The reason I looked to Google and here for such a mock-server is that
I'm experienced enough to know I don't want to build one from scratch.
Even though I'm capable enough to do so.

I want one I can easily integrate into my project so that the dozens of
other developers that depend on my code-base can benefit with the
minimum amount of work on their part. I don't want them to have to set
up a new Apache or Nginx instance just to be able to run Unit Tests.
*I* don't want to set up an instance just for unit tests.
>
> And I've seen more people like you who don't know what they're doing -
> but want someone to validate it. It ain't gonna happen here.
That's not what I'm asking for. I've validated the approach I'm taking.
>
> And if you don't like the answer, don't ask the question.
I'm asking for options of Mock HTTP servers. You gave your opinion. I
read it, considered it, and I have decided it isn't the right fit. You
needn't reply further.
>
> Another option wold be for you to listen to experience - but I know that
> won't happen. You already have the answers.

I gave my reasons why your solution didn't work for me. It may work for
others in smaller companies with fewer developers. I answer to about a
dozen different *teams* of developers, so I want to provide the solution
as self-encapsulated as possible.

Thanks for your input. I do appreciate the advice you gave in the first
reply, even though it wasn't right for my situation.

Unless you have experience with *mock* servers which meet my
requirements, you need not reply further.

Thanks,
Daniel.
Re: Mock HTTP servers for unit tests. [message #185687 is a reply to message #185679] Wed, 30 April 2014 16:46 Go to previous messageGo to next message
Daniel Pitts is currently offline  Daniel Pitts
Messages: 68
Registered: May 2012
Karma: 0
Member
On 4/30/14 12:00 AM, Michael Vilain wrote:
> In article <MzX7v.346104$2N5(dot)318310(at)fx05(dot)iad>,
> Daniel Pitts <newsgroup(dot)nospam(at)virtualinfinity(dot)net> wrote:
>> You do this nearly every single time I post to this newsgroup. You
>> don't understand my requirements, and I do. Stop trying to read into
>> it. I asked about Mock server, and provide an example that looks like
>> it should work. I have asked for experience with said mock server, or
>> other similar systems.
>
> Well, seems you've been here before and gotten the same answer to your
> question. You pose a very specific question. You got no answer other
> than "here's what I do. Why are you doing that instead?"
This is the first time I've asked this specific question. Not the first
time Jerry has answered it with "Do this completely different thing."
Thanks Jerry, but that different thing *really* *doesn't* work for my team.

> Not what you're looking for? Time to look elsewhere. If all you want
> is confirmation (or applause) then you're come to the wrong place.
Making assumptions aren't we?

> Try contacting the developer of the tool you have questions about. They'll
> probably have more info than us. You want to re-invent the wheel or do
> testing your way, fine. Ask the developer for help would probably be a
> better use of your time (and ours).
I was hoping to get pointers to tools I hadn't heard about. I had hoped
that c.l.php would be full of the type of diverse and experienced
engineers that the other groups I've been a participant in, such as
c.l.java.programmer. Alas, PHP seems to breed a different sort of
developer than Java.
Re: Mock HTTP servers for unit tests. [message #185688 is a reply to message #185681] Wed, 30 April 2014 16:49 Go to previous messageGo to next message
Daniel Pitts is currently offline  Daniel Pitts
Messages: 68
Registered: May 2012
Karma: 0
Member
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!
Re: Mock HTTP servers for unit tests. [message #185689 is a reply to message #185686] Wed, 30 April 2014 17:35 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/30/2014 12:40 PM, Daniel Pitts wrote:
> On 4/29/14 5:50 PM, Jerry Stuckle wrote:
>> On 4/29/2014 8:35 PM, Daniel Pitts wrote:
>>> You do this nearly every single time I post to this newsgroup. You
>>> don't understand my requirements, and I do. Stop trying to read into
>>> it. I asked about Mock server, and provide an example that looks like
>>> it should work. I have asked for experience with said mock server, or
>>> other similar systems.
>>>
>>>
>>
>> I understand WHAT YOU SAY. I told you how EXPERIENCED PROGRAMMERS do
>> it. And I probably have more programming experience (going on 47 years
>> now) than you've been alive. And I've probably worked on more projects,
>> from one programmer to a couple of hundred programmers, than you will
>> ever dream of.
> You might have more years under your belt, that doesn't mean you're
> better than me. I've got 24 years of programming experience. I've
> developed many things from scratch, alone and in teams, including
> enterprise applications, large scale websites, graphics drivers, physics
> simulators, ray tracers, CPU emulators. I've had successful projects,
> and I've had failed projects. I've written complete applications in C,
> C++, Java, Assembly, PHP.
>

It also doesn't mean I am NOT better than you. I've been consulting for
a lot of big companies in the last 24 years - most of them from the
Fortune 500 list. By the time you started programming, I already had 13
years with IBM and had been programming for 10 years before that.

You may *think* you know how to test. But your reply shows otherwise.

> I tell you none of this to receive validation or kudos. Only to let you
> know the context of my question. I'm not budding young programmer; I'm
> an experienced veteran. When I say I want a Mock HTTP server, I know
> that's exactly what I want, and it will do what I want.
>

A mock server will give you *some* good results. But it will not
duplicate real world situations, nor will it give you *all* of the
results you want.

> The reason I looked to Google and here for such a mock-server is that
> I'm experienced enough to know I don't want to build one from scratch.
> Even though I'm capable enough to do so.
>

And you didn't find much because experienced programmers don't use them.

> I want one I can easily integrate into my project so that the dozens of
> other developers that depend on my code-base can benefit with the
> minimum amount of work on their part. I don't want them to have to set
> up a new Apache or Nginx instance just to be able to run Unit Tests. *I*
> don't want to set up an instance just for unit tests.

It is quite easy to set up an Apache server. You can even include a
pre-configured one in your package for others to install - very easily.

But you're looking for shortcuts. They don't exist in *good* testing.

>>
>> And I've seen more people like you who don't know what they're doing -
>> but want someone to validate it. It ain't gonna happen here.
> That's not what I'm asking for. I've validated the approach I'm taking.
>>
>> And if you don't like the answer, don't ask the question.
> I'm asking for options of Mock HTTP servers. You gave your opinion. I
> read it, considered it, and I have decided it isn't the right fit. You
> needn't reply further.

And I'm trying to tell you why you're off base. However, your mind is
made up. You don't want to be bothered with the facts.

>>
>> Another option wold be for you to listen to experience - but I know that
>> won't happen. You already have the answers.
>
> I gave my reasons why your solution didn't work for me. It may work for
> others in smaller companies with fewer developers. I answer to about a
> dozen different *teams* of developers, so I want to provide the solution
> as self-encapsulated as possible.
>

Yes, basically you said you're too lazy to do it right. A little work
and the solution can be self-encapsulated.

> Thanks for your input. I do appreciate the advice you gave in the first
> reply, even though it wasn't right for my situation.
>
> Unless you have experience with *mock* servers which meet my
> requirements, you need not reply further.
>
> Thanks,
> Daniel.
>
>

No, I don't have experience with mock servers because I test things the
right way.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: Mock HTTP servers for unit tests. [message #185690 is a reply to message #185688] Wed, 30 April 2014 17:38 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
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(at)attglobal(dot)net
==================
Re: Mock HTTP servers for unit tests. [message #185691 is a reply to message #185688] Wed, 30 April 2014 17:41 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
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
Re: Mock HTTP servers for unit tests. [message #185692 is a reply to message #185687] Wed, 30 April 2014 17:59 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
Daniel Pitts wrote:

> I was hoping to get pointers to tools I hadn't heard about. I had hoped
> that c.l.php would be full of the type of diverse and experienced
> engineers that the other groups I've been a participant in, such as
> c.l.java.programmer. Alas, PHP seems to breed a different sort of
> developer than Java.

Not necessarily, IMHO. However, even if I don't do any Java
programming, I had to fall back on several text books that were mainly
written for Java developers, because the PHP literature wrt. agile
development, (unit) testing and refactoring seems to be rare.

--
Christoph M. Becker
Re: Mock HTTP servers for unit tests. [message #185693 is a reply to message #185686] Wed, 30 April 2014 19:46 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
On 30/04/14 17:40, Daniel Pitts wrote:
> I tell you none of this to receive validation or kudos. Only to let you
> know the context of my question. I'm not budding young programmer; I'm
> an experienced veteran. When I say I want a Mock HTTP server, I know
> that's exactly what I want, and it will do what I want.

I would say that you probably need to write it.

Most people simply set up apache on a spare linux machne. If that
doesn't have the fine control you need, either hack te source or start
again using bits of it as a starting point


--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to
lead are elected by the least capable of producing, and where the
members of society least likely to sustain themselves or succeed, are
rewarded with goods and services paid for by the confiscated wealth of a
diminishing number of producers.
Re: Mock HTTP servers for unit tests. [message #185694 is a reply to message #185683] Thu, 01 May 2014 01:47 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
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(at)gmail(dot)com
Re: Mock HTTP servers for unit tests. [message #185695 is a reply to message #185694] Thu, 01 May 2014 02:37 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 4/30/2014 9:47 PM, Denis McMahon wrote:
> 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,

I agree with you - but it looks to me like he wants to do more of a
module test than a unit test. The difference being that unit test
doesn't normally require external resources, but a module test often
does. In such a case, I agree with you - I'd set up a test server and
run the code against the server, with appropriate code on the server to
return both good and bad responses.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: Mock HTTP servers for unit tests. [message #185696 is a reply to message #185668] Thu, 01 May 2014 11:54 Go to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Disaster Mitigation Program - Apr. 27, 2014
Next Topic: Storing strings and numbers properly in CSV files
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 00:13:01 GMT 2024

Total time taken to generate the page: 0.02554 seconds