Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/CurationSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Class CurationSet
*
* @package \Typesense
* @property-read CurationSetItems $items
*/
class CurationSet
{
Expand Down Expand Up @@ -37,14 +38,15 @@ public function __construct(string $curationSetName, ApiCall $apiCall)
}

/**
* @param $id
* @param string $id
*
* @return mixed
*/
public function __get($id)
{
if (isset($this->{$id})) {
return $this->{$id};
if ($id !== 'items') {
trigger_error(sprintf('Undefined property: %s::$%s', static::class, $id), E_USER_WARNING);
return null;
}

if (!isset($this->typesenseCurationSetItems[$id])) {
Expand Down
8 changes: 5 additions & 3 deletions src/SynonymSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Class SynonymSet
*
* @package \Typesense
* @property-read SynonymSetItems $items
*/
class SynonymSet
{
Expand Down Expand Up @@ -37,14 +38,15 @@ public function __construct(string $synonymSetName, ApiCall $apiCall)
}

/**
* @param $id
* @param string $id
*
* @return mixed
*/
public function __get($id)
{
if (isset($this->{$id})) {
return $this->{$id};
if ($id !== 'items') {
trigger_error(sprintf('Undefined property: %s::$%s', static::class, $id), E_USER_WARNING);
return null;
}

if (!isset($this->typesenseSynonymSetItems[$id])) {
Expand Down
30 changes: 30 additions & 0 deletions tests/Feature/CurationSetItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,34 @@ public function testCanUpsertRetrieveAndDeleteAnItem(): void
$deletion = $this->curationSets['test-curation-set-items']->getItems()['rule-1']->delete();
$this->assertEquals('rule-1', $deletion['id']);
}

public function testGetItemsReturnsTheItemsProperty(): void
{
$curationSet = $this->curationSets['test-curation-set-items'];

$this->assertSame($curationSet->items, $curationSet->getItems());
}

public function testPropertiesOtherThanItemsAreUndefined(): void
{
$curationSet = $this->curationSets['test-curation-set-items'];
$warnings = [];
set_error_handler(function (int $level, string $message) use (&$warnings): bool {
$warnings[] = $message;
return true;
}, E_USER_WARNING);

try {
$values = [$curationSet->itmes, $curationSet->curationSetName, $curationSet->apiCall];
} finally {
restore_error_handler();
}

$this->assertSame([null, null, null], $values);
$this->assertSame([
'Undefined property: Typesense\CurationSet::$itmes',
'Undefined property: Typesense\CurationSet::$curationSetName',
'Undefined property: Typesense\CurationSet::$apiCall',
], $warnings);
}
}
23 changes: 23 additions & 0 deletions tests/Feature/SynonymSetItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,27 @@ public function testGetItemsReturnsTheItemsProperty(): void

$this->assertSame($synonymSet->items, $synonymSet->getItems());
}

public function testPropertiesOtherThanItemsAreUndefined(): void
{
$synonymSet = $this->synonymSets['test-synonym-set-items'];
$warnings = [];
set_error_handler(function (int $level, string $message) use (&$warnings): bool {
$warnings[] = $message;
return true;
}, E_USER_WARNING);

try {
$values = [$synonymSet->itmes, $synonymSet->synonymSetName, $synonymSet->apiCall];
} finally {
restore_error_handler();
}

$this->assertSame([null, null, null], $values);
$this->assertSame([
'Undefined property: Typesense\SynonymSet::$itmes',
'Undefined property: Typesense\SynonymSet::$synonymSetName',
'Undefined property: Typesense\SynonymSet::$apiCall',
], $warnings);
}
}
Loading