3 namespace Drupal\Tests;
5 use Symfony\Component\HttpFoundation\Request;
7 trait XdebugRequestTrait {
10 * Adds xdebug cookies, from request setup.
12 * In order to debug web tests you need to either set a cookie, have the
13 * Xdebug session in the URL or set an environment variable in case of CLI
14 * requests. If the developer listens to connection on the parent site, by
15 * default the cookie is not forwarded to the client side, so you cannot
16 * debug the code running on the child site. In order to make debuggers work
17 * this bit of information is forwarded. Make sure that the debugger listens
18 * to at least three external connections.
20 * @param \Symfony\Component\HttpFoundation\Request $request
24 * The extracted cookies.
26 protected function extractCookiesFromRequest(Request $request) {
27 $cookie_params = $request->cookies;
29 if ($cookie_params->has('XDEBUG_SESSION')) {
30 $cookies['XDEBUG_SESSION'][] = $cookie_params->get('XDEBUG_SESSION');
32 // For CLI requests, the information is stored in $_SERVER.
33 $server = $request->server;
34 if ($server->has('XDEBUG_CONFIG')) {
35 // $_SERVER['XDEBUG_CONFIG'] has the form "key1=value1 key2=value2 ...".
36 $pairs = explode(' ', $server->get('XDEBUG_CONFIG'));
37 foreach ($pairs as $pair) {
38 list($key, $value) = explode('=', $pair);
39 // Account for key-value pairs being separated by multiple spaces.
40 if (trim($key, ' ') == 'idekey') {
41 $cookies['XDEBUG_SESSION'][] = trim($value, ' ');