forked from solariumphp/solarium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoreLikeThisTest.php
114 lines (92 loc) · 2.81 KB
/
MoreLikeThisTest.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
namespace Solarium\Tests\Component\Result\MoreLikeThis;
use PHPUnit\Framework\TestCase;
use Solarium\Component\Result\MoreLikeThis\MoreLikeThis;
use Solarium\Component\Result\MoreLikeThis\Result;
use Solarium\Exception\UnexpectedValueException;
use Solarium\QueryType\Select\Result\Document;
class MoreLikeThisTest extends TestCase
{
/**
* @var MoreLikeThis
*/
protected $mlt;
protected $results;
protected $interestingTerms;
public function setUp(): void
{
$docs = [
new Document(['id' => 1, 'name' => 'test1']),
new Document(['id' => 2, 'name' => 'test2']),
];
$this->results = [
'key1' => new Result(2, 5.13, $docs),
'key2' => new Result(2, 2.3, $docs),
];
$this->interestingTerms = [
'key1' => ['cat:term1' => 1.0, 'cat:term2' => 1.84],
'key2' => ['cat:term1' => 1.0, 'cat:term3' => 1.23],
];
$this->mlt = new MoreLikeThis($this->results, $this->interestingTerms);
}
public function testGetResults()
{
$this->assertEquals($this->results, $this->mlt->getResults());
}
public function testGetResult()
{
$this->assertEquals(
$this->results['key1'],
$this->mlt->getResult('key1')
);
}
public function testGetInvalidResult()
{
$this->assertNull(
$this->mlt->getResult('invalid')
);
}
public function testGetInterestingTerms()
{
$this->assertEquals($this->interestingTerms, $this->mlt->getInterestingTerms());
}
public function testGetInterestingTermsNone()
{
$mlt = new MoreLikeThis($this->results, null);
$this->expectException(UnexpectedValueException::class);
$this->expectExceptionMessage('interestingterms is none');
$mlt->getInterestingTerms();
}
public function testGetInterestingTerm()
{
$this->assertEquals(
$this->interestingTerms['key1'],
$this->mlt->getInterestingTerm('key1')
);
}
public function testGetInvalidInterestingTerm()
{
$this->assertNull(
$this->mlt->getInterestingTerm('invalid')
);
}
public function testGetInterestingTermNone()
{
$mlt = new MoreLikeThis($this->results, null);
$this->expectException(UnexpectedValueException::class);
$this->expectExceptionMessage('interestingterms is none');
$mlt->getInterestingTerm('key1');
}
public function testIterator()
{
$items = [];
foreach ($this->mlt as $key => $item) {
$items[$key] = $item;
}
$this->assertEquals($this->results, $items);
}
public function testCount()
{
$this->assertSameSize($this->results, $this->mlt);
}
}