Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.
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
32 changes: 32 additions & 0 deletions Model/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ public function addMetadata(
$this->metadata[$key] = $value;
}

/**
* @param string $key
*/
public function deleteMetadata(string $key)
{
unset($this->metadata[$key]);
}

/**
* Get IndexedMetadata.
*
Expand Down Expand Up @@ -323,6 +331,14 @@ public function addIndexedMetadata(
$this->indexedMetadata[$key] = $value;
}

/**
* @param string $key
*/
public function deleteIndexedMetadata(string $key)
{
unset($this->indexedMetadata[$key]);
}

/**
* Get SearchableMetadata.
*
Expand Down Expand Up @@ -356,6 +372,14 @@ public function addSearchableMetadata(
$this->searchableMetadata[$key] = $value;
}

/**
* @param string $key
*/
public function deleteSearchableMetadata(string $key)
{
unset($this->searchableMetadata[$key]);
}

/**
* Get ExactMatchingMetadata.
*
Expand Down Expand Up @@ -389,6 +413,14 @@ public function addExactMatchingMetadata(
$this->exactMatchingMetadata[$key] = $value;
}

/**
* @param string $key
*/
public function deleteExactMatchingMetadata(string $key)
{
unset($this->exactMatchingMetadata[$key]);
}

/**
* Get all metadata.
*
Expand Down
14 changes: 6 additions & 8 deletions Tests/App/AppRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

use Apisearch\App\AppRepository;
use Apisearch\Config\Config;
use Apisearch\Exception\ResourceExistsException;
use Apisearch\Exception\ResourceNotAvailableException;
use Apisearch\Model\AppUUID;
use Apisearch\Model\IndexUUID;
use Apisearch\Model\Token;
Expand Down Expand Up @@ -49,14 +51,13 @@ public function testCreateIndex()

/**
* Test create index already created.
*
* @expectedException \Apisearch\Exception\ResourceExistsException
*/
public function testCreateIndexAlreadyCreated()
{
$inMemoryAppRepository = $this->getRepository();
$inMemoryAppRepository->setRepositoryReference(RepositoryReference::create(AppUUID::createById('xxx')));
$inMemoryAppRepository->createIndex(IndexUUID::createById('yyy'), new Config());
$this->expectException(ResourceExistsException::class);
$inMemoryAppRepository->createIndex(IndexUUID::createById('yyy'), new Config());
}

Expand All @@ -75,39 +76,36 @@ public function testDeleteIndex()

/**
* Test delete index.
*
* @expectedException \Apisearch\Exception\ResourceNotAvailableException
*/
public function testDeleteIndexAlreadyDeleted()
{
$inMemoryAppRepository = $this->getRepository();
$inMemoryAppRepository->setRepositoryReference(RepositoryReference::create(AppUUID::createById('xxx')));
$inMemoryAppRepository->createIndex(IndexUUID::createById('yyy'), new Config());
$inMemoryAppRepository->deleteIndex(IndexUUID::createById('yyy'));
$this->expectException(ResourceNotAvailableException::class);
$inMemoryAppRepository->deleteIndex(IndexUUID::createById('yyy'));
}

/**
* Test delete non existing index.
*
* @expectedException \Apisearch\Exception\ResourceNotAvailableException
*/
public function testDeleteNotExistingIndex()
{
$inMemoryAppRepository = $this->getRepository();
$inMemoryAppRepository->setRepositoryReference(RepositoryReference::create(AppUUID::createById('xxx')));
$this->expectException(ResourceNotAvailableException::class);
$inMemoryAppRepository->resetIndex(IndexUUID::createById('yyy'));
}

