Skip to content

Instantly share code, notes, and snippets.

@lesstif
Created August 10, 2020 04:47
Show Gist options
  • Save lesstif/cfa84f8e38d41ec43d99dae6fdd452c0 to your computer and use it in GitHub Desktop.
Save lesstif/cfa84f8e38d41ec43d99dae6fdd452c0 to your computer and use it in GitHub Desktop.
PHP Mockery simple example TestCase.
<?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());
}
}
@lesstif
Copy link
Author

lesstif commented Aug 10, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment