Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example temperature webservice
<?php
/**
* @test
*/
public function getsAverageTemperatureFromThreeServiceReadings() {
$service = m::mock('Service');
$service->shouldReceive('readTemp')->times(3)->andReturn(10, 12, 14);
$temperature = new Temperature($service);
$this->assertEquals(12, $temperature->average());
}
<?php
/**
* @test
*/
public function getsAverageTemperatureFromThreeServiceReadings() {
$service = Phake::mock('Service');
Phake::when($service)->readTemp()->thenReturn(10)
->thenReturn(12)
->thenReturn(14);
$temperature = new Temperature($service);
$this->assertEquals(12, $temperature->average());
}
<?php
/**
* @test
*/
public function getsAverageTemperatureFromThreeServiceReadings() {
$service = Phockito::mock('Service');
Phockito::when($service->readTemp())->return(10)->return(12)->return(14);
$temperature = new Temperature($service);
$this->assertEquals(12, $temperature->average());
}
<?php
/**
* @test
*/
public function getsAverageTemperatureFromThreeServiceReadings()
{
$service = $this->getMock('Service',array('readTemp'));
$service->expects($this->any())
->method('readTemp')
->will($this->onConsecutiveCalls(10,12,14));
$temperature = new Temperature($service);
$this->assertEquals(12, $temperature->average());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment