Page MenuHomePhorge

Fix unit test PhutilRemarkupEngineTestCase
Open, WishlistPublic

Description

It seems the unit test PhutilRemarkupEngineTestCase does not work anymore, probably since T15161.

I realized this now by launching arc unit --everything manually and discovering the existence of PhutilRemarkupEngineTestCase.

Steps to reproduce:

$ arc unit src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php 
   FAIL  PhutilRemarkupEngineTestCase::testEngine
EXCEPTION (Exception): Trying to read configuration "phabricator.production-uri" before configuration has been initialized.
#0 /phorge/src/infrastructure/env/PhabricatorEnv.php(423): PhabricatorEnv::getEnvConfig('...')
#1 /phorge/src/infrastructure/env/PhabricatorEnv.php(447): PhabricatorEnv::getProductionURI('...')
#2 /phorge/src/infrastructure/env/PhabricatorEnv.php(441): PhabricatorEnv::getSelfURIMap()
#3 /phorge/src/infrastructure/parser/PhutilURIHelper.php(43): PhabricatorEnv::isSelfURI('...')
#4 /phorge/src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php(80): PhutilURIHelper->isSelf()
#5 /phorge/src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php(186): PhutilRemarkupDocumentLinkRule->renderHyperlink('...', '...')
#6 /home/boz/repos/phorge/src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php(133): PhutilRemarkupDocumentLinkRule->markupDocumentLink(Array)
#7 [internal function]: PhutilRemarkupDocumentLinkRule->markupAlternateLink(Array)
#8 /phorge/src/infrastructure/markup/markuprule/PhutilRemarkupDocumentLinkRule.php(17): preg_replace_callback('...', Array, '...')
#9 /phorge/src/infrastructure/markup/blockrule/PhutilRemarkupBlockRule.php(92): PhutilRemarkupDocumentLinkRule->apply('...')
#10 /phorge/src/infrastructure/markup/blockrule/PhutilRemarkupDefaultBlockRule.php(17): PhutilRemarkupBlockRule->applyRules('...')
#11 /phorge/src/infrastructure/markup/remarkup/PhutilRemarkupEngine.php(283): PhutilRemarkupDefaultBlockRule->markupText('...', NULL)
#12 /phorge/src/infrastructure/markup/remarkup/PhutilRemarkupEngine.php(140): PhutilRemarkupEngine->markupBlock(Array)
#13 /phorge/src/infrastructure/markup/remarkup/PhutilRemarkupEngine.php(106): PhutilRemarkupEngine->preprocessText('...')
#14 /phorge/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php(56): PhutilRemarkupEngine->markupText('...')
#15 /phorge/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php(13): PhutilRemarkupEngineTestCase->markupText('...')
#16 /arcanist/src/unit/engine/phutil/PhutilTestCase.php(639): PhutilRemarkupEngineTestCase->testEngine()
#17 /arcanist/src/unit/engine/PhutilUnitTestEngine.php(69): PhutilTestCase->run()
#18 /arcanist/src/unit/engine/ArcanistConfigurationDrivenUnitTestEngine.php(148): PhutilUnitTestEngine->run()
#19 /arcanist/src/workflow/ArcanistUnitWorkflow.php(170): ArcanistConfigurationDrivenUnitTestEngine->run()
#20 /arcanist/scripts/arcanist.php(427): ArcanistUnitWorkflow->run()
#21 {main}

So:

Trying to read configuration "phabricator.production-uri" before configuration has been initialized.

Possible cause

Probably the unit test is not configuring the ENV correctly.

Possible solution

This seems a unit test that sets a fake ENV various times and it works:

https://we.phorge.it/source/phorge/browse/master/src/infrastructure/env/__tests__/PhabricatorEnvTestCase.php

So the unit test PhutilRemarkupEngineTestCase should do something like this, early:

$env = PhabricatorEnv::beginScopedEnv();
$env->overrideEnvConfig('phabricator.production-uri', $something);

Sub-problem

Unfortunately this patch does not work:

diff --git a/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php b/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php
index 2f1ac692b9..6f2cdec7f4 100644
--- a/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php
+++ b/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php
@@ -27,6 +27,11 @@ final class PhutilRemarkupEngineTestCase extends PhutilTestCase {
     $expected_output = $this->unescapeTrailingWhitespace($expected_output);
     $expected_text = $this->unescapeTrailingWhitespace($expected_text);
 
+    $env = PhabricatorEnv::beginScopedEnv();
+    $env->overrideEnvConfig(
+      'phabricator.production-uri',
+      'https://phorge.localhost');
+
     $engine = $this->buildNewTestEngine();
 
     switch ($file) {

Error:

[2024-12-09 09:42:04] EXCEPTION: (Error) Call to a member function pushSource() on null at [<phorge>/src/infrastructure/env/PhabricatorEnv.php:606]
arcanist(head=arcpatch-D25823_1, ref.master=b3d45c710414, ref.arcpatch-D25823_1=f67bffc37bbb), phorge(head=master, ref.master=e5d7c9aa4e0b)
  #0 PhabricatorEnv::pushTestEnvironment() called at [<phorge>/src/infrastructure/env/PhabricatorEnv.php:596]
  #1 PhabricatorEnv::beginScopedEnv() called at [<phorge>/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php:30]
  #2 PhutilRemarkupEngineTestCase::markupText(string) called at [<phorge>/src/infrastructure/markup/remarkup/__tests__/PhutilRemarkupEngineTestCase.php:13]
  #3 PhutilRemarkupEngineTestCase::testEngine() called at [<arcanist>/src/unit/engine/phutil/PhutilTestCase.php:639]
  #4 PhutilTestCase::run() called at [<arcanist>/src/unit/engine/PhutilUnitTestEngine.php:69]
  #5 PhutilUnitTestEngine::run() called at [<arcanist>/src/unit/engine/ArcanistConfigurationDrivenUnitTestEngine.php:148]
  #6 ArcanistConfigurationDrivenUnitTestEngine::run() called at [<arcanist>/src/workflow/ArcanistUnitWorkflow.php:170]
  #7 ArcanistUnitWorkflow::run() called at [<arcanist>/scripts/arcanist.php:427]

So it's not clear to me why PhabricatorEnvTestCase works.

Revisions and Commits