Created
August 10, 2020 04:47
-
-
Save lesstif/cfa84f8e38d41ec43d99dae6fdd452c0 to your computer and use it in GitHub Desktop.
PHP Mockery simple example TestCase.
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 | |
namespace Tests\Feature; | |
use App\Temperature; | |
use Illuminate\Foundation\Testing\RefreshDatabase; | |
use Illuminate\Foundation\Testing\WithFaker; | |
use Mockery; | |
use Tests\TestCase; | |
class TemperatureTest extends \Mockery\Adapter\Phpunit\MockeryTestCase | |
{ | |
public function mockeryTestSetUp() | |
{ | |
parent::mockeryTestSetUp(); | |
} | |
public function mockeryTestTearDown() | |
{ | |
parent::mockeryTestTearDown(); | |
Mockery::close(); | |
} | |
public function testGetsAverageTemperatureFromThreeServiceReadings() | |
{ | |
$service = Mockery::mock('service'); | |
$count = 4; | |
$service->shouldReceive([ | |
'count' => $count | |
]); | |
$service->shouldReceive('readTemp') | |
->times($count) | |
->andReturn(14, 10, 9, 15); | |
$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
see Temperature.php