-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from phiHero/master
Add more tests
- Loading branch information
Showing
23 changed files
with
816 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Feature; | ||
|
||
use Tests\TestCase; | ||
use Typesense\Exceptions\ObjectNotFound; | ||
|
||
class AliasesTest extends TestCase | ||
{ | ||
private $sampleAliasResponse = [ | ||
"name" => "companies", | ||
"collection_name" => "companies_june11", | ||
]; | ||
private $upsertResponse = null; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$aliasedCollection = [ | ||
'collection_name' => 'companies_june11' | ||
]; | ||
$this->upsertResponse = $this->client()->aliases->upsert('companies', $aliasedCollection); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
$aliases = $this->client()->aliases->retrieve(); | ||
foreach ($aliases['aliases'] as $alias) { | ||
$this->client()->aliases[$alias['name']]->delete(); | ||
} | ||
} | ||
|
||
public function testCanUpsertAnAlias(): void | ||
{ | ||
$this->assertEquals($this->sampleAliasResponse, $this->upsertResponse); | ||
} | ||
|
||
public function testCanRetrieveAlias(): void | ||
{ | ||
$response = $this->client()->aliases['companies']->retrieve(); | ||
$this->assertEquals($this->sampleAliasResponse, $response); | ||
} | ||
|
||
public function testCanDeleteAlias(): void | ||
{ | ||
$response = $this->client()->aliases['companies']->delete(); | ||
$this->assertEquals($this->sampleAliasResponse, $response); | ||
|
||
$this->expectException(ObjectNotFound::class); | ||
$this->client()->aliases['companies']->retrieve(); | ||
} | ||
|
||
public function testCanRetrieveAllAliases(): void | ||
{ | ||
$response = $this->client()->aliases->retrieve(); | ||
|
||
$this->assertEquals(['aliases' => [0 => $this->sampleAliasResponse]], $response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Feature; | ||
|
||
use Tests\TestCase; | ||
|
||
class AnalyticsEventsTest extends TestCase | ||
{ | ||
//* there is no method for sending events | ||
// public function testCanCreateAnEvent(): void | ||
// { | ||
// $returnData = $this->client()->analytics->rules()->even | ||
// $this->assertEquals($returnData['name'], $this->ruleName); | ||
// } | ||
|
||
public function testNeedImplementationForAnalyticsEvents(): void | ||
{ | ||
$this->markTestIncomplete( | ||
'This test has not been implemented yet.', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Feature; | ||
|
||
use Tests\TestCase; | ||
use Typesense\Exceptions\ObjectNotFound; | ||
|
||
class AnalyticsRulesTest extends TestCase | ||
{ | ||
private $ruleName = 'product_queries_aggregation'; | ||
private $ruleConfiguration = [ | ||
"type" => "popular_queries", | ||
"params" => [ | ||
"source" => [ | ||
"collections" => ["products"] | ||
], | ||
"destination" => [ | ||
"collection" => "product_queries" | ||
], | ||
"expand_query" => false, | ||
"limit" => 1000 | ||
] | ||
]; | ||
private $ruleUpsertResponse = null; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->ruleUpsertResponse = $this->client()->analytics->rules()->upsert($this->ruleName, $this->ruleConfiguration); | ||
} | ||
|
||
public function testCanUpsertARule(): void | ||
{ | ||
$this->assertEquals($this->ruleName, $this->ruleUpsertResponse['name']); | ||
} | ||
|
||
public function testCanRetrieveARule(): void | ||
{ | ||
$returnData = $this->client()->analytics->rules()->{$this->ruleName}->retrieve(); | ||
$this->assertEquals($returnData['name'], $this->ruleName); | ||
} | ||
|
||
public function testCanDeleteARule(): void | ||
{ | ||
$returnData = $this->client()->analytics->rules()->{$this->ruleName}->delete(); | ||
$this->assertEquals($returnData['name'], $this->ruleName); | ||
|
||
$this->expectException(ObjectNotFound::class); | ||
$this->client()->analytics->rules()->{$this->ruleName}->retrieve(); | ||
} | ||
|
||
public function testCanRetrieveAllRules(): void | ||
{ | ||
$returnData = $this->client()->analytics->rules()->retrieve(); | ||
$this->assertCount(1, $returnData['rules']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Feature; | ||
|
||
use Tests\TestCase; | ||
use Typesense\Collections; | ||
use Typesense\Stopwords; | ||
use Typesense\Aliases; | ||
use Typesense\Keys; | ||
use Typesense\Debug; | ||
use Typesense\Metrics; | ||
use Typesense\Health; | ||
use Typesense\Operations; | ||
use Typesense\MultiSearch; | ||
use Typesense\Presets; | ||
use Typesense\Analytics; | ||
|
||
class ClientTest extends TestCase | ||
{ | ||
public function testCanCreateAClient(): void | ||
{ | ||
$this->assertInstanceOf(Collections::class, $this->client()->collections); | ||
$this->assertInstanceOf(Stopwords::class, $this->client()->stopwords); | ||
$this->assertInstanceOf(Aliases::class, $this->client()->aliases); | ||
$this->assertInstanceOf(Keys::class, $this->client()->keys); | ||
$this->assertInstanceOf(Debug::class, $this->client()->debug); | ||
$this->assertInstanceOf(Metrics::class, $this->client()->metrics); | ||
$this->assertInstanceOf(Health::class, $this->client()->health); | ||
$this->assertInstanceOf(Operations::class, $this->client()->operations); | ||
$this->assertInstanceOf(MultiSearch::class, $this->client()->multiSearch); | ||
$this->assertInstanceOf(Presets::class, $this->client()->presets); | ||
$this->assertInstanceOf(Analytics::class, $this->client()->analytics); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Feature; | ||
|
||
use Tests\TestCase; | ||
use Typesense\Exceptions\ObjectNotFound; | ||
|
||
class CollectionsTest extends TestCase | ||
{ | ||
private $createCollectionRes = null; | ||
|
||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$schema = $this->getSchema('books'); | ||
$this->createCollectionRes = $this->client()->collections->create($schema); | ||
} | ||
|
||
public function testCanCreateACollection(): void | ||
{ | ||
$this->assertEquals('books', $this->createCollectionRes['name']); | ||
} | ||
|
||
public function testCanRetrieveACollection(): void | ||
{ | ||
$response = $this->client()->collections['books']->retrieve(); | ||
$this->assertEquals('books', $response['name']); | ||
} | ||
|
||
public function testCanUpdateACollection(): void | ||
{ | ||
$update_schema = [ | ||
'fields' => [ | ||
[ | ||
'name' => 'isbn', | ||
'drop' => true | ||
] | ||
] | ||
]; | ||
$response = $this->client()->collections['books']->update($update_schema); | ||
$this->assertEquals('isbn', $response['fields'][0]['name']); | ||
$this->assertArrayHasKey('drop', $response['fields'][0]); | ||
|
||
$response = $this->client()->collections['books']->retrieve(); | ||
$this->assertEquals(5, count($response['fields'])); | ||
} | ||
|
||
public function testCanDeleteACollection(): void | ||
{ | ||
$this->client()->collections['books']->delete(); | ||
|
||
$this->expectException(ObjectNotFound::class); | ||
$this->client()->collections['books']->retrieve(); | ||
} | ||
|
||
public function testCanRetrieveAllCollections(): void | ||
{ | ||
$response = $this->client()->collections->retrieve(); | ||
$this->assertCount(1, $response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Feature; | ||
|
||
use Tests\TestCase; | ||
|
||
class DebugTest extends TestCase | ||
{ | ||
public function testCanRetrieveDebugInformation(): void | ||
{ | ||
$returnData = $this->client()->debug->retrieve(); | ||
$this->assertArrayHasKey('version', $returnData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Feature; | ||
|
||
use Tests\TestCase; | ||
use Typesense\Exceptions\ObjectNotFound; | ||
|
||
class DocumentTest extends TestCase | ||
{ | ||
private $documentId = '1'; | ||
private $testDocument = null; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->setUpCollection('books'); | ||
$this->setUpDocuments('books'); | ||
|
||
$this->testDocument = $this->client()->collections['books']->documents[$this->documentId]; | ||
} | ||
|
||
public function testCanRetrieveADocumentById(): void | ||
{ | ||
$response = $this->testDocument->retrieve(); | ||
$this->assertEquals($this->documentId, $response['id']); | ||
} | ||
|
||
public function testCanUpdateADocumentById(): void | ||
{ | ||
$partialDocument = [ | ||
"title" => "hello there :D", | ||
]; | ||
$response = $this->testDocument->update($partialDocument); | ||
$this->assertEquals("hello there :D", $response['title']); | ||
} | ||
|
||
public function testCanUpdateADocumentWithDirtyValuesById(): void | ||
{ | ||
$partialDocument = [ | ||
"title" => 1, | ||
]; | ||
$response = $this->testDocument->update( | ||
$partialDocument, | ||
[ | ||
"dirty_values" => "coerce_or_reject", | ||
] | ||
); | ||
$this->assertIsString($response['title']); | ||
} | ||
|
||
public function testCanDeleteADocumentById(): void | ||
{ | ||
$response = $this->testDocument->delete(); | ||
$this->assertEquals($this->documentId, $response['id']); | ||
|
||
$this->expectException(ObjectNotFound::class); | ||
$this->testDocument->retrieve(); | ||
} | ||
} |
Oops, something went wrong.