Skip to content

Commit 523db65

Browse files
authored
Merge pull request #67 from phiHero/master
Add more tests
2 parents d0ce46c + 0b36de4 commit 523db65

23 files changed

Lines changed: 816 additions & 58 deletions

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ jobs:
2626
coverage: xdebug
2727
- uses: php-actions/composer@v6
2828
- name: Run tests
29-
run: vendor/bin/phpunit --coverage-text
29+
run: vendor/bin/phpunit --coverage-text --testdox

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"Composer\\Config::disableProcessTimeout",
6666
"docker-compose up"
6767
],
68-
"test": "vendor/bin/phpunit",
68+
"test": "vendor/bin/phpunit --testdox",
6969
"lint": "phpcs -v",
7070
"lint:fix": "phpcbf"
7171
}

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
failOnWarning="true"
1111
failOnNotice="true"
1212
failOnRisky="true"
13+
executionOrder="random"
1314
>
1415
<testsuites>
1516
<testsuite name="feature">

tests/Feature/AliasesTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Feature;
4+
5+
use Tests\TestCase;
6+
use Typesense\Exceptions\ObjectNotFound;
7+
8+
class AliasesTest extends TestCase
9+
{
10+
private $sampleAliasResponse = [
11+
"name" => "companies",
12+
"collection_name" => "companies_june11",
13+
];
14+
private $upsertResponse = null;
15+
16+
protected function setUp(): void
17+
{
18+
parent::setUp();
19+
20+
$aliasedCollection = [
21+
'collection_name' => 'companies_june11'
22+
];
23+
$this->upsertResponse = $this->client()->aliases->upsert('companies', $aliasedCollection);
24+
}
25+
26+
protected function tearDown(): void
27+
{
28+
$aliases = $this->client()->aliases->retrieve();
29+
foreach ($aliases['aliases'] as $alias) {
30+
$this->client()->aliases[$alias['name']]->delete();
31+
}
32+
}
33+
34+
public function testCanUpsertAnAlias(): void
35+
{
36+
$this->assertEquals($this->sampleAliasResponse, $this->upsertResponse);
37+
}
38+
39+
public function testCanRetrieveAlias(): void
40+
{
41+
$response = $this->client()->aliases['companies']->retrieve();
42+
$this->assertEquals($this->sampleAliasResponse, $response);
43+
}
44+
45+
public function testCanDeleteAlias(): void
46+
{
47+
$response = $this->client()->aliases['companies']->delete();
48+
$this->assertEquals($this->sampleAliasResponse, $response);
49+
50+
$this->expectException(ObjectNotFound::class);
51+
$this->client()->aliases['companies']->retrieve();
52+
}
53+
54+
public function testCanRetrieveAllAliases(): void
55+
{
56+
$response = $this->client()->aliases->retrieve();
57+
58+
$this->assertEquals(['aliases' => [0 => $this->sampleAliasResponse]], $response);
59+
}
60+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Feature;
4+
5+
use Tests\TestCase;
6+
7+
class AnalyticsEventsTest extends TestCase
8+
{
9+
//* there is no method for sending events
10+
// public function testCanCreateAnEvent(): void
11+
// {
12+
// $returnData = $this->client()->analytics->rules()->even
13+
// $this->assertEquals($returnData['name'], $this->ruleName);
14+
// }
15+
16+
public function testNeedImplementationForAnalyticsEvents(): void
17+
{
18+
$this->markTestIncomplete(
19+
'This test has not been implemented yet.',
20+
);
21+
}
22+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace Feature;
4+
5+
use Tests\TestCase;
6+
use Typesense\Exceptions\ObjectNotFound;
7+
8+
class AnalyticsRulesTest extends TestCase
9+
{
10+
private $ruleName = 'product_queries_aggregation';
11+
private $ruleConfiguration = [
12+
"type" => "popular_queries",
13+
"params" => [
14+
"source" => [
15+
"collections" => ["products"]
16+
],
17+
"destination" => [
18+
"collection" => "product_queries"
19+
],
20+
"expand_query" => false,
21+
"limit" => 1000
22+
]
23+
];
24+
private $ruleUpsertResponse = null;
25+
26+
protected function setUp(): void
27+
{
28+
parent::setUp();
29+
$this->ruleUpsertResponse = $this->client()->analytics->rules()->upsert($this->ruleName, $this->ruleConfiguration);
30+
}
31+
32+
public function testCanUpsertARule(): void
33+
{
34+
$this->assertEquals($this->ruleName, $this->ruleUpsertResponse['name']);
35+
}
36+
37+
public function testCanRetrieveARule(): void
38+
{
39+
$returnData = $this->client()->analytics->rules()->{$this->ruleName}->retrieve();
40+
$this->assertEquals($returnData['name'], $this->ruleName);
41+
}
42+
43+
public function testCanDeleteARule(): void
44+
{
45+
$returnData = $this->client()->analytics->rules()->{$this->ruleName}->delete();
46+
$this->assertEquals($returnData['name'], $this->ruleName);
47+
48+
$this->expectException(ObjectNotFound::class);
49+
$this->client()->analytics->rules()->{$this->ruleName}->retrieve();
50+
}
51+
52+
public function testCanRetrieveAllRules(): void
53+
{
54+
$returnData = $this->client()->analytics->rules()->retrieve();
55+
$this->assertCount(1, $returnData['rules']);
56+
}
57+
}

tests/Feature/ClientTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Feature;
4+
5+
use Tests\TestCase;
6+
use Typesense\Collections;
7+
use Typesense\Stopwords;
8+
use Typesense\Aliases;
9+
use Typesense\Keys;
10+
use Typesense\Debug;
11+
use Typesense\Metrics;
12+
use Typesense\Health;
13+
use Typesense\Operations;
14+
use Typesense\MultiSearch;
15+
use Typesense\Presets;
16+
use Typesense\Analytics;
17+
18+
class ClientTest extends TestCase
19+
{
20+
public function testCanCreateAClient(): void
21+
{
22+
$this->assertInstanceOf(Collections::class, $this->client()->collections);
23+
$this->assertInstanceOf(Stopwords::class, $this->client()->stopwords);
24+
$this->assertInstanceOf(Aliases::class, $this->client()->aliases);
25+
$this->assertInstanceOf(Keys::class, $this->client()->keys);
26+
$this->assertInstanceOf(Debug::class, $this->client()->debug);
27+
$this->assertInstanceOf(Metrics::class, $this->client()->metrics);
28+
$this->assertInstanceOf(Health::class, $this->client()->health);
29+
$this->assertInstanceOf(Operations::class, $this->client()->operations);
30+
$this->assertInstanceOf(MultiSearch::class, $this->client()->multiSearch);
31+
$this->assertInstanceOf(Presets::class, $this->client()->presets);
32+
$this->assertInstanceOf(Analytics::class, $this->client()->analytics);
33+
}
34+
}

tests/Feature/CollectionTest.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/Feature/CollectionsTest.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Feature;
4+
5+
use Tests\TestCase;
6+
use Typesense\Exceptions\ObjectNotFound;
7+
8+
class CollectionsTest extends TestCase
9+
{
10+
private $createCollectionRes = null;
11+
12+
13+
protected function setUp(): void
14+
{
15+
parent::setUp();
16+
17+
$schema = $this->getSchema('books');
18+
$this->createCollectionRes = $this->client()->collections->create($schema);
19+
}
20+
21+
public function testCanCreateACollection(): void
22+
{
23+
$this->assertEquals('books', $this->createCollectionRes['name']);
24+
}
25+
26+
public function testCanRetrieveACollection(): void
27+
{
28+
$response = $this->client()->collections['books']->retrieve();
29+
$this->assertEquals('books', $response['name']);
30+
}
31+
32+
public function testCanUpdateACollection(): void
33+
{
34+
$update_schema = [
35+
'fields' => [
36+
[
37+
'name' => 'isbn',
38+
'drop' => true
39+
]
40+
]
41+
];
42+
$response = $this->client()->collections['books']->update($update_schema);
43+
$this->assertEquals('isbn', $response['fields'][0]['name']);
44+
$this->assertArrayHasKey('drop', $response['fields'][0]);
45+
46+
$response = $this->client()->collections['books']->retrieve();
47+
$this->assertEquals(5, count($response['fields']));
48+
}
49+
50+
public function testCanDeleteACollection(): void
51+
{
52+
$this->client()->collections['books']->delete();
53+
54+
$this->expectException(ObjectNotFound::class);
55+
$this->client()->collections['books']->retrieve();
56+
}
57+
58+
public function testCanRetrieveAllCollections(): void
59+
{
60+
$response = $this->client()->collections->retrieve();
61+
$this->assertCount(1, $response);
62+
}
63+
}

tests/Feature/DebugTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Feature;
4+
5+
use Tests\TestCase;
6+
7+
class DebugTest extends TestCase
8+
{
9+
public function testCanRetrieveDebugInformation(): void
10+
{
11+
$returnData = $this->client()->debug->retrieve();
12+
$this->assertArrayHasKey('version', $returnData);
13+
}
14+
}

0 commit comments

Comments
 (0)