3
나는 테스트하기에 상당히 새롭기 때문에 맨손으로.테스트 중에 모델에 대한 속성 설정
컨트롤러를 테스트하고 모델을 조롱하려고합니다. 뷰가로드 될 때까지 모두 잘 돌아 간다. 뷰를 통해 관계를 통해로드해야하는 속성을 검색 할 수 없다.
조롱 된 개체에서 andSet()
을 사용하여 해당 속성을 설정하려고했지만 오류 getAttribute() does not exist on this mocked object.
이 표시됩니다.
내 컨트롤러 방법은 다음과 같습니다.
public function __construct(ApplicationRepositoryInterface $application)
{
$this->beforeFilter('consumer_application');
$this->application = $application;
}
public function edit($application_id)
{
$application = $this->application->find($application_id);
$is_consumer = Auth::user()->isAdmin() ? 'false' : 'true';
return View::make('application.edit')
->with('application', $application)
->with('is_consumer', $is_consumer)
->with('consumer', $application->consumer);
}
그리고 내 테스트
...public function setUp()
{
parent::setUp();
$this->mock = Mockery::mock($this->app->make('ApplicationRepositoryInterface'));
}
public function testEdit()
{
$this->app->instance('ApplicationRepositoryInterface', $this->mock);
$this->mock
->shouldReceive('find')
->once()
->andReturn(Mockery::mock('Application'))
->andSet('consumer', Mockery::mock('Consumer'));
Auth::shouldReceive('user')
->once()
->andReturn(Mockery::mock(array('isAdmin' => 'true')));
$application_id = Application::first()->id;
$this->call('GET', 'consumer/application/'.$application_id.'/edit');
$this->assertResponseOk();
$this->assertViewHas('application');
$this->assertViewHas('is_consumer');
$this->assertViewHas('consumer');
}
내가 찍었을 먼은 getAttribute() does not exist on this mock object
을 담당하여 andSet()
부분을 제거하지만, 다음 뷰가로드 될 때 consumer
이 정의되지 하더군요 여전히 실패합니다.
도움이나 도움을 주시면 대단히 감사하겠습니다.