我有一个使用子域路由到代理的应用程序:
foo.domain.dev -> Agency:showAction(foo)
bar.domain.dev -> Agency:showAction(bar)
domain.dev -> Agency:indexAction()
这些每个对应于一个代理实体和控制器。
我有一个监听器,它监听 onDomainParse 事件并将子域写入请求属性。
/**
* Listens for on domainParse event
* Writes to request attributes
*/
class SubdomainListener {
public function onDomainParse(Event $event)
{
$request = $event->getRequest();
$session = $request->getSession();
// Split the host name into tokens
$tokens = $this->tokenizeHost($request->getHost());
if (isset($tokens['subdomain'])){
$request->attributes->set('_subdomain',$tokens['subdomain']);
}
}
//...
}
然后我在控制器中使用它来重新路由到显示操作:
class AgencyController extends Controller
{
/**
* Lists all Agency entities.
*
*/
public function indexAction()
{
// We reroute to show action here.
$subdomain = $this->getRequest()
->attributes
->get('_subdomain');
if ($subdomain)
return $this->showAction($subdomain);
$em = $this->getDoctrine()->getEntityManager();
$agencies = $em->getRepository('NordRvisnCoreBundle:Agency')->findAll();
return $this->render('NordRvisnCoreBundle:Agency:index.html.twig', array(
'agencies' => $agencies
));
}
// ...
}
我的问题是:
使用 WebTestCase 进行测试时如何伪造这个?