class UserController extends BaseController { public function __construct(UserRepositoryInterface $users) { $this->users = $users; } public function index() { $users = $this->users->all(); return View::make(‘user.index‘, compact(‘users‘)); } } class UserControllerTest extends TestCase { public function testIndex() { $repository = m::mock(‘UserRepositoryInterface‘); $repository->shouldReceive(‘all‘)->andReturn(new Collection(array(new User, new User))); App::instance(‘UserRepositoryInterface‘, $repository); $this->call(‘GET‘, ‘users‘); } }
时间: 2024-10-12 16:14:09