Skip to content

Instantly share code, notes, and snippets.

@bkuhl
Last active August 29, 2015 13:55
Show Gist options
  • Save bkuhl/8732511 to your computer and use it in GitHub Desktop.
Save bkuhl/8732511 to your computer and use it in GitHub Desktop.
public function __construct(Company $company, User $user)
{
$this->company = $company;
$this->user = $user;
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index($companyId)
{
$company = $this->company->find($companyId);
$users = $company->users()->get();
return View::make('company.users.index', compact('users', 'companyId'));
}
public function setUp()
{
parent::setUp();
//mock company
$modelClass = 'Models\Company';
$this->mock = m::mock('Eloquent', $modelClass)->shouldDeferMissing();
$this->app->instance($modelClass, $this->mock);
//mock user
$userClass = 'Models\User';
$this->user = m::mock('Eloquent', $userClass)->shouldDeferMissing();
$this->app->instance($userClass, $this->user);
$this->collection = m::mock('Illuminate\Database\Eloquent\Collection')->shouldDeferMissing();
$this->app->instance('Illuminate\Database\Eloquent\Collection', $this->collection);
$this->attributes = Factory::make($modelClass, ['id' => 1]);
//create a voice broadcast
$this->call('GET', 'company/create');
}
public function tearDown()
{
m::close();
}
public function testIndex()
{
$this->company->shouldReceive('find')->once()->andReturn($this->collection);
$this->company->shouldReceive('users')->once()->andReturn($this->collection);
$this->call('GET', '1/users');
$this->assertViewHas('users');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment