Skip to content

Commit 191cf92

Browse files
committed
Add path_params to symfony 5.2
1 parent 4b030e9 commit 191cf92

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

src/Integrations/Integrations/Symfony/SymfonyIntegration.php

+7
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,13 @@ function (SpanData $span, $args, $response) use ($integration) {
401401
$rootSpan->meta[Tag::HTTP_STATUS_CODE] = $response->getStatusCode();
402402
}
403403

404+
$parameters = $request->get('_route_params');
405+
if (!empty($parameters) &&
406+
is_array($parameters) &&
407+
function_exists('\datadog\appsec\ddappsec_push_address')) {
408+
\datadog\appsec\ddappsec_push_address($parameters);
409+
}
410+
404411
$route = $request->get('_route');
405412
if (null !== $route && null !== $request) {
406413
if (dd_trace_env_config("DD_HTTP_SERVER_ROUTE_BASED_NAMING")) {

tests/Frameworks/Symfony/Version_5_2/src/Controller/CommonScenariosController.php

+10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ public function simpleViewAction(Request $request)
3232
]);
3333
}
3434

35+
/**
36+
* @Route("/dynamic_route/{param01}/{param02?}", name="dynamic route with optionals")
37+
*/
38+
public function dynamicWithOptionalsAction($param01, $param02)
39+
{
40+
return new Response(
41+
'Hi!'
42+
);
43+
}
44+
3545
/**
3646
* @Route("/error", name="error")
3747
* @throws \Exception
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
namespace DDTrace\Tests\Integrations\Symfony\V5_2;
4+
5+
use DDTrace\Tests\Common\WebFrameworkTestCase;
6+
use DDTrace\Tests\Frameworks\Util\Request\PostSpec;
7+
use DDTrace\Tests\Frameworks\Util\Request\GetSpec;
8+
use datadog\appsec\AppsecStatus;
9+
10+
class PathParamsTest extends WebFrameworkTestCase
11+
{
12+
protected static function getAppIndexScript()
13+
{
14+
return __DIR__ . '/../../../Frameworks/Symfony/Version_5_2/public/index.php';
15+
}
16+
17+
protected function connection()
18+
{
19+
return new \PDO('mysql:host=mysql_integration;dbname=test', 'test', 'test');
20+
}
21+
22+
protected function ddSetUp()
23+
{
24+
parent::ddSetUp();
25+
AppsecStatus::getInstance()->setDefaults();
26+
}
27+
28+
public static function ddSetUpBeforeClass()
29+
{
30+
parent::ddSetUpBeforeClass();
31+
AppsecStatus::getInstance()->init();
32+
}
33+
34+
public static function ddTearDownAfterClass()
35+
{
36+
AppsecStatus::getInstance()->destroy();
37+
parent::ddTearDownAfterClass();
38+
}
39+
40+
public function testDynamicRouteWithOptionalsFilled()
41+
{
42+
$param01 = 'first_param';
43+
$param02 = 'second_param';
44+
$this->call(GetSpec::create('dynamic', "/dynamic_route/$param01/$param02"));
45+
$events = AppsecStatus::getInstance()->getEvents();
46+
$this->assertEquals(1, count($events));
47+
$this->assertEquals($param01, $events[0]['param01']);
48+
$this->assertEquals($param02, $events[0]['param02']);
49+
$this->assertEquals('ddappsec_push_address', $events[0]['eventName']);
50+
}
51+
52+
public function testDynamicRouteWithOptionalsNotFilled()
53+
{
54+
$param01 = 'first_param';
55+
$this->call(GetSpec::create('dynamic', "/dynamic_route/$param01"));
56+
$events = AppsecStatus::getInstance()->getEvents();
57+
$this->assertEquals(1, count($events));
58+
$this->assertEquals($param01, $events[0]['param01']);
59+
$this->assertEmpty($events[0]['param02']);
60+
$this->assertEquals('ddappsec_push_address', $events[0]['eventName']);
61+
}
62+
63+
64+
public function testStaticRoute()
65+
{
66+
$this->call(GetSpec::create('static', "/simple"));
67+
$events = AppsecStatus::getInstance()->getEvents();
68+
$this->assertEquals(0, count($events));
69+
}
70+
}

0 commit comments

Comments
 (0)