From 3cbe65179e4edde30afd786a8a3d7ad4ebbf6abf Mon Sep 17 00:00:00 2001 From: Fanis Tharropoulos Date: Mon, 23 Nov 2026 17:16:47 +0200 Subject: [PATCH] fix: stop resource collection __get from returning private fields --- src/Aliases.php | 4 ---- src/AnalyticsRules.php | 3 --- src/Collections.php | 3 --- src/ConversationModels.php | 3 --- src/Conversations.php | 4 ---- src/NLSearchModels.php | 3 --- src/Presets.php | 3 --- tests/Feature/AliasesTest.php | 10 ++++++++++ tests/Feature/AnalyticsRulesTest.php | 12 +++++++++++- tests/Feature/ClientTest.php | 10 ++++++++++ tests/Feature/CollectionsTest.php | 9 +++++++++ tests/Feature/ConversationModelsTest.php | 10 ++++++++++ tests/Feature/ConversationTest.php | 10 ++++++++++ tests/Feature/PresetsTest.php | 10 ++++++++++ 14 files changed, 70 insertions(+), 24 deletions(-) diff --git a/src/Aliases.php b/src/Aliases.php index 61da92f6..27bea08a 100644 --- a/src/Aliases.php +++ b/src/Aliases.php @@ -88,10 +88,6 @@ public function retrieve(): array */ public function __get($name) { - if (isset($this->{$name})) { - return $this->{$name}; - } - if (!isset($this->typesenseAliases[$name])) { $this->typesenseAliases[$name] = new Alias($name, $this->apiCall); } diff --git a/src/AnalyticsRules.php b/src/AnalyticsRules.php index ca8ca9b9..ebfecf6a 100644 --- a/src/AnalyticsRules.php +++ b/src/AnalyticsRules.php @@ -57,9 +57,6 @@ public function retrieve() */ public function __get($ruleName) { - if (isset($this->{$ruleName})) { - return $this->{$ruleName}; - } if (!isset($this->analyticsRules[$ruleName])) { $this->analyticsRules[$ruleName] = new AnalyticsRule($ruleName, $this->apiCall); } diff --git a/src/Collections.php b/src/Collections.php index c0659f90..0ec44d5d 100644 --- a/src/Collections.php +++ b/src/Collections.php @@ -43,9 +43,6 @@ public function __construct(ApiCall $apiCall) */ public function __get($collectionName) { - if (isset($this->{$collectionName})) { - return $this->{$collectionName}; - } if (!isset($this->typesenseCollections[$collectionName])) { $this->typesenseCollections[$collectionName] = new Collection($collectionName, $this->apiCall); } diff --git a/src/ConversationModels.php b/src/ConversationModels.php index e69224e1..7e218527 100644 --- a/src/ConversationModels.php +++ b/src/ConversationModels.php @@ -41,9 +41,6 @@ public function __construct(ApiCall $apiCall) */ public function __get($id) { - if (isset($this->{$id})) { - return $this->{$id}; - } if (!isset($this->typesenseModels[$id])) { $this->typesenseModels[$id] = new ConversationModel($id, $this->apiCall); } diff --git a/src/Conversations.php b/src/Conversations.php index 37842839..485d080d 100644 --- a/src/Conversations.php +++ b/src/Conversations.php @@ -62,10 +62,6 @@ public function getModels(): ConversationModels */ public function __get($id) { - if (isset($this->{$id})) { - return $this->{$id}; - } - if (!isset($this->individualConversations[$id])) { $this->individualConversations[$id] = new Conversation($id, $this->apiCall); } diff --git a/src/NLSearchModels.php b/src/NLSearchModels.php index 9d9a4085..a7ac6d53 100644 --- a/src/NLSearchModels.php +++ b/src/NLSearchModels.php @@ -41,9 +41,6 @@ public function __construct(ApiCall $apiCall) */ public function __get($id) { - if (isset($this->{$id})) { - return $this->{$id}; - } if (!isset($this->nlSearchModels[$id])) { $this->nlSearchModels[$id] = new NLSearchModel($id, $this->apiCall); } diff --git a/src/Presets.php b/src/Presets.php index 72c0597d..c642c6aa 100644 --- a/src/Presets.php +++ b/src/Presets.php @@ -125,9 +125,6 @@ private function multiSearchEndpointPath() */ public function __get($presetName) { - if (isset($this->{$presetName})) { - return $this->{$presetName}; - } if (!isset($this->typesensePresets[$presetName])) { $this->typesensePresets[$presetName] = new Preset($presetName, $this->apiCall); } diff --git a/tests/Feature/AliasesTest.php b/tests/Feature/AliasesTest.php index 903b2058..15d05b05 100644 --- a/tests/Feature/AliasesTest.php +++ b/tests/Feature/AliasesTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature; use Tests\TestCase; +use Typesense\Alias; use Typesense\Exceptions\ObjectNotFound; class AliasesTest extends TestCase @@ -66,4 +67,13 @@ public function testCanRetrieveAllAliases(): void $this->assertEquals(['aliases' => [0 => $this->sampleAliasResponse]], $response); } + + public function testPrivateFieldNamesResolveToAliases(): void + { + $aliases = $this->client()->aliases; + + $this->assertInstanceOf(Alias::class, $aliases->apiCall); + $this->assertSame($aliases['apiCall'], $aliases->apiCall); + $this->assertSame($aliases['typesenseAliases'], $aliases->typesenseAliases); + } } diff --git a/tests/Feature/AnalyticsRulesTest.php b/tests/Feature/AnalyticsRulesTest.php index d98e0594..7c916bd5 100644 --- a/tests/Feature/AnalyticsRulesTest.php +++ b/tests/Feature/AnalyticsRulesTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature; use Tests\TestCase; +use Typesense\AnalyticsRule; use Typesense\Exceptions\RequestMalformed; use Exception; @@ -167,4 +168,13 @@ public function testArrayAccessCompatibility(): void $rule = $this->client()->analytics->rules()[$this->ruleName]; $this->assertInstanceOf('Typesense\AnalyticsRule', $rule); } -} \ No newline at end of file + + public function testPrivateFieldNamesResolveToRules(): void + { + $rules = $this->client()->analytics->rules(); + + $this->assertInstanceOf(AnalyticsRule::class, $rules->apiCall); + $this->assertSame($rules['apiCall'], $rules->apiCall); + $this->assertSame($rules['analyticsRules'], $rules->analyticsRules); + } +} diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index 3824ed5c..9acd325c 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -15,6 +15,7 @@ use Typesense\Presets; use Typesense\Analytics; use Typesense\Conversations; +use Typesense\NLSearchModel; class ClientTest extends TestCase { @@ -33,4 +34,13 @@ public function testCanCreateAClient(): void $this->assertInstanceOf(Analytics::class, $this->client()->analytics); $this->assertInstanceOf(Conversations::class, $this->client()->conversations); } + + public function testPrivateFieldNamesResolveToNLSearchModels(): void + { + $models = $this->client()->nlSearchModels; + + $this->assertInstanceOf(NLSearchModel::class, $models->apiCall); + $this->assertSame($models['apiCall'], $models->apiCall); + $this->assertSame($models['nlSearchModels'], $models->nlSearchModels); + } } diff --git a/tests/Feature/CollectionsTest.php b/tests/Feature/CollectionsTest.php index efb13285..ca0c5ff1 100644 --- a/tests/Feature/CollectionsTest.php +++ b/tests/Feature/CollectionsTest.php @@ -71,4 +71,13 @@ public function testCanCloneACollectionSchema(): void $this->assertEquals('books_v2', $response['name']); $this->assertEquals($this->createCollectionRes['fields'], $response['fields']); } + + public function testPrivateFieldNamesResolveToCollections(): void + { + $collections = $this->client()->collections; + + $this->assertInstanceOf(Collection::class, $collections->apiCall); + $this->assertSame($collections['apiCall'], $collections->apiCall); + $this->assertSame($collections['typesenseCollections'], $collections->typesenseCollections); + } } diff --git a/tests/Feature/ConversationModelsTest.php b/tests/Feature/ConversationModelsTest.php index 51dd9657..c1dd7613 100644 --- a/tests/Feature/ConversationModelsTest.php +++ b/tests/Feature/ConversationModelsTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature; use Tests\ConversationsTestCase; +use Typesense\ConversationModel; class ConversationModelsTest extends ConversationsTestCase { @@ -31,4 +32,13 @@ public function testCanRetrieveAllModels(): void $response = $this->client()->conversations->typesenseModels->retrieve(); $this->assertEquals([], $response); } + + public function testPrivateFieldNamesResolveToModels(): void + { + $models = $this->mockConversations()->typesenseModels; + + $this->assertInstanceOf(ConversationModel::class, $models->apiCall); + $this->assertSame($models['apiCall'], $models->apiCall); + $this->assertSame($models['typesenseModels'], $models->typesenseModels); + } } diff --git a/tests/Feature/ConversationTest.php b/tests/Feature/ConversationTest.php index f0550b0a..e1026d17 100644 --- a/tests/Feature/ConversationTest.php +++ b/tests/Feature/ConversationTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature; use Tests\ConversationsTestCase; +use Typesense\Conversation; class ConversationTest extends ConversationsTestCase { @@ -35,6 +36,15 @@ public function testCanDeleteAConversation(): void $this->assertEquals([], $response); } + public function testPrivateFieldNamesResolveToConversations(): void + { + $conversations = $this->mockConversations(); + + $this->assertInstanceOf(Conversation::class, $conversations->apiCall); + $this->assertSame($conversations['apiCall'], $conversations->apiCall); + $this->assertSame($conversations['individualConversations'], $conversations->individualConversations); + } + private function endPointPath(): string { return sprintf('%s/%s', "/conversations", $this->id); diff --git a/tests/Feature/PresetsTest.php b/tests/Feature/PresetsTest.php index e3c7f01c..4f5203ea 100644 --- a/tests/Feature/PresetsTest.php +++ b/tests/Feature/PresetsTest.php @@ -4,6 +4,7 @@ use Tests\TestCase; use Typesense\Exceptions\ObjectNotFound; +use Typesense\Preset; class PresetsTest extends TestCase { @@ -56,4 +57,13 @@ public function testCanRetrieveAllPresets(): void $returnData = $this->client()->presets->retrieve(); $this->assertCount(1, $returnData['presets']); } + + public function testPrivateFieldNamesResolveToPresets(): void + { + $presets = $this->client()->presets; + + $this->assertInstanceOf(Preset::class, $presets->apiCall); + $this->assertSame($presets['apiCall'], $presets->apiCall); + $this->assertSame($presets['typesensePresets'], $presets->typesensePresets); + } }