4

I have a curl wrapper class for which I'm writing unit tests. The wrapper class is able to detect a lost or changed connection and restart a download accordingly. It does this by tracking how much data has been downloaded at fixed intervals.

Is there any way to manipulate the internet connection within a PHPUnit test?

Twifty
  • 3,267
  • 1
  • 29
  • 54

2 Answers2

1

Write a mock object to wrap the network communication for unit testing. In that mock class you can freely implement any kind of behaviour, like e.g. aborting the connection on a certain condition which would seem like a dropped connection to your application.

mcserep
  • 3,231
  • 21
  • 36
0

Not directly for a PHPUnit test, but maybe still related:

You can go hardcore mode: Pull your ethernet cable or turn off the wifi.

Seriously,

On Linux and Mac OS X you can try playing with ipfw

  • sudo ipfw pipe 1 config bw 56Kbit/s delay 200 plr 0.2
  • sudo ipfw add 1 pipe 1 ip from any to any

And turn it off with sudo ipfw delete 1

There is also comcast which is a really great and handy tool for such things!

Sadly I don't know what can be used on windows.

Also this thread could be related

Community
  • 1
  • 1
CodeBrauer
  • 2,690
  • 1
  • 26
  • 51