diff --git a/core/assets/scaffold/files/example.settings.local.php b/core/assets/scaffold/files/example.settings.local.php index 7cb0e68577..1e18af9f21 100644 --- a/core/assets/scaffold/files/example.settings.local.php +++ b/core/assets/scaffold/files/example.settings.local.php @@ -32,8 +32,11 @@ * * @see https://wiki.php.net/rfc/expectations */ -assert_options(ASSERT_ACTIVE, TRUE); -assert_options(ASSERT_EXCEPTION, TRUE); +if (PHP_VERSION_ID < 80300) { + // phpcs:ignore Generic.PHP.DeprecatedFunctions.Deprecated + assert_options(ASSERT_ACTIVE, TRUE); + assert_options(ASSERT_EXCEPTION, TRUE); +} /** * Enable local development services. diff --git a/core/modules/jsonapi/src/EventSubscriber/ResourceResponseValidator.php b/core/modules/jsonapi/src/EventSubscriber/ResourceResponseValidator.php index 9761f0a7f3..167bf8af62 100644 --- a/core/modules/jsonapi/src/EventSubscriber/ResourceResponseValidator.php +++ b/core/modules/jsonapi/src/EventSubscriber/ResourceResponseValidator.php @@ -105,16 +105,8 @@ public function onResponse(ResponseEvent $event) { return; } - $this->doValidateResponse($response, $event->getRequest()); - } - - /** - * Wraps validation in an assert to prevent execution in production. - * - * @see self::validateResponse - */ - public function doValidateResponse(Response $response, Request $request) { - assert($this->validateResponse($response, $request), 'A JSON:API response failed validation (see the logs for details). Please report this in the issue queue on drupal.org'); + // Wraps validation in an assert to prevent execution in production. + assert($this->validateResponse($response, $event->getRequest())); } /** diff --git a/core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php b/core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php index df1c67603d..0e889198c2 100644 --- a/core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php +++ b/core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.php @@ -54,51 +54,6 @@ protected function setUp(): void { $this->subscriber = $subscriber; } - /** - * @covers ::doValidateResponse - */ - public function testDoValidateResponse() { - $request = $this->createRequest( - 'jsonapi.node--article.individual', - new ResourceType('node', 'article', NULL) - ); - - $response = $this->createResponse('{"data":null}'); - - // Capture the default assert settings. - $zend_assertions_default = ini_get('zend.assertions'); - // phpcs:ignore Generic.PHP.DeprecatedFunctions.Deprecated - $assert_active_default = assert_options(ASSERT_ACTIVE); - - // The validator *should* be called when asserts are active. - $validator = $this->prophesize(Validator::class); - $validator->check(Argument::any(), Argument::any())->shouldBeCalled('Validation should be run when asserts are active.'); - $validator->isValid()->willReturn(TRUE); - $this->subscriber->setValidator($validator->reveal()); - - // Ensure asset is active. - ini_set('zend.assertions', 1); - // phpcs:ignore Generic.PHP.DeprecatedFunctions.Deprecated - assert_options(ASSERT_ACTIVE, 1); - $this->subscriber->doValidateResponse($response, $request); - - // The validator should *not* be called when asserts are inactive. - $validator = $this->prophesize(Validator::class); - $validator->check(Argument::any(), Argument::any())->shouldNotBeCalled('Validation should not be run when asserts are not active.'); - $this->subscriber->setValidator($validator->reveal()); - - // Ensure asset is inactive. - ini_set('zend.assertions', 0); - // phpcs:ignore Generic.PHP.DeprecatedFunctions.Deprecated - assert_options(ASSERT_ACTIVE, 0); - $this->subscriber->doValidateResponse($response, $request); - - // Reset the original assert values. - ini_set('zend.assertions', $zend_assertions_default); - // phpcs:ignore Generic.PHP.DeprecatedFunctions.Deprecated - assert_options(ASSERT_ACTIVE, $assert_active_default); - } - /** * @covers ::validateResponse * @dataProvider validateResponseProvider