Mercurial > hg > isophonics-drupal-site
comparison core/tests/Drupal/Tests/XdebugRequestTrait.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests; | |
4 | |
5 use Symfony\Component\HttpFoundation\Request; | |
6 | |
7 trait XdebugRequestTrait { | |
8 | |
9 /** | |
10 * Adds xdebug cookies, from request setup. | |
11 * | |
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. | |
19 * | |
20 * @param \Symfony\Component\HttpFoundation\Request $request | |
21 * The request. | |
22 * | |
23 * @return array | |
24 * The extracted cookies. | |
25 */ | |
26 protected function extractCookiesFromRequest(Request $request) { | |
27 $cookie_params = $request->cookies; | |
28 $cookies = []; | |
29 if ($cookie_params->has('XDEBUG_SESSION')) { | |
30 $cookies['XDEBUG_SESSION'][] = $cookie_params->get('XDEBUG_SESSION'); | |
31 } | |
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, ' '); | |
42 } | |
43 } | |
44 } | |
45 return $cookies; | |
46 } | |
47 | |
48 } |