I have an application that uses subdomains to route to agencies:
foo.domain.dev -> Agency:showAction(foo) bar.domain.dev -> Agency:showAction(bar) domain.dev -> Agency:indexAction()
Each of them corresponds to the object and controller of the agency.
I have a listener that listens for the onDomainParse event and writes the subdomain to the request attributes.
/** * 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']); } } //... }
Then I use this in the controller to redirect to the show action:
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 )); } // ... }
My question is:
How do I fake this when running a test using WebTestCase?
source share