Skip to content

Commit 58016f3

Browse files
committed
Used Services::injectMock instead of ReflectionClass
1 parent 655e6b6 commit 58016f3

1 file changed

Lines changed: 4 additions & 11 deletions

File tree

tests/system/HTTP/ResponseTest.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use DateTimeZone;
2525
use PHPUnit\Framework\Attributes\DataProvider;
2626
use PHPUnit\Framework\Attributes\Group;
27-
use ReflectionClass;
2827

2928
/**
3029
* @internal
@@ -612,14 +611,11 @@ public function testSendRemovesCustomNoncePlaceholdersWhenCSPDisabled(): void
612611
$cspConfig->scriptNonceTag = '{custom-script-tag}';
613612
$cspConfig->styleNonceTag = '{custom-style-tag}';
614613

614+
Services::injectMock('csp', new ContentSecurityPolicy($cspConfig));
615+
615616
$response = new Response($appConfig);
616617
$response->pretend(true);
617618

618-
// Inject the custom CSP config
619-
$reflection = new ReflectionClass($response);
620-
$cspProperty = $reflection->getProperty('CSP');
621-
$cspProperty->setValue($response, new ContentSecurityPolicy($cspConfig));
622-
623619
$body = '<html><script {custom-script-tag}>test()</script><style {custom-style-tag}>.x{}</style></html>';
624620
$response->setBody($body);
625621

@@ -708,14 +704,11 @@ public function testSendRemovesPlaceholdersWhenBothCSPAndAutoNonceAreDisabled():
708704
$cspConfig = new \Config\ContentSecurityPolicy();
709705
$cspConfig->autoNonce = false;
710706

707+
Services::injectMock('csp', new ContentSecurityPolicy($cspConfig));
708+
711709
$response = new Response($appConfig);
712710
$response->pretend(true);
713711

714-
// Inject the custom CSP config
715-
$reflection = new ReflectionClass($response);
716-
$cspProperty = $reflection->getProperty('CSP');
717-
$cspProperty->setValue($response, new ContentSecurityPolicy($cspConfig));
718-
719712
$body = '<html><script {csp-script-nonce}>test()</script><style {csp-style-nonce}>.x{}</style></html>';
720713
$response->setBody($body);
721714

0 commit comments

Comments
 (0)