1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

Fix DifferentialDiff getFieldValuesForConduit PHP 8.1 strlen(null) errors

Summary:
Fix DifferentialDiff getFieldValuesForConduit PHP 8.1 strlen(null) errors by replacing the strlen() calls with phutil_nonempty_string().

Also needed to update DifferentialDiffTestCase.php to being a PhabricatorTestCase, as it was throwing an exception prior to any code changes -
```
EXCEPTION (Exception): Trying to read configuration "policy.locked" before configuration has been initialized.
```

Fixes T15529

Test Plan: arc diff

Reviewers: O1 Blessed Committers, valerio.bozzolan, avivey

Reviewed By: O1 Blessed Committers, valerio.bozzolan, avivey

Subscribers: avivey, speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15529

Differential Revision: https://we.phorge.it/D25333
This commit is contained in:
sten 2023-08-11 10:39:59 +01:00
parent 4b3c384856
commit 8310591523
3 changed files with 42 additions and 6 deletions

View file

@ -6565,7 +6565,7 @@ phutil_register_library_map(array(
'DifferentialDiffRepositoryProjectsHeraldField' => 'DifferentialDiffHeraldField',
'DifferentialDiffSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
'DifferentialDiffSearchEngine' => 'PhabricatorApplicationSearchEngine',
'DifferentialDiffTestCase' => 'PhutilTestCase',
'DifferentialDiffTestCase' => 'PhabricatorTestCase',
'DifferentialDiffTransaction' => 'PhabricatorApplicationTransaction',
'DifferentialDiffTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'DifferentialDiffViewController' => 'DifferentialController',

View file

@ -780,7 +780,7 @@ final class DifferentialDiff
$refs = array();
$branch = $this->getBranch();
if (strlen($branch)) {
if (phutil_nonempty_string($branch)) {
$refs[] = array(
'type' => 'branch',
'name' => $branch,
@ -788,7 +788,7 @@ final class DifferentialDiff
}
$onto = $this->loadTargetBranch();
if (strlen($onto)) {
if (phutil_nonempty_string($onto)) {
$refs[] = array(
'type' => 'onto',
'name' => $onto,
@ -796,7 +796,7 @@ final class DifferentialDiff
}
$base = $this->getSourceControlBaseRevision();
if (strlen($base)) {
if ($base !== null && strlen($base)) {
$refs[] = array(
'type' => 'base',
'identifier' => $base,
@ -804,7 +804,7 @@ final class DifferentialDiff
}
$bookmark = $this->getBookmark();
if (strlen($bookmark)) {
if (phutil_nonempty_string($bookmark)) {
$refs[] = array(
'type' => 'bookmark',
'name' => $bookmark,

View file

@ -1,6 +1,12 @@
<?php
final class DifferentialDiffTestCase extends PhutilTestCase {
final class DifferentialDiffTestCase extends PhabricatorTestCase {
protected function getPhabricatorTestCaseConfiguration() {
return array(
self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true,
);
}
public function testDetectCopiedCode() {
$copies = $this->detectCopiesIn('lint_engine.diff');
@ -73,5 +79,35 @@ EODIFF;
$this->assertTrue(true);
}
public function testGetFieldValuesForConduit() {
$parser = new ArcanistDiffParser();
$raw_diff = <<<EODIFF
diff --git a/src b/src
index 123457..bb216b1 100644
--- a/src
+++ b/src
@@ -1,5 +1,5 @@
Line a
-Line b
+Line 2
Line c
Line d
Line e
EODIFF;
$diff = DifferentialDiff::newFromRawChanges(
PhabricatorUser::getOmnipotentUser(),
$parser->parseDiff($raw_diff));
$this->assertTrue(true);
$field_values = $diff->getFieldValuesForConduit();
$this->assertTrue(is_array($field_values));
foreach (['revisionPHID', 'authorPHID', 'repositoryPHID', 'refs']
as $key) {
$this->assertTrue(array_key_exists($key, $field_values));
}
}
}