2626use Elastic \Apm \ElasticApm ;
2727use Elastic \Apm \Impl \Config \AllOptionsMetadata ;
2828use Elastic \Apm \Impl \Config \OptionNames ;
29+ use Elastic \Apm \Impl \Constants ;
2930use Elastic \Apm \Impl \StackTraceFrame ;
3031use Elastic \Apm \Impl \Util \ArrayUtil ;
3132use Elastic \Apm \Impl \Util \ClassNameUtil ;
@@ -193,10 +194,10 @@ public function dataProviderForTestPhpErrorUndefinedVariable(): iterable
193194 {
194195 $ result = (new DataProviderForTestBuilder ())
195196 ->addBoolKeyedDimensionAllValuesCombinable (self ::INCLUDE_IN_ERROR_REPORTING_KEY )
196- ->addBoolKeyedDimensionAllValuesCombinable (OptionNames::CAPTURE_ERRORS )
197- ->addBoolKeyedDimensionAllValuesCombinable (OptionNames::CAPTURE_ERRORS_WITH_PHP_PART )
198- ->addKeyedDimensionAllValuesCombinable (OptionNames::CAPTURE_EXCEPTIONS , [ null , false , true ] )
199- ->addKeyedDimensionAllValuesCombinable (OptionNames::DEV_INTERNAL_CAPTURE_ERRORS_ONLY_TO_LOG , [ false , true ] )
197+ ->addAgentBoolConfigOptionKeyedDimensionAllValuesCombinable (OptionNames::CAPTURE_ERRORS )
198+ ->addAgentBoolConfigOptionKeyedDimensionAllValuesCombinable (OptionNames::CAPTURE_ERRORS_WITH_PHP_PART )
199+ ->addAgentNullableBoolConfigOptionKeyedDimensionAllValuesCombinable (OptionNames::CAPTURE_EXCEPTIONS )
200+ ->addAgentBoolConfigOptionKeyedDimensionAllValuesCombinable (OptionNames::DEV_INTERNAL_CAPTURE_ERRORS_ONLY_TO_LOG )
200201 ->build ();
201202
202203 return DataProviderForTestBuilder::convertEachDataSetToMixedMap (self ::adaptKeyValueToSmoke ($ result ));
@@ -226,6 +227,7 @@ function (AppCodeRequestParams $appCodeRequestParams) use ($testArgs): void {
226227 $ expectedErrorCount = $ isErrorExpected ? 1 : 0 ;
227228 $ dataFromAgent = $ testCaseHandle ->waitForDataFromAgent ((new ExpectedEventCounts ())->transactions (1 )->errors ($ expectedErrorCount ));
228229 $ dbgCtx ->add (compact ('dataFromAgent ' ));
230+
229231 self ::assertCount ($ expectedErrorCount , $ dataFromAgent ->idToError );
230232 if (!$ isErrorExpected ) {
231233 return ;
@@ -302,6 +304,14 @@ function () use ($testArgs): void {
302304
303305 public static function appCodeForTestPhpErrorUncaughtExceptionWrapper (bool $ justReturnLineNumber = false ): int
304306 {
307+ if (!$ justReturnLineNumber ) {
308+ /**
309+ * We set display_errors to 0 to ensure HTTP status 500 is returned on PHP error.
310+ * For more details see https://bugs.php.net/bug.php?id=50921
311+ */
312+ ini_set ('display_errors ' , '0 ' );
313+ }
314+
305315 return $ justReturnLineNumber ? __LINE__ : appCodeForTestPhpErrorUncaughtException ();
306316 }
307317
@@ -337,12 +347,7 @@ private function implTestPhpErrorUncaughtException(MixedMap $testArgs): void
337347 AppCodeTarget::asRouted ([__CLASS__ , 'appCodeForTestPhpErrorUncaughtExceptionWrapper ' ]),
338348 function (AppCodeRequestParams $ appCodeRequestParams ): void {
339349 if ($ appCodeRequestParams instanceof HttpAppCodeRequestParams) {
340- /**
341- * It seems it depends on 'display_errors' whether 200 or 500 is returned on PHP error.
342- * We ignore HTTP status since it's not the main point of the test case.
343- * For more details see https://bugs.php.net/bug.php?id=50921
344- */
345- $ appCodeRequestParams ->expectedHttpResponseStatusCode = null ;
350+ $ appCodeRequestParams ->expectedHttpResponseStatusCode = HttpConstantsForTests::STATUS_INTERNAL_SERVER_ERROR ;
346351 }
347352 }
348353 );
@@ -364,6 +369,11 @@ function (AppCodeRequestParams $appCodeRequestParams): void {
364369 $ expectedErrorCount = $ isErrorExpected ? 1 : 0 ;
365370 $ dataFromAgent = $ testCaseHandle ->waitForDataFromAgent ((new ExpectedEventCounts ())->transactions (1 )->errors ($ expectedErrorCount ));
366371 $ dbgCtx ->add (compact ('dataFromAgent ' ));
372+
373+ if (self ::isMainAppCodeHostHttp ()) {
374+ self ::assertSame (Constants::OUTCOME_FAILURE , $ dataFromAgent ->singleTransaction ()->outcome );
375+ }
376+
367377 self ::assertCount ($ expectedErrorCount , $ dataFromAgent ->idToError );
368378 if (!$ isErrorExpected ) {
369379 return ;
@@ -468,6 +478,11 @@ function (AppCodeRequestParams $appCodeRequestParams): void {
468478 $ expectedErrorCount = $ isErrorExpected ? 1 : 0 ;
469479 $ dataFromAgent = $ testCaseHandle ->waitForDataFromAgent ((new ExpectedEventCounts ())->transactions (1 )->errors ($ expectedErrorCount ));
470480 $ dbgCtx ->add (compact ('dataFromAgent ' ));
481+
482+ if (self ::isMainAppCodeHostHttp ()) {
483+ self ::assertSame (Constants::OUTCOME_FAILURE , $ dataFromAgent ->singleTransaction ()->outcome );
484+ }
485+
471486 self ::assertCount ($ expectedErrorCount , $ dataFromAgent ->idToError );
472487 if (!$ isErrorExpected ) {
473488 return ;
0 commit comments