forked from moliware/travis-solr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.php
64 lines (45 loc) · 1.78 KB
/
Test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
if (!@include __DIR__ . '/vendor/autoload.php') {
die('You must set up the project dependencies, run the following commands:
wget http://getcomposer.org/composer.phar
php composer.phar install');
}
require_once 'vendor/reprovinci/solr-php-client/Apache/Solr/Service.php';
require_once 'vendor/reprovinci/solr-php-client/Apache/Solr/Compatibility/Solr4CompatibilityLayer.php';
class Test extends PHPUnit_Framework_TestCase
{
private $solr;
private $config = [
'solr_host' => 'localhost',
'solr_port' => 8180,
'solr_core' => 'cbtest_test'
];
public function setUp()
{
$layer = new \Apache_Solr_Compatibility_Solr4CompatibilityLayer;
$this->solr = $solr = new \Apache_Solr_Service($this->config['solr_host'], $this->config['solr_port'], "/solr/".$this->config['solr_core']."/", false, $layer);
}
public function testConnection()
{
$this->assertTrue(is_numeric($this->solr->ping()));
}
public function testAddDocument() {
$doc = new Apache_Solr_Document();
$doc->id = 1;
$doc->name="test";
$doc->dstatus = 0;
$response = $this->solr->addDocument($doc);
$this->assertTrue($response->getHttpStatus() == 200, "ERROR SOLR ADD DOCUMENT:".print_r($response,true));
$response = $this->solr->commit();
$this->assertTrue($response->getHttpStatus() == 200, "ERROR SOLR COMMIT:".print_r($response,true));
}
/**
* @depends testAddDocument
*/
public function testQuery() {
$response = $this->solr->search("id:1");
$r = json_decode($response->getRawResponse(),true);
$this->assertTrue(isset($r['response']['numFound']) && $r['response']['numFound'] >=0, print_r($r,true));
}
}
?>