Skip to content

Instantly share code, notes, and snippets.

@isidromerayo
Created February 6, 2012 18:13
Show Gist options
  • Save isidromerayo/1753804 to your computer and use it in GitHub Desktop.
Save isidromerayo/1753804 to your computer and use it in GitHub Desktop.
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