snowplow / snowplow-php-tracker

Snowplow event tracker for PHP. Add analytics into your PHP apps and scripts
http://snowplowanalytics.com
34 stars 36 forks source link

Unit tests should not do any network connections at all. #52

Open smentek opened 9 years ago

smentek commented 9 years ago

The way to go with unit tests is:

$emitterCurlMock = //Here lots of lines that would set up mock! // use: disableOriginalConstructor() // set how what methods mock have and how many times they should be called // Use returnCallback() to return somthing so code outside would "think" it deals with real object // So at this point we know that right mock methods has been called right amount of time

$subject = Snowplow\Tracker\Subject() $trucker = new Tracker($emitterCurlMock, $subject, "nodejs-tracker")

//Here we run our processing: $trucker->trackUnstructEvent($json, $context, $timestamp)

//Here we get out from our tracker what data would be send (is not send since we use mock). // So for instance if we send some JSON in a body check if this json is right: $this->assertEquals($trucker->useApiToGetJsonThatWouldBeSend(), "{this is the json}");