Skip to content

Instantly share code, notes, and snippets.

@Sankame
Last active May 6, 2020 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sankame/393556a5fb90b37acb7ceddd22860f3f to your computer and use it in GitHub Desktop.
Save Sankame/393556a5fb90b37acb7ceddd22860f3f to your computer and use it in GitHub Desktop.
Sample code using Laravel, PHPUnit and Mockery
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testEditNormal()
{
$this->mock = M::mock('alias:App\Contact')->makePartial();
$this->mock->shouldReceive('find')->once()->with(self::ID)->andReturnUsing(function(){
$contacts = (object)array(
'id'=>self::ID,
'first_name'=>self::FIRST_NAME,
'last_name'=>self::LAST_NAME,
'email'=>self::EMAIL,
'city'=>self::CITY,
'country'=>self::COUNTRY,
'job_title'=>self::JOB_TITLE);
return $contacts;
});
$response = $this->get('/contacts/' . self::ID . '/edit');
$response->assertStatus(200);
//Check all values output in the page.
$response->assertSee(self::FIRST_NAME);
$response->assertSee(self::LAST_NAME);
$response->assertSee(self::EMAIL);
$response->assertSee(self::CITY);
$response->assertSee(self::COUNTRY);
$response->assertSee(self::JOB_TITLE);
//Check header items in the page.
$response->assertSee('First Name:');
$response->assertSee('Last Name:');
$response->assertSee('Email:');
$response->assertSee('City:');
$response->assertSee('Country:');
$response->assertSee('Job Title:');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment