Instantiation

How can I test code that instantiates an object?

src/Clock.php
<?php namespace Example; use DateTime; class Clock { public function getTime() { $time = new DateTime(); $time->format('g:i a'); } }

Add it to your list of side effects. Then list any method calls:

lens/tests/Clock.php
<?php namespace Example; use DateTime; // Test $clock = new Clock(); $clock->getTime(); // Effect $time = new DateTime(); $time->format('g:i a'); // return '6:35 am'; // Effect $time = new DateTime(); $time->format('g:i a'); // return '12:01 pm';

Download this example