Created
February 6, 2012 18:13
-
-
Save isidromerayo/1753804 to your computer and use it in GitHub Desktop.
Example temperature webservice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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