summaryrefslogtreecommitdiff
path: root/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php
diff options
context:
space:
mode:
authorYuriy Andamasov <yuriy@vyos.io>2026-05-23 13:54:24 +0300
committerYuriy Andamasov <yuriy@vyos.io>2026-05-23 13:55:22 +0300
commit4d836601cb2f602c0089134eda1604f605fb39da (patch)
treed034801a5667eeb638983bf952a9c8ae3f4cb544 /src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php
parent51ceab16c95efc5527445788cb83f0289675d0bf (diff)
downloadphorge-elasticsearch-modern-4d836601cb2f602c0089134eda1604f605fb39da.tar.gz
phorge-elasticsearch-modern-4d836601cb2f602c0089134eda1604f605fb39da.zip
E8 fixup: four correctness fixes from Phase 0 review
1. strlen(\$query_string) → null-safe check \$query->getParameter('query') may return null; strlen(null) is deprecated in PHP 8.1+. Switch to explicit !== null && !== '' check. 2. ids.values nesting fix in buildSpec() 'values' => array(\$exclude) wraps an already-array \$exclude in a nested array, producing invalid Elasticsearch ids syntax. Cast to (array) then re-index with array_values() so both scalar PHID and array-of-PHIDs produce a flat list. 3. initIndex() host consistency: pass write host to indexExists() initIndex() called indexExists() without a host argument, which fell back to the read host, then deleted via getHostForWrite(). A read/write split lag window could cause false-positive "index doesn't exist" results. Pass the already-resolved write host. 4. getIndexStats() unchecked array access \$res['indices'][\$this->index] was accessed without verifying the key exists. If the index was just deleted or the name drifted, this throws an undefined-offset PHP notice. Add an explicit isset() guard with a clear exception message naming the index. 🤖 Generated by [robots](https://vyos.io)
Diffstat (limited to 'src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php')
-rw-r--r--src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php b/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php
index 9f08f8c..8a8b29c 100644
--- a/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php
+++ b/src/__tests__/VyOSElasticModernFulltextStorageEngineTestCase.php
@@ -257,4 +257,24 @@ final class VyOSElasticModernFulltextStorageEngineTestCase
$this->assertEqual('lastModified', $engine->getTimestampField());
}
+ public function testBuildSpecTreatsZeroQueryAsSearchTerm() {
+ // '0' is falsy in PHP but must be treated as a non-empty search term.
+ // strlen('0') == 1, so the query clause should be present and the
+ // default date-sorted path should NOT fire.
+ $engine = $this->newEngine()->setVersion(7);
+ $query = id(new PhabricatorSavedQuery())
+ ->setParameter('query', '0');
+
+ $method = new ReflectionMethod($engine, 'buildSpec');
+ $method->setAccessible(true);
+ $spec = $method->invoke($engine, $query, array('TASK'));
+
+ $this->assertFalse(isset($spec['sort']));
+ $this->assertEqual(
+ '0',
+ idxv(
+ $spec,
+ array('query', 'bool', 'must', 0, 'simple_query_string', 'query')));
+ }
+
}