Skip to content

Commit b62f408

Browse files
damcouchloelbn
andauthored
Add Algolia CTS (#665)
* Indexing and Settings tests for SearchIndexTest.php * Add SearchTest method * Add SynonymsTest method * Add testQueryRules method * Add testBatching method * Add testReplacing and testExists methods + move sample data * Add SearchClientTest.php * Add multiQueries test * Adding AccountTest.php and remove usage of SyncClient * Adding SecuredApiKeysTest * Adding AnalyticsClientTest.php * Adding AnalyticsClientTest.php * Adding InsightsClientTest.php * Adding RecommendationClientTest.php + CS fixer * Adding Mcm tests * Add stopAbTest() test * Remove unnecessary files * Handling of param array in the $queries array for multipleQueries method (#663) * Remove unnecessary files * First required changes * Removing self::assert* notations * fix(cts): delete indexes initialisation * Using wait() on saveObject() rather than multiResponse * Removing all static arrays for indices * Removing unwanted setPersonalizationStrategy call * use secured index name * Required changes after code review * Adding loop to check if indices exist before additing the A/B Tests * Adding security into loops * Set cpts to 10 * Set cpts to 20 * Set cpts to 10 * Set cpts to 10 Co-authored-by: Chloe Liban <[email protected]>
1 parent 0097572 commit b62f408

26 files changed

+1815
-1378
lines changed

phpunit.xml.dist

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit colors="true" bootstrap="tests/bootstrap.php">
2+
<phpunit colors="true">
33
<ini name="date.timezone" value="UTC"/>
44
<testsuites>
55
<testsuite name="Community">
66
<directory suffix="Test.php">tests/Integration/</directory>
7-
<exclude>./tests/Integration/KeysTest.php</exclude>
87
</testsuite>
98
<testsuite name="AlgoliaSearch">
109
<directory suffix="Test.php">tests/Integration/</directory>

tests/Integration/AccountTest.php

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
3+
namespace Algolia\AlgoliaSearch\Tests\Integration;
4+
5+
use Algolia\AlgoliaSearch\AccountClient;
6+
use Algolia\AlgoliaSearch\Response\MultiResponse;
7+
use Algolia\AlgoliaSearch\SearchIndex;
8+
use Algolia\AlgoliaSearch\Tests\TestHelper;
9+
10+
class AccountTest extends BaseTest
11+
{
12+
protected $secondaryIndexes = array();
13+
14+
public function testCopyIndex()
15+
{
16+
$this->indexes['copy_index'] = TestHelper::getTestIndexName('copy_index');
17+
$this->indexes['copy_index_2'] = TestHelper::getTestIndexName('copy_index_2');
18+
19+
/** @var SearchIndex $copyIndex */
20+
$copyIndex = TestHelper::getClient()->initIndex($this->indexes['copy_index']);
21+
$secondaryIndex = TestHelper::getClient()->initIndex($this->indexes['copy_index_2']);
22+
23+
try {
24+
AccountClient::copyIndex($copyIndex, $secondaryIndex)->wait();
25+
} catch (\Exception $e) {
26+
$this->assertInstanceOf('\InvalidArgumentException', $e);
27+
$this->assertEquals(
28+
'If both index are on the same app, please use SearchClient::copyIndex method instead.',
29+
$e->getMessage()
30+
);
31+
}
32+
33+
$secondaryConfig = array(
34+
'appId' => getenv('ALGOLIA_APPLICATION_ID_2'),
35+
'apiKey' => getenv('ALGOLIA_ADMIN_KEY_2'),
36+
);
37+
38+
$secondaryClient = TestHelper::getClient($secondaryConfig);
39+
$this->secondaryIndexes['copy_index_2'] = TestHelper::getTestIndexName('copy_index_2');
40+
41+
/** @var SearchIndex $secondaryIndex */
42+
$secondaryIndex = $secondaryClient->initIndex($this->secondaryIndexes['copy_index_2']);
43+
44+
$responses = array();
45+
$responses[] = $copyIndex->saveObject(
46+
array('objectID' => 'one'),
47+
array('autoGenerateObjectIDIfNotExist' => true)
48+
);
49+
50+
$rule = array(
51+
'objectID' => 'one',
52+
'condition' => array(
53+
'anchoring' => 'is',
54+
'pattern' => 'pattern',
55+
),
56+
'consequence' => array(
57+
'params' => array(
58+
'query' => array(
59+
'edits' => array(
60+
array(
61+
'type' => 'remove',
62+
'delete' => 'pattern',
63+
),
64+
),
65+
),
66+
),
67+
),
68+
);
69+
70+
$responses[] = $copyIndex->saveRule($rule);
71+
72+
$synonym = array(
73+
'objectID' => 'one',
74+
'type' => 'synonym',
75+
'synonyms' => array('one', 'two'),
76+
);
77+
78+
$responses[] = $copyIndex->saveSynonym($synonym);
79+
80+
$responses[] = $copyIndex->setSettings(array('searchableAttributes' => array('objectID')));
81+
82+
/* Wait all collected task to terminate */
83+
$multiResponse = new MultiResponse($responses);
84+
$multiResponse->wait();
85+
86+
AccountClient::copyIndex($copyIndex, $secondaryIndex)->wait();
87+
88+
$result = $secondaryIndex->getObject('one');
89+
$this->assertEquals('one', $result['objectID']);
90+
91+
$result = $secondaryIndex->getSettings();
92+
$this->assertEquals(array('objectID'), $result['searchableAttributes']);
93+
94+
$result = $secondaryIndex->getRule($rule['objectID']);
95+
$this->assertEquals('one', $result['objectID']);
96+
97+
$result = $secondaryIndex->getSynonym($synonym['objectID']);
98+
$this->assertEquals('one', $result['objectID']);
99+
100+
try {
101+
AccountClient::copyIndex($copyIndex, $secondaryIndex)->wait();
102+
} catch (\Exception $e) {
103+
$this->assertInstanceOf('\InvalidArgumentException', $e);
104+
$this->assertEquals(
105+
'Destination index already exists. Please delete it before copying index across applications.',
106+
$e->getMessage()
107+
);
108+
}
109+
}
110+
}

tests/Integration/AlgoliaIntegrationTestCase.php

-166
This file was deleted.

0 commit comments

Comments
 (0)