/**
* Test configure non existing index.
*
* @expectedException \Apisearch\Exception\ResourceNotAvailableException
*/
public function testConfigureNotExistingIndex()
{
$inMemoryAppRepository = $this->getRepository();
$inMemoryAppRepository->setRepositoryReference(RepositoryReference::create(AppUUID::createById('xxx')));
$this->expectException(ResourceNotAvailableException::class);
$inMemoryAppRepository->configureIndex(IndexUUID::createById('yyy'), Config::createFromArray([]));
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/Config/SynonymReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace Apisearch\Tests\Config;

use Apisearch\Config\SynonymReader;
use Apisearch\Exception\SynonymsException;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -25,12 +26,11 @@ class SynonymReaderTest extends TestCase
{
/**
* Test non existing file.
*
* @expectedException \Apisearch\Exception\SynonymsException
*/
public function testNonExistingFile()
{
$synonymReader = new SynonymReader();
$this->expectException(SynonymsException::class);
$synonymReader->readSynonymsFromFile(__DIR__.'/nonexistingfile276892.csv');
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/Exporter/ExporterCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Apisearch\Tests\Exporter;

use Apisearch\Exception\ExporterFormatNotImplementedException;
use Apisearch\Exporter\CSVExporter;
use Apisearch\Exporter\ExporterCollection;
use Apisearch\Exporter\JSONExporter;
Expand All @@ -41,14 +42,13 @@ public function testCollection()

/**
* Test collection with exception.
*
* @expectedException \Apisearch\Exception\ExporterFormatNotImplementedException
*/
public function testCollectionException()
{
$exporterCollection = new ExporterCollection();
$exporterCollection->addExporter(new JSONExporter());
$exporterCollection->addExporter(new CSVExporter());
$this->expectException(ExporterFormatNotImplementedException::class);
$exporterCollection->getExporterByName('xml');
}
}
4 changes: 2 additions & 2 deletions Tests/Model/AppUUIDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Apisearch\Tests\Model;

use Apisearch\Exception\InvalidFormatException;
use Apisearch\Model\AppUUID;
use PHPUnit\Framework\TestCase;

Expand All @@ -27,11 +28,10 @@ class AppUUIDTest extends TestCase
* Test creation with bad data.
*
* @dataProvider dataEmptyCreation
*
* @expectedException \Apisearch\Exception\InvalidFormatException
*/
public function testEmptyCreation(array $data): void
{
$this->expectException(InvalidFormatException::class);
AppUUID::createFromArray($data);
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/Model/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Apisearch\Tests\Model;

use Apisearch\Exception\InvalidFormatException;
use Apisearch\Model\AppUUID;
use Apisearch\Model\Index;
use Apisearch\Model\IndexUUID;
Expand All @@ -29,11 +30,10 @@ class IndexTest extends TestCase
* Test creation with bad data.
*
* @dataProvider dataEmptyCreation
*
* @expectedException \Apisearch\Exception\InvalidFormatException
*/
public function testEmptyCreation(array $data): void
{
$this->expectException(InvalidFormatException::class);
Index::createFromArray($data);
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/Model/IndexUUIDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Apisearch\Tests\Model;

use Apisearch\Exception\InvalidFormatException;
use Apisearch\Model\IndexUUID;
use PHPUnit\Framework\TestCase;

Expand All @@ -27,11 +28,10 @@ class IndexUUIDTest extends TestCase
* Test creation with bad data.
*
* @dataProvider dataEmptyCreation
*
* @expectedException \Apisearch\Exception\InvalidFormatException
*/
public function testEmptyCreation(array $data): void
{
$this->expectException(InvalidFormatException::class);
IndexUUID::createFromArray($data);
}

Expand Down
28 changes: 24 additions & 4 deletions Tests/Model/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Apisearch\Tests\Model;

use Apisearch\Exception\InvalidFormatException;
use Apisearch\Model\AppUUID;
use Apisearch\Model\Coordinate;
use Apisearch\Model\IndexUUID;
Expand Down Expand Up @@ -136,11 +137,10 @@ public function testCreateEmptyValues()
* Test create item with bad formatted UUID.
*
* @dataProvider dataItemBadFormattedUUID
*
* @expectedException \Apisearch\Exception\InvalidFormatException
*/
public function testItemBadFormattedUUID($data)
{
$this->expectException(InvalidFormatException::class);
Item::createFromArray($data);
}

Expand All @@ -167,11 +167,10 @@ public function dataItemBadFormattedUUID()
* Test create Coordinate with bad formatted.
*
* @dataProvider dataCoordinateBadFormattedUUID
*
* @expectedException \Apisearch\Exception\InvalidFormatException
*/
public function testCoordinateFormattedUUID($data)
{
$this->expectException(InvalidFormatException::class);
Item::createFromArray(array_merge(['uuid' => [
'id' => '1',
'type' => 'product',
Expand Down Expand Up @@ -466,4 +465,25 @@ public function testIndexAndAppUUID()
$item->getAppUUID()
);
}

/**
* Test delete methods.
*/
public function testDeleteMethods()
{
$item = Item::createFromArray([
'uuid' => ['id' => 'A', 'type' => 'B'],
'metadata' => ['A' => 1],
'indexed_metadata' => ['B' => 2],
'searchable_metadata' => ['C' => 3],
'exact_matching_metadata' => ['D' => 4],
]);

$item->deleteMetadata('A');
$item->deleteIndexedMetadata('B');
$item->deleteSearchableMetadata('C');
$item->deleteExactMatchingMetadata('D');

$this->assertEquals(['uuid' => ['id' => 'A', 'type' => 'B']], $item->toArray());
}
}
7 changes: 3 additions & 4 deletions Tests/Model/ItemUUIDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Apisearch\Tests\Model;

use Apisearch\Exception\InvalidFormatException;
use Apisearch\Model\ItemUUID;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -56,11 +57,10 @@ public function testCreateByComposedUUID()
* Test create by composed UUID with exception.
*
* @dataProvider dataCreateByComposedUUIDException
*
* @expectedException \Apisearch\Exception\InvalidFormatException
*/
public function testCreateByComposedUUIDException(string $composedUUID)
{
$this->expectException(InvalidFormatException::class);
ItemUUID::createByComposedUUID($composedUUID);
}

Expand Down Expand Up @@ -96,11 +96,10 @@ public function testCreateFromArray()
* Test create from array with exception.
*
* @dataProvider dataCreateFromArrayException
*
* @expectedException \Apisearch\Exception\InvalidFormatException
*/
public function testCreateFromArrayException(array $composedUUID)
{
$this->expectException(InvalidFormatException::class);
ItemUUID::createFromArray($composedUUID);
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/Model/TokenUUIDTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Apisearch\Tests\Model;

use Apisearch\Exception\InvalidFormatException;
use Apisearch\Model\TokenUUID;
use PHPUnit\Framework\TestCase;

Expand All @@ -27,11 +28,10 @@ class TokenUUIDTest extends TestCase
* Test creation with bad data.
*
* @dataProvider dataEmptyCreation
*
* @expectedException \Apisearch\Exception\InvalidFormatException
*/
public function testEmptyCreation(array $data): void
{
$this->expectException(InvalidFormatException::class);
TokenUUID::createFromArray($data);
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/Model/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Apisearch\Tests\Model;

use Apisearch\Exception\InvalidFormatException;
use Apisearch\Model\User;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -54,11 +55,10 @@ public function testHttpTransport()
* Test create from array with exception.
*
* @dataProvider dataCreateFromArrayException
*
* @expectedException \Apisearch\Exception\InvalidFormatException
*/
public function testCreateFromArrayException(array $user)
{
$this->expectException(InvalidFormatException::class);
User::createFromArray($user);
}

Expand Down
Loading