Posts クラスと Blog クラスがあります。
以下からわかるように、Posts クラスは Blog クラスに依存しています。
public function index(Blog $blog) {
$posts = $this->post->all()->where('blog_id', $blog->id)->orderBy('date')->paginate(20);
return View::make($this->tmpl('index'), compact('blog', 'posts'));
}
このアクションの URL は次のとおりです。
http://example.com/blogs/[blog_name]/posts
これをテストしようとしていますが、問題が発生しています。
これが私のテスト クラス PostTestController です。
public function setUp() {
parent::setUp();
$this->mock = Mockery::mock('Eloquent', 'Post');
}
public function tearDown() {
Mockery::close();
}
public function testIndex() {
$this->mock->shouldReceive('with')->once();
$this->app->instance('Post', $this->mock);
// get posts url
$this->get('blogs/blog/posts'); //this is where I'm stuck.
$this->assertViewHas('posts');
}
問題はこれです... get 自体にデータに基づく変数出力が含まれている場合、get 呼び出しをテストするにはどうすればよいですか? これを正しくテストするにはどうすればよいですか?