From Apprentice To Artisan 翻译 02

Respect Boundaries 严守边界

Remember to respect responsibility boundaries. Controllers and routes serve as a mediator between HTTP and your application. When writing large applications, don‘t clutter them up with your domain logic.
记得要保持清晰的责任边界。 控制器和路由是作为HTTP和你的应用程序之间的中间件来用的。当编写大型应用程序时,不要将你的领域逻辑混杂在其中(控制器、路由)。

To solidify our understanding, let‘s write a quick test. First, we‘ll mock the repository and bind it to the application IoC container. Then, we‘ll ensure that the controller properly calls the repository:
为了巩固学到的知识,咱们来写一个测试案例。首先,我们要模拟一个资料库然后绑定到应用的IoC容器里。 然后,我们要保证控制器正确的调用了这个资料库:

public function testIndexActionBindsUsersFromRepository()
{    
    // Arrange...
    $repository = Mockery::mock(‘UserRepositoryInterface‘);
    $repository->shouldReceive(‘all‘)->once()->andReturn(array(‘foo‘));
}

asdasd

class a

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。