`` compatibility between Solr versions. [#7](https://github.com/reprovinci/solr-php-client/issues/7)
57 |
58 | ## Further Information
59 | Please see [Frequently Asked Questions](http://code.google.com/p/solr-php-client/wiki/FAQ)
60 |
61 | Or, if you have usage questions, try posting to the
62 | [USER DISCUSSION GROUP](http://groups.google.com/group/php-solr-client).
63 |
64 | ## Disclaimer
65 | This PHP library is not part of the Apache Solr project, nor is it maintained by the Apache Software Foundation.
66 | All linked Apache Solr documentation or logos remain the sole property of the Apache Solr project, its authors,
67 | and the Apache Software Foundation.
68 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "reprovinci/solr-php-client",
3 | "description": "A PHP library for indexing and searching documents within an Apache Solr installation.",
4 | "license": "BSD-3-Clause",
5 | "authors": [
6 | {
7 | "name": "Donovan Jiménez",
8 | "email": "donovan.jimenez@gmail.com",
9 | "role": "Developer"
10 | },
11 | {
12 | "name": "Reinier Kip",
13 | "email": "github@reinierkip.nl",
14 | "role": "Developer"
15 | }
16 | ],
17 | "autoload": {
18 | "psr-0": {
19 | "Apache_Solr_": ["", "tests"]
20 | }
21 | },
22 | "require-dev": {
23 | "phpunit/phpunit": "3.7.*"
24 | },
25 | "config": {
26 | "bin-dir": "bin/"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "hash": "422be6f08003663225b1b5c913ab3bbe",
3 | "packages": [
4 |
5 | ],
6 | "packages-dev": [
7 | {
8 | "name": "phpunit/php-code-coverage",
9 | "version": "1.2.3",
10 | "source": {
11 | "type": "git",
12 | "url": "git://github.com/sebastianbergmann/php-code-coverage.git",
13 | "reference": "1.2.3"
14 | },
15 | "dist": {
16 | "type": "zip",
17 | "url": "https://github.com/sebastianbergmann/php-code-coverage/zipball/1.2.3",
18 | "reference": "1.2.3",
19 | "shasum": ""
20 | },
21 | "require": {
22 | "php": ">=5.3.3",
23 | "phpunit/php-file-iterator": ">=1.3.0@stable",
24 | "phpunit/php-token-stream": ">=1.1.3@stable",
25 | "phpunit/php-text-template": ">=1.1.1@stable"
26 | },
27 | "suggest": {
28 | "ext-dom": "*",
29 | "ext-reflection": "*",
30 | "ext-spl": "*",
31 | "ext-xdebug": ">=2.0.5"
32 | },
33 | "time": "2012-10-05 00:00:00",
34 | "type": "library",
35 | "installation-source": "dist",
36 | "autoload": {
37 | "classmap": [
38 | "PHP/"
39 | ]
40 | },
41 | "include-path": [
42 | ""
43 | ],
44 | "license": [
45 | "BSD-3-Clause"
46 | ],
47 | "authors": [
48 | {
49 | "name": "Sebastian Bergmann",
50 | "email": "sb@sebastian-bergmann.de",
51 | "role": "lead"
52 | }
53 | ],
54 | "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
55 | "homepage": "http://www.phpunit.de/",
56 | "keywords": [
57 | "testing",
58 | "coverage",
59 | "xunit"
60 | ]
61 | },
62 | {
63 | "name": "phpunit/php-file-iterator",
64 | "version": "1.3.3",
65 | "source": {
66 | "type": "git",
67 | "url": "git://github.com/sebastianbergmann/php-file-iterator.git",
68 | "reference": "1.3.3"
69 | },
70 | "dist": {
71 | "type": "zip",
72 | "url": "https://github.com/sebastianbergmann/php-file-iterator/zipball/1.3.3",
73 | "reference": "1.3.3",
74 | "shasum": ""
75 | },
76 | "require": {
77 | "php": ">=5.2.7"
78 | },
79 | "time": "2012-10-05 09:06:25",
80 | "type": "library",
81 | "installation-source": "dist",
82 | "autoload": {
83 | "classmap": [
84 | "File/"
85 | ]
86 | },
87 | "include-path": [
88 | ""
89 | ],
90 | "license": [
91 | "BSD-3-Clause"
92 | ],
93 | "authors": [
94 | {
95 | "name": "Sebastian Bergmann",
96 | "email": "sb@sebastian-bergmann.de",
97 | "role": "lead"
98 | }
99 | ],
100 | "description": "FilterIterator implementation that filters files based on a list of suffixes.",
101 | "homepage": "http://www.phpunit.de/",
102 | "keywords": [
103 | "filesystem",
104 | "iterator"
105 | ]
106 | },
107 | {
108 | "name": "phpunit/php-text-template",
109 | "version": "1.1.3",
110 | "source": {
111 | "type": "git",
112 | "url": "git://github.com/sebastianbergmann/php-text-template.git",
113 | "reference": "1.1.3"
114 | },
115 | "dist": {
116 | "type": "zip",
117 | "url": "https://github.com/sebastianbergmann/php-text-template/zipball/1.1.3",
118 | "reference": "1.1.3",
119 | "shasum": ""
120 | },
121 | "require": {
122 | "php": ">=5.2.7"
123 | },
124 | "time": "2012-10-05 09:17:21",
125 | "type": "library",
126 | "installation-source": "dist",
127 | "autoload": {
128 | "classmap": [
129 | "Text/"
130 | ]
131 | },
132 | "include-path": [
133 | ""
134 | ],
135 | "license": [
136 | "BSD-3-Clause"
137 | ],
138 | "authors": [
139 | {
140 | "name": "Sebastian Bergmann",
141 | "email": "sb@sebastian-bergmann.de",
142 | "role": "lead"
143 | }
144 | ],
145 | "description": "Simple template engine.",
146 | "homepage": "http://www.phpunit.de/",
147 | "keywords": [
148 | "template"
149 | ]
150 | },
151 | {
152 | "name": "phpunit/php-timer",
153 | "version": "1.0.4",
154 | "source": {
155 | "type": "git",
156 | "url": "git://github.com/sebastianbergmann/php-timer.git",
157 | "reference": "1.0.4"
158 | },
159 | "dist": {
160 | "type": "zip",
161 | "url": "https://github.com/sebastianbergmann/php-timer/zipball/1.0.4",
162 | "reference": "1.0.4",
163 | "shasum": ""
164 | },
165 | "require": {
166 | "php": ">=5.2.7"
167 | },
168 | "time": "2012-10-05 09:09:13",
169 | "type": "library",
170 | "installation-source": "dist",
171 | "autoload": {
172 | "classmap": [
173 | "PHP/"
174 | ]
175 | },
176 | "include-path": [
177 | ""
178 | ],
179 | "license": [
180 | "BSD-3-Clause"
181 | ],
182 | "authors": [
183 | {
184 | "name": "Sebastian Bergmann",
185 | "email": "sb@sebastian-bergmann.de",
186 | "role": "lead"
187 | }
188 | ],
189 | "description": "Utility class for timing",
190 | "homepage": "http://www.phpunit.de/",
191 | "keywords": [
192 | "timer"
193 | ]
194 | },
195 | {
196 | "name": "phpunit/php-token-stream",
197 | "version": "1.1.5",
198 | "source": {
199 | "type": "git",
200 | "url": "git://github.com/sebastianbergmann/php-token-stream.git",
201 | "reference": "1.1.5"
202 | },
203 | "dist": {
204 | "type": "zip",
205 | "url": "https://github.com/sebastianbergmann/php-token-stream/zipball/1.1.5",
206 | "reference": "1.1.5",
207 | "shasum": ""
208 | },
209 | "require": {
210 | "php": ">=5.2.7",
211 | "ext-tokenizer": "*"
212 | },
213 | "time": "2012-10-05 09:17:52",
214 | "type": "library",
215 | "installation-source": "dist",
216 | "autoload": {
217 | "classmap": [
218 | "PHP/"
219 | ]
220 | },
221 | "include-path": [
222 | ""
223 | ],
224 | "license": [
225 | "BSD-3-Clause"
226 | ],
227 | "authors": [
228 | {
229 | "name": "Sebastian Bergmann",
230 | "email": "sb@sebastian-bergmann.de",
231 | "role": "lead"
232 | }
233 | ],
234 | "description": "Wrapper around PHP's tokenizer extension.",
235 | "homepage": "http://www.phpunit.de/",
236 | "keywords": [
237 | "tokenizer"
238 | ]
239 | },
240 | {
241 | "name": "phpunit/phpunit",
242 | "version": "3.7.6",
243 | "source": {
244 | "type": "git",
245 | "url": "git://github.com/sebastianbergmann/phpunit.git",
246 | "reference": "3.7.6"
247 | },
248 | "dist": {
249 | "type": "zip",
250 | "url": "https://github.com/sebastianbergmann/phpunit/zipball/3.7.6",
251 | "reference": "3.7.6",
252 | "shasum": ""
253 | },
254 | "require": {
255 | "php": ">=5.3.3",
256 | "phpunit/php-file-iterator": ">=1.3.1",
257 | "phpunit/php-text-template": ">=1.1.1",
258 | "phpunit/php-code-coverage": ">=1.2.1",
259 | "phpunit/php-timer": ">=1.0.2",
260 | "phpunit/phpunit-mock-objects": ">=1.2.0",
261 | "symfony/yaml": ">=2.1.0",
262 | "ext-dom": "*",
263 | "ext-pcre": "*",
264 | "ext-reflection": "*",
265 | "ext-spl": "*"
266 | },
267 | "suggest": {
268 | "phpunit/php-invoker": ">=1.1.0",
269 | "ext-json": "*",
270 | "ext-simplexml": "*",
271 | "ext-tokenizer": "*"
272 | },
273 | "time": "2012-10-06 23:46:25",
274 | "bin": [
275 | "composer/bin/phpunit"
276 | ],
277 | "type": "library",
278 | "extra": {
279 | "branch-alias": {
280 | "dev-master": "3.7.x-dev"
281 | }
282 | },
283 | "installation-source": "dist",
284 | "autoload": {
285 | "classmap": [
286 | "PHPUnit/"
287 | ]
288 | },
289 | "include-path": [
290 | "",
291 | "../../symfony/yaml/"
292 | ],
293 | "license": [
294 | "BSD-3-Clause"
295 | ],
296 | "authors": [
297 | {
298 | "name": "Sebastian Bergmann",
299 | "email": "sebastian@phpunit.de",
300 | "role": "lead"
301 | }
302 | ],
303 | "description": "The PHP Unit Testing framework.",
304 | "homepage": "http://www.phpunit.de/",
305 | "keywords": [
306 | "testing",
307 | "phpunit",
308 | "xunit"
309 | ]
310 | },
311 | {
312 | "name": "phpunit/phpunit-mock-objects",
313 | "version": "1.2.1",
314 | "source": {
315 | "type": "git",
316 | "url": "git://github.com/sebastianbergmann/phpunit-mock-objects.git",
317 | "reference": "1.2.1"
318 | },
319 | "dist": {
320 | "type": "zip",
321 | "url": "https://github.com/sebastianbergmann/phpunit-mock-objects/zipball/1.2.1",
322 | "reference": "1.2.1",
323 | "shasum": ""
324 | },
325 | "require": {
326 | "php": ">=5.3.3",
327 | "phpunit/php-text-template": ">=1.1.1@stable",
328 | "ext-reflection": "*",
329 | "ext-spl": "*"
330 | },
331 | "suggest": {
332 | "ext-soap": "*"
333 | },
334 | "time": "2012-10-05 00:00:00",
335 | "type": "library",
336 | "installation-source": "dist",
337 | "autoload": {
338 | "classmap": [
339 | "PHPUnit/"
340 | ]
341 | },
342 | "include-path": [
343 | ""
344 | ],
345 | "license": [
346 | "BSD-3-Clause"
347 | ],
348 | "authors": [
349 | {
350 | "name": "Sebastian Bergmann",
351 | "email": "sb@sebastian-bergmann.de",
352 | "role": "lead"
353 | }
354 | ],
355 | "description": "Mock Object library for PHPUnit",
356 | "homepage": "http://www.phpunit.de/",
357 | "keywords": [
358 | "mock",
359 | "xunit"
360 | ]
361 | },
362 | {
363 | "name": "symfony/yaml",
364 | "version": "v2.1.2",
365 | "target-dir": "Symfony/Component/Yaml",
366 | "source": {
367 | "type": "git",
368 | "url": "https://github.com/symfony/Yaml",
369 | "reference": "v2.1.0-RC2"
370 | },
371 | "dist": {
372 | "type": "zip",
373 | "url": "https://github.com/symfony/Yaml/zipball/v2.1.0-RC2",
374 | "reference": "v2.1.0-RC2",
375 | "shasum": ""
376 | },
377 | "require": {
378 | "php": ">=5.3.3"
379 | },
380 | "time": "2012-08-22 13:48:41",
381 | "type": "library",
382 | "extra": {
383 | "branch-alias": {
384 | "dev-master": "2.1-dev"
385 | }
386 | },
387 | "installation-source": "dist",
388 | "autoload": {
389 | "psr-0": {
390 | "Symfony\\Component\\Yaml": ""
391 | }
392 | },
393 | "license": [
394 | "MIT"
395 | ],
396 | "authors": [
397 | {
398 | "name": "Fabien Potencier",
399 | "email": "fabien@symfony.com"
400 | },
401 | {
402 | "name": "Symfony Community",
403 | "homepage": "http://symfony.com/contributors"
404 | }
405 | ],
406 | "description": "Symfony Yaml Component",
407 | "homepage": "http://symfony.com"
408 | }
409 | ],
410 | "aliases": [
411 |
412 | ],
413 | "minimum-stability": "stable",
414 | "stability-flags": [
415 |
416 | ]
417 | }
418 |
--------------------------------------------------------------------------------
/tests/Apache/Solr/DocumentTest.php:
--------------------------------------------------------------------------------
1 |
36 | */
37 |
38 | /**
39 | * Apache_Solr_Document Unit Test
40 | */
41 | class Apache_Solr_DocumentTest extends PHPUnit_Framework_TestCase
42 | {
43 | /**
44 | * Fixture used for testing
45 | *
46 | * @var Apache_Solr_Document
47 | */
48 | private $_fixture;
49 |
50 | /**
51 | * Setup for the fixture before each unit test - part of test case API
52 | */
53 | protected function setup()
54 | {
55 | $this->_fixture = new Apache_Solr_Document();
56 | }
57 |
58 | /**
59 | * Teardown after each unit test - part of test case API
60 | */
61 | protected function tearDown()
62 | {
63 | unset($this->_fixture);
64 | }
65 |
66 | public function testDefaultStateAfterConstructor()
67 | {
68 | // document boost should be false
69 | $this->assertFalse($this->_fixture->getBoost());
70 |
71 | // document fields should be empty
72 | $this->assertEquals(0, count($this->_fixture->getFieldNames()));
73 | $this->assertEquals(0, count($this->_fixture->getFieldValues()));
74 | $this->assertEquals(0, count($this->_fixture->getFieldBoosts()));
75 |
76 | // document iterator should be empty
77 | $this->assertEquals(0, iterator_count($this->_fixture));
78 | }
79 |
80 | public function testSetAndGetField()
81 | {
82 | $field = 'field';
83 | $value = 'value';
84 | $boost = 0.5;
85 |
86 | // set the field
87 | $this->_fixture->setField($field, $value, $boost);
88 |
89 | $result = $this->_fixture->getField($field);
90 |
91 | // check the array values
92 | $this->assertTrue(is_array($result));
93 | $this->assertEquals($field, $result['name']);
94 | $this->assertEquals($value, $result['value']);
95 | $this->assertEquals($boost, $result['boost']);
96 | }
97 |
98 | public function testGetFieldReturnsFalseForNonExistentField()
99 | {
100 | $this->assertFalse($this->_fixture->getField('field'));
101 | }
102 |
103 | public function testMagicGetForFieldValues()
104 | {
105 | $field = 'field';
106 | $value = 'value';
107 |
108 | $this->_fixture->setField($field, $value);
109 |
110 | // test the __get value
111 | $this->assertEquals($value, $this->_fixture->{$field});
112 | }
113 |
114 | /**
115 | * Added for issue #48 (http://code.google.com/p/solr-php-client/issues/detail?id=48)
116 | */
117 | public function testMagicGetReturnsNullForNonExistentField()
118 | {
119 | $this->assertNull($this->_fixture->nonExistent);
120 | }
121 |
122 | public function testMagicSetForFieldValues()
123 | {
124 | $field = 'field';
125 | $value = 'value';
126 |
127 | // set field value with magic __set
128 | $this->_fixture->{$field} = $value;
129 |
130 | $fieldArray = $this->_fixture->getField($field);
131 |
132 | // set values
133 | $this->assertEquals($field, $fieldArray['name']);
134 | $this->assertEquals($value, $fieldArray['value']);
135 | $this->assertTrue($fieldArray['boost'] === false);
136 | }
137 |
138 | public function testMagicIssetForNonExistentField()
139 | {
140 | $this->assertFalse(isset($this->_fixture->field));
141 | }
142 |
143 | public function testMagicIssetForExistingField()
144 | {
145 | $field = 'field';
146 | $this->_fixture->{$field} = 'value';
147 | $this->assertTrue(isset($this->_fixture->{$field}));
148 | }
149 |
150 | public function testMagicUnsetForExistingField()
151 | {
152 | $field = 'field';
153 |
154 | $this->_fixture->{$field} = 'value';
155 |
156 | // now unset the field
157 | unset($this->_fixture->{$field});
158 |
159 | // now test that its unset
160 | $this->assertFalse(isset($this->_fixture->{$field}));
161 | }
162 |
163 | public function testMagicUnsetForNonExistingField()
164 | {
165 | $field = 'field';
166 | unset($this->_fixture->{$field});
167 |
168 | // now test that it still does not exist
169 | $this->assertFalse(isset($this->_fixture->{$field}));
170 | }
171 |
172 | public function testSetAndGetFieldBoostWithPositiveNumberSetsBoost()
173 | {
174 | $field = 'field';
175 | $boost = 0.5;
176 |
177 | $this->_fixture->setFieldBoost($field, $boost);
178 |
179 | // test the field boost
180 | $this->assertEquals($boost, $this->_fixture->getFieldBoost($field));
181 | }
182 |
183 | public function testSetAndGetFieldBoostWithZeroRemovesBoost()
184 | {
185 | $field = 'field';
186 | $boost = 0;
187 |
188 | $this->_fixture->setFieldBoost($field, $boost);
189 |
190 | // test the field boost
191 | $this->assertTrue($this->_fixture->getFieldBoost($field) === false);
192 | }
193 |
194 | public function testSetAndGetFieldBoostWithNegativeNumberRemovesBoost()
195 | {
196 | $field = 'field';
197 | $boost = -1;
198 |
199 | $this->_fixture->setFieldBoost($field, $boost);
200 |
201 | // test the field boost
202 | $this->assertTrue($this->_fixture->getFieldBoost($field) === false);
203 | }
204 |
205 | public function testSetAndGetFieldBoostWithNonNumberRemovesBoost()
206 | {
207 | $field = 'field';
208 | $boost = "i am not a number";
209 |
210 | $this->_fixture->setFieldBoost($field, $boost);
211 |
212 | // test the field boost
213 | $this->assertTrue($this->_fixture->getFieldBoost($field) === false);
214 | }
215 |
216 | public function testSetAndGetBoostWithPositiveNumberSetsBoost()
217 | {
218 | $boost = 0.5;
219 | $this->_fixture->setBoost($boost);
220 |
221 | // the boost should now be set
222 | $this->assertEquals($boost, $this->_fixture->getBoost());
223 | }
224 |
225 | public function testSetAndGetBoostWithZeroRemovesBoost()
226 | {
227 | $this->_fixture->setBoost(0);
228 |
229 | // should be boolean false
230 | $this->assertTrue($this->_fixture->getBoost() === false);
231 | }
232 |
233 | public function testSetAndGetBoostWithNegativeNumberRemovesBoost()
234 | {
235 | $this->_fixture->setBoost(-1);
236 |
237 | // should be boolean false
238 | $this->assertTrue($this->_fixture->getBoost() === false);
239 | }
240 |
241 | public function testSetAndGetBoostWithNonNumberRemovesBoost()
242 | {
243 | $this->_fixture->setBoost("i am not a number");
244 |
245 | // should be boolean false
246 | $this->assertTrue($this->_fixture->getBoost() === false);
247 | }
248 |
249 | public function testAddFieldCreatesMultiValueWhenFieldDoesNotExist()
250 | {
251 | $field = 'field';
252 | $value = 'value';
253 |
254 | $this->_fixture->addField($field, $value);
255 |
256 | // check that value is an array with correct values
257 | $fieldValue = $this->_fixture->{$field};
258 |
259 | $this->assertTrue(is_array($fieldValue));
260 | $this->assertEquals(1, count($fieldValue));
261 | $this->assertEquals($value, $fieldValue[0]);
262 | }
263 |
264 | /**
265 | * setMultiValue has been deprecated and defers to addField
266 | *
267 | * @deprecated
268 | */
269 | public function testSetMultiValueCreateMultiValueWhenFieldDoesNotExist()
270 | {
271 | $field = 'field';
272 | $value = 'value';
273 |
274 | $this->_fixture->setMultiValue($field, $value);
275 |
276 | // check that value is an array with correct values
277 | $fieldValue = $this->_fixture->{$field};
278 |
279 | $this->assertTrue(is_array($fieldValue));
280 | $this->assertEquals(1, count($fieldValue));
281 | $this->assertEquals($value, $fieldValue[0]);
282 | }
283 |
284 | public function testAddFieldCreatesMultiValueWhenFieldDoesExistAsSingleValue()
285 | {
286 | $field = 'field';
287 | $value1 = 'value1';
288 | $value2 = 'value2';
289 |
290 | // set first value as singular value
291 | $this->_fixture->{$field} = $value1;
292 |
293 | // add a second value with addField
294 | $this->_fixture->addField($field, $value2);
295 |
296 | // check that value is an array with correct values
297 | $fieldValue = $this->_fixture->{$field};
298 |
299 | $this->assertTrue(is_array($fieldValue));
300 | $this->assertEquals(2, count($fieldValue));
301 | $this->assertEquals($value1, $fieldValue[0]);
302 | $this->assertEquals($value2, $fieldValue[1]);
303 | }
304 |
305 | /**
306 | * setMultiValue has been deprecated and defers to addField
307 | *
308 | * @deprecated
309 | */
310 | public function testSetMultiValueCreatesMultiValueWhenFieldDoesExistAsSingleValue()
311 | {
312 | $field = 'field';
313 | $value1 = 'value1';
314 | $value2 = 'value2';
315 |
316 | // set first value as singular value
317 | $this->_fixture->{$field} = $value1;
318 |
319 | // add a second value with addField
320 | $this->_fixture->setMultiValue($field, $value2);
321 |
322 | // check that value is an array with correct values
323 | $fieldValue = $this->_fixture->{$field};
324 |
325 | $this->assertTrue(is_array($fieldValue));
326 | $this->assertEquals(2, count($fieldValue));
327 | $this->assertEquals($value1, $fieldValue[0]);
328 | $this->assertEquals($value2, $fieldValue[1]);
329 | }
330 |
331 | public function testAddFieldWithBoostSetsFieldBoost()
332 | {
333 | $field = 'field';
334 | $boost = 0.5;
335 |
336 | $this->_fixture->addField($field, 'value', $boost);
337 |
338 | // check the field boost
339 | $this->assertEquals($boost, $this->_fixture->getFieldBoost($field));
340 | }
341 |
342 | public function testAddFieldWithBoostMultipliesWithAPreexistingBoost()
343 | {
344 | $field = 'field';
345 | $boost = 0.5;
346 |
347 | // set a field with a boost
348 | $this->_fixture->setField($field, 'value1', $boost);
349 |
350 | // now add another value with the same boost
351 | $this->_fixture->addField($field, 'value2', $boost);
352 |
353 | // new boost should be $boost * $boost
354 | $this->assertEquals($boost * $boost, $this->_fixture->getFieldBoost($field));
355 | }
356 |
357 | public function testGetFieldNamesIsInitiallyEmpty()
358 | {
359 | $fieldNames = $this->_fixture->getFieldNames();
360 |
361 | $this->assertTrue(empty($fieldNames));
362 | }
363 |
364 | public function testGetFieldNamesAfterFieldIsSetIsNotEmpty()
365 | {
366 | $field = 'field';
367 |
368 | $this->_fixture->{$field} = 'value';
369 | $fieldNames = $this->_fixture->getFieldNames();
370 |
371 | $this->assertTrue(!empty($fieldNames));
372 | $this->assertEquals(1, count($fieldNames));
373 | $this->assertEquals($field, $fieldNames[0]);
374 | }
375 |
376 | public function testGetFieldValuesIsInitiallyEmpty()
377 | {
378 | $fieldValues = $this->_fixture->getFieldValues();
379 |
380 | $this->assertTrue(empty($fieldValues));
381 | }
382 |
383 | public function testGetFieldValuessAfterFieldIsSetIsNotEmpty()
384 | {
385 | $value = 'value';
386 |
387 | $this->_fixture->field = $value;
388 | $fieldValues = $this->_fixture->getFieldValues();
389 |
390 | $this->assertTrue(!empty($fieldValues));
391 | $this->assertEquals(1, count($fieldValues));
392 | $this->assertEquals($value, $fieldValues[0]);
393 | }
394 |
395 | public function testGetIteratorAfterFieldValueIsSet()
396 | {
397 | $field = 'field';
398 | $value = 'value';
399 |
400 | $this->_fixture->{$field} = $value;
401 |
402 | $itemCount = 0;
403 |
404 | foreach ($this->_fixture as $iteratedField => $iteratedValue)
405 | {
406 | ++$itemCount;
407 |
408 | // test field and value
409 | $this->assertEquals($field, $iteratedField);
410 | $this->assertEquals($value, $iteratedValue);
411 | }
412 |
413 | // test number of iterations is 1
414 | $this->assertEquals(1, $itemCount);
415 | }
416 |
417 | public function testClearReturnsDocumentToDefaultState()
418 | {
419 | // set the document boost
420 | $this->_fixture->setBoost(0.5);
421 |
422 | // set a field
423 | $this->_fixture->someField = "some value";
424 |
425 | // clear the document to remove boost and fields
426 | $this->_fixture->clear();
427 |
428 | // document boost should now be false
429 | $this->assertFalse($this->_fixture->getBoost());
430 |
431 | // document fields should now be empty
432 | $this->assertEquals(0, count($this->_fixture->getFieldNames()));
433 | $this->assertEquals(0, count($this->_fixture->getFieldValues()));
434 | $this->assertEquals(0, count($this->_fixture->getFieldBoosts()));
435 |
436 | // document iterator should now be empty
437 | $this->assertEquals(0, iterator_count($this->_fixture));
438 | }
439 | }
--------------------------------------------------------------------------------
/tests/Apache/Solr/HttpTransport/AbstractTest.php:
--------------------------------------------------------------------------------
1 |
36 | */
37 |
38 | /**
39 | * Apache_Solr_HttpTransport_Abstract Unit Tests
40 | */
41 | abstract class Apache_Solr_HttpTransport_AbstractTest extends PHPUnit_Framework_TestCase
42 | {
43 | const TIMEOUT = 10;
44 |
45 | // request our copyright file from googlecode for GET and HEAD
46 | const GET_URL = "http://reinierkip.nl/echo/";
47 | const GET_RESPONSE_MIME_TYPE = 'application/json';
48 | const GET_RESPONSE_ENCODING = 'UTF-8';
49 | const GET_RESPONSE_MATCH = '{"method":"GET"}';
50 |
51 | // post to the issue list page with a search for 'meh'
52 | const POST_URL = "http://reinierkip.nl/echo/";
53 | const POST_DATA = "ok=true";
54 | const POST_REQUEST_CONTENT_TYPE = 'application/x-www-form-urlencoded; charset=UTF-8';
55 |
56 | const POST_RESPONSE_MIME_TYPE = 'application/json';
57 | const POST_RESPONSE_ENCODING = 'UTF-8';
58 | const POST_RESPONSE_MATCH = '{"method":"POST","data":{"ok":"true"}}';
59 |
60 | abstract public function getFixture();
61 |
62 | public function testGetDefaultTimeoutWithDefaultConstructor()
63 | {
64 | $fixture = $this->getFixture();
65 | $timeout = $fixture->getDefaultTimeout();
66 |
67 | $this->assertGreaterThan(0, $timeout);
68 | }
69 |
70 | public function testGetDefaultTimeoutSetToSixtyForBadValues()
71 | {
72 | // first set our default_socket_timeout ini setting
73 | $previousValue = ini_get('default_socket_timeout');
74 | ini_set('default_socket_timeout', 0);
75 |
76 | $fixture = $this->getFixture();
77 | $timeout = $fixture->getDefaultTimeout();
78 |
79 | // reset timeout
80 | ini_set('default_socket_timeout', $previousValue);
81 |
82 | $this->assertEquals(60, $timeout);
83 | }
84 |
85 | public function testSetDefaultTimeout()
86 | {
87 | $newTimeout = 1234;
88 |
89 | $fixture = $this->getFixture();
90 | $fixture->setDefaultTimeout($newTimeout);
91 | $timeout = $fixture->getDefaultTimeout();
92 |
93 | $this->assertEquals($newTimeout, $timeout);
94 | }
95 |
96 | public function testPerformGetRequest()
97 | {
98 | $fixture = $this->getFixture();
99 | $fixture->setDefaultTimeout(self::TIMEOUT);
100 |
101 | $response = $fixture->performGetRequest(self::GET_URL);
102 |
103 | $this->assertInstanceOf('Apache_Solr_HttpTransport_Response', $response);
104 |
105 | $this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200');
106 | $this->assertEquals(self::GET_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct');
107 | $this->assertEquals(self::GET_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct');
108 | $this->assertStringStartsWith(self::GET_RESPONSE_MATCH, $response->getBody(), 'body did not start with match text');
109 | }
110 |
111 | public function testPerformGetRequestWithTimeout()
112 | {
113 | $fixture = $this->getFixture();
114 | $response = $fixture->performGetRequest(self::GET_URL, self::TIMEOUT);
115 |
116 | $this->assertInstanceOf('Apache_Solr_HttpTransport_Response', $response);
117 |
118 | $this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200');
119 | $this->assertEquals(self::GET_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct');
120 | $this->assertEquals(self::GET_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct');
121 | $this->assertStringStartsWith(self::GET_RESPONSE_MATCH, $response->getBody(), 'body did not start with match text');
122 | }
123 |
124 | public function testPerformHeadRequest()
125 | {
126 | $fixture = $this->getFixture();
127 | $fixture->setDefaultTimeout(self::TIMEOUT);
128 |
129 | $response = $fixture->performHeadRequest(self::GET_URL);
130 |
131 | // we should get everything the same as a get, except the body
132 | $this->assertInstanceOf('Apache_Solr_HttpTransport_Response', $response);
133 |
134 | $this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200');
135 | $this->assertEquals(self::GET_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct');
136 | $this->assertEquals(self::GET_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct');
137 | $this->assertEquals("", $response->getBody(), 'body was not empty');
138 | }
139 |
140 | public function testPerformHeadRequestWithTimeout()
141 | {
142 | $fixture = $this->getFixture();
143 | $response = $fixture->performHeadRequest(self::GET_URL, self::TIMEOUT);
144 |
145 | // we should get everything the same as a get, except the body
146 | $this->assertInstanceOf('Apache_Solr_HttpTransport_Response', $response);
147 |
148 | $this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200');
149 | $this->assertEquals(self::GET_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct');
150 | $this->assertEquals(self::GET_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct');
151 | $this->assertEquals("", $response->getBody(), 'body was not empty');
152 | }
153 |
154 | public function testPerformPostRequest()
155 | {
156 | $fixture = $this->getFixture();
157 | $fixture->setDefaultTimeout(self::TIMEOUT);
158 |
159 | $response = $fixture->performPostRequest(self::POST_URL, self::POST_DATA, self::POST_REQUEST_CONTENT_TYPE);
160 |
161 | $this->assertInstanceOf('Apache_Solr_HttpTransport_Response', $response);
162 |
163 | $this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200');
164 | $this->assertEquals(self::POST_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct');
165 | $this->assertEquals(self::POST_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct');
166 | $this->assertStringStartsWith(self::POST_RESPONSE_MATCH, $response->getBody(), 'body did not start with match text');
167 | }
168 |
169 | public function testPerformPostRequestWithTimeout()
170 | {
171 | $fixture = $this->getFixture();
172 | $response = $fixture->performPostRequest(self::POST_URL, self::POST_DATA, self::POST_REQUEST_CONTENT_TYPE, self::TIMEOUT);
173 |
174 | $this->assertInstanceOf('Apache_Solr_HttpTransport_Response', $response);
175 |
176 | $this->assertEquals(200, $response->getStatusCode(), 'Status code was not 200');
177 | $this->assertEquals(self::POST_RESPONSE_MIME_TYPE, $response->getMimeType(), 'mimetype was not correct');
178 | $this->assertEquals(self::POST_RESPONSE_ENCODING, $response->getEncoding(), 'character encoding was not correct');
179 | $this->assertStringStartsWith(self::POST_RESPONSE_MATCH, $response->getBody(), 'body did not start with match text');
180 | }
181 |
182 | /**
183 | * Test one session doing multiple requests in multiple orders
184 | */
185 | public function testMultipleRequests()
186 | {
187 | // initial get request
188 | $this->testPerformGetRequest();
189 |
190 | // head following get
191 | $this->testPerformHeadRequest();
192 |
193 | // post following head
194 | $this->testPerformPostRequest();
195 |
196 | // get following post
197 | $this->testPerformGetRequest();
198 |
199 | // post following get
200 | $this->testPerformPostRequest();
201 |
202 | // head following post
203 | $this->testPerformHeadRequest();
204 |
205 | // get following post
206 | $this->testPerformGetRequest();
207 | }
208 | }
--------------------------------------------------------------------------------
/tests/Apache/Solr/HttpTransport/CurlNoReuseTest.php:
--------------------------------------------------------------------------------
1 |
36 | */
37 |
38 | /**
39 | * Apache_Solr_HttpTransport_CurlNoReuse Unit Tests
40 | */
41 | class Apache_Solr_HttpTransport_CurlNoReuseTest extends Apache_Solr_HttpTransport_AbstractTest
42 | {
43 | public function getFixture()
44 | {
45 | // ensure curl is enabled
46 | if (!extension_loaded('curl'))
47 | {
48 | $this->markTestSkipped("curl module is not enabled");
49 | }
50 |
51 | return new Apache_Solr_HttpTransport_CurlNoReuse();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/tests/Apache/Solr/HttpTransport/CurlTest.php:
--------------------------------------------------------------------------------
1 |
36 | */
37 |
38 | /**
39 | * Apache_Solr_HttpTransport_Curl Unit Tests
40 | */
41 | class Apache_Solr_HttpTransport_CurlTest extends Apache_Solr_HttpTransport_AbstractTest
42 | {
43 | public function getFixture()
44 | {
45 | // ensure curl is enabled
46 | if (!extension_loaded('curl'))
47 | {
48 | $this->markTestSkipped("curl module is not enabled");
49 | }
50 |
51 | return new Apache_Solr_HttpTransport_Curl();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/tests/Apache/Solr/HttpTransport/FileGetContentsTest.php:
--------------------------------------------------------------------------------
1 |
36 | */
37 |
38 | /**
39 | * Apache_Solr_HttpTransport_FileGetContents Unit Tests
40 | */
41 | class Apache_Solr_HttpTransport_FileGetContentsTest extends Apache_Solr_HttpTransport_AbstractTest
42 | {
43 | public function getFixture()
44 | {
45 | // make sure allow_url_fopen is on
46 | if (!ini_get("allow_url_fopen"))
47 | {
48 | $this->markTestSkipped("allow_url_fopen is not enabled");
49 | }
50 |
51 | return new Apache_Solr_HttpTransport_FileGetContents();
52 | }
53 | }
--------------------------------------------------------------------------------
/tests/Apache/Solr/HttpTransport/ResponseTest.php:
--------------------------------------------------------------------------------
1 |
36 | */
37 |
38 | /**
39 | * Apache_Solr_HttpTransport_Response Unit Tests
40 | */
41 | class Apache_Solr_HttpTransport_ResponseTest extends PHPUnit_Framework_TestCase
42 | {
43 | // generated with the following query string: select?q=solr&wt=json
44 | const STATUS_CODE_200 = 200;
45 | const STATUS_MESSAGE_200 = "OK";
46 | const BODY_200 = '{"responseHeader":{"status":0,"QTime":0,"params":{"q":"solr","wt":"json"}},"response":{"numFound":0,"start":0,"docs":[]}}';
47 | const BODY_200_WITH_DOCUMENTS = '{"responseHeader":{"status":0,"QTime":0,"params":{"q":"*:*","wt":"json"}},"response":{"numFound":1,"start":0,"docs":[{"guid":"dev/2/products/45410/1236981","cit_domain":"products","cit_client":"2","cit_instance":"dev","cit_timestamp":"2010-10-06T18:16:51.573Z","product_code_t":["235784"],"product_id":[1236981],"dealer_id":[45410],"category_id":[1030],"manufacturer_id":[0],"vendor_id":[472],"catalog_id":[202]}]}}';
48 | const CONTENT_TYPE_200 = "text/plain; charset=utf-8";
49 | const MIME_TYPE_200 = "text/plain";
50 | const ENCODING_200 = "utf-8";
51 |
52 | // generated with the following query string: select?qt=standad&q=solr&wt=json
53 | // NOTE: the intentional mispelling of the standard in the qt parameter
54 | const STATUS_CODE_400 = 400;
55 | const STATUS_MESSAGE_400 = "Bad Request";
56 | const BODY_400 = 'Apache Tomcat/6.0.24 - Error report HTTP Status 400 - unknown handler: standad
type Status report
message unknown handler: standad
description The request sent by the client was syntactically incorrect (unknown handler: standad).
Apache Tomcat/6.0.24
';
57 | const CONTENT_TYPE_400 = "text/html; charset=utf-8";
58 | const MIME_TYPE_400 = "text/html";
59 | const ENCODING_400 = "utf-8";
60 |
61 | // generated with the following query string: select?q=solr&wt=json on a core that does not exist
62 | const STATUS_CODE_404 = 404;
63 | const STATUS_MESSAGE_404 = "Not Found";
64 | const BODY_404 = 'Apache Tomcat/6.0.24 - Error report HTTP Status 404 - /solr/doesnotexist/select
type Status report
message /solr/doesnotexist/select
description The requested resource (/solr/doesnotexist/select) is not available.
Apache Tomcat/6.0.24
';
65 | const CONTENT_TYPE_404 = "text/html; charset=utf-8";
66 | const MIME_TYPE_404 = "text/html";
67 | const ENCODING_404 = "utf-8";
68 |
69 | public static function get0Response()
70 | {
71 | return new Apache_Solr_HttpTransport_Response(null, null, null);
72 | }
73 |
74 | public static function get200Response()
75 | {
76 | return new Apache_Solr_HttpTransport_Response(self::STATUS_CODE_200, self::CONTENT_TYPE_200, self::BODY_200);
77 | }
78 |
79 | public static function get200ResponseWithDocuments()
80 | {
81 | return new Apache_Solr_HttpTransport_Response(self::STATUS_CODE_200, self::CONTENT_TYPE_200, self::BODY_200_WITH_DOCUMENTS);
82 | }
83 |
84 | public static function get400Response()
85 | {
86 | return new Apache_Solr_HttpTransport_Response(self::STATUS_CODE_400, self::CONTENT_TYPE_400, self::BODY_400);
87 | }
88 |
89 | public static function get404Response()
90 | {
91 | return new Apache_Solr_HttpTransport_Response(self::STATUS_CODE_404, self::CONTENT_TYPE_404, self::BODY_404);
92 | }
93 |
94 | public function testGetStatusCode()
95 | {
96 | $fixture = self::get200Response();
97 |
98 | $statusCode = $fixture->getStatusCode();
99 |
100 | $this->assertEquals(self::STATUS_CODE_200, $statusCode);
101 | }
102 |
103 | public function testGetStatusMessage()
104 | {
105 | $fixture = self::get200Response();
106 |
107 | $statusMessage = $fixture->getStatusMessage();
108 |
109 | $this->assertEquals(self::STATUS_MESSAGE_200, $statusMessage);
110 | }
111 |
112 | public function testGetStatusMessageWithUnknownCode()
113 | {
114 | $fixture = new Apache_Solr_HttpTransport_Response(499, null, null);
115 |
116 | $statusMessage = $fixture->getStatusMessage();
117 | $this->assertEquals("Unknown Status", $statusMessage);
118 | }
119 |
120 | public function testGetBody()
121 | {
122 | $fixture = self::get200Response();
123 |
124 | $body = $fixture->getBody();
125 |
126 | $this->assertEquals(self::BODY_200, $body);
127 | }
128 |
129 | public function testGetMimeType()
130 | {
131 | $fixture = self::get200Response();
132 |
133 | $mimeType = $fixture->getMimeType();
134 |
135 | $this->assertEquals(self::MIME_TYPE_200, $mimeType);
136 | }
137 |
138 | public function testGetEncoding()
139 | {
140 | $fixture = self::get200Response();
141 |
142 | $encoding = $fixture->getEncoding();
143 |
144 | $this->assertEquals(self::ENCODING_200, $encoding);
145 | }
146 |
147 | public function testGetStatusMessageWhenNotProvided()
148 | {
149 | // test 4 of the most common status code responses, probably don't need
150 | // to test all the codes we have
151 |
152 | $fixture = new Apache_Solr_HttpTransport_Response(null, null, null, null, null);
153 | $this->assertEquals("Communication Error", $fixture->getStatusMessage(), 'Did not get correct default status message for status code 0');
154 |
155 | $fixture = new Apache_Solr_HttpTransport_Response(200, null, null, null, null);
156 | $this->assertEquals("OK", $fixture->getStatusMessage(), 'Did not get correct default status message for status code 200');
157 |
158 | $fixture = new Apache_Solr_HttpTransport_Response(400, null, null, null, null);
159 | $this->assertEquals("Bad Request", $fixture->getStatusMessage(), 'Did not get correct default status message for status code 400');
160 |
161 | $fixture = new Apache_Solr_HttpTransport_Response(404, null, null, null, null);
162 | $this->assertEquals("Not Found", $fixture->getStatusMessage(), 'Did not get correct default status message for status code 404');
163 | }
164 | }
165 |
--------------------------------------------------------------------------------
/tests/Apache/Solr/HttpTransportExceptionTest.php:
--------------------------------------------------------------------------------
1 |
36 | */
37 |
38 | /**
39 | * Apache_Solr_HttpTransportException Unit Tests
40 | */
41 | class Apache_Solr_HttpTransportExceptionTest extends PHPUnit_Framework_TestCase
42 | {
43 | /**
44 | * @expectedException PHPUnit_Framework_Error
45 | */
46 | public function testConstructorRequiresResponse()
47 | {
48 | $fixture = new Apache_Solr_HttpTransportException();
49 | }
50 |
51 | public function testGetResponse()
52 | {
53 | $response = Apache_Solr_ResponseTest::get0Response();
54 | $fixture = new Apache_Solr_HttpTransportException($response);
55 |
56 | $this->assertEquals($response, $fixture->getResponse());
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/tests/Apache/Solr/ResponseTest.php:
--------------------------------------------------------------------------------
1 |
36 | */
37 |
38 | /**
39 | * Apache_Solr_Response Unit Test
40 | */
41 | class Apache_Solr_ResponseTest extends PHPUnit_Framework_TestCase
42 | {
43 | static public function get0Response($createDocuments = true, $collapseSingleValueArrays = true)
44 | {
45 | return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get0Response(), $createDocuments, $collapseSingleValueArrays);
46 | }
47 |
48 | static public function get200Response($createDocuments = true, $collapseSingleValueArrays = true)
49 | {
50 | return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get200Response(), $createDocuments, $collapseSingleValueArrays);
51 | }
52 |
53 | static public function get200ResponseWithDocuments($createDocuments = true, $collapseSingleValueArrays = true)
54 | {
55 | return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get200ResponseWithDocuments(), $createDocuments, $collapseSingleValueArrays);
56 | }
57 |
58 | static public function get400Response($createDocuments = true, $collapseSingleValueArrays = true)
59 | {
60 | return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get400Response(), $createDocuments, $collapseSingleValueArrays);
61 | }
62 |
63 | static public function get404Response($createDocuments = true, $collapseSingleValueArrays = true)
64 | {
65 | return new Apache_Solr_Response(Apache_Solr_HttpTransport_ResponseTest::get404Response(), $createDocuments, $collapseSingleValueArrays);
66 | }
67 |
68 | public function testConstuctorWithValidBodyAndHeaders()
69 | {
70 | $fixture = self::get200Response();
71 |
72 | // check that we parsed the HTTP status correctly
73 | $this->assertEquals(Apache_Solr_HttpTransport_ResponseTest::STATUS_CODE_200, $fixture->getHttpStatus());
74 |
75 | // check that we received the body correctly
76 | $this->assertEquals(Apache_Solr_HttpTransport_ResponseTest::BODY_200, $fixture->getRawResponse());
77 |
78 | // check that our defaults are correct
79 | $this->assertEquals(Apache_Solr_HttpTransport_ResponseTest::ENCODING_200, $fixture->getEncoding());
80 | $this->assertEquals(Apache_Solr_HttpTransport_ResponseTest::MIME_TYPE_200, $fixture->getType());
81 | }
82 |
83 | public function testConstructorWithBadBodyAndHeaders()
84 | {
85 | $fixture = self::get0Response();
86 |
87 | // check that our defaults are correct
88 | $this->assertEquals(0, $fixture->getHttpStatus());
89 | $this->assertEquals("UTF-8", $fixture->getEncoding());
90 | $this->assertEquals("text/plain", $fixture->getType());
91 | }
92 |
93 | public function testMagicGetWithValidBodyAndHeaders()
94 | {
95 | $fixture = self::get200Response();
96 |
97 | // test top level gets
98 | $this->assertInstanceOf('stdClass', $fixture->responseHeader);
99 | $this->assertEquals(0, $fixture->responseHeader->status);
100 | $this->assertEquals(0, $fixture->responseHeader->QTime);
101 |
102 | $this->assertInstanceOf('stdClass', $fixture->response);
103 | $this->assertEquals(0, $fixture->response->numFound);
104 |
105 | $this->assertTrue(is_array($fixture->response->docs));
106 | $this->assertEquals(0, count($fixture->response->docs));
107 | }
108 |
109 | /**
110 | * @expectedException Apache_Solr_ParserException
111 | */
112 | public function testMagicGetWith0Response()
113 | {
114 | $fixture = self::get0Response();
115 |
116 | // attempting to magic get a part of the response
117 | // should throw a ParserException
118 | $fixture->responseHeader;
119 |
120 | $this->fail("Expected Apache_Solr_ParserException was not raised");
121 | }
122 |
123 | /**
124 | * @expectedException Apache_Solr_ParserException
125 | */
126 | public function testMagicGetWith400Response()
127 | {
128 | $fixture = self::get400Response();
129 |
130 | // attempting to magic get a part of the response
131 | // should throw a ParserException
132 | $fixture->responseHeader;
133 |
134 | $this->fail("Expected Apache_Solr_ParserException was not raised");
135 | }
136 |
137 | /**
138 | * @expectedException Apache_Solr_ParserException
139 | */
140 | public function testMagicGetWith404Response()
141 | {
142 | $fixture = self::get404Response();
143 |
144 | // attempting to magic get a part of the response
145 | // should throw a ParserException
146 | $fixture->responseHeader;
147 |
148 | $this->fail("Expected Apache_Solr_ParserException was not raised");
149 | }
150 |
151 | public function testCreateDocuments()
152 | {
153 | $fixture = self::get200ResponseWithDocuments();
154 |
155 | $this->assertTrue(count($fixture->response->docs) > 0, 'There are not 1 or more documents, cannot test');
156 | $this->assertInstanceOf('Apache_Solr_Document', $fixture->response->docs[0], 'The first document is not of type Apache_Solr_Document');
157 | }
158 |
159 | public function testDontCreateDocuments()
160 | {
161 | $fixture = self::get200ResponseWithDocuments(false);
162 |
163 | $this->assertTrue(count($fixture->response->docs) > 0, 'There are not 1 or more documents, cannot test');
164 | $this->assertInstanceOf('stdClass', $fixture->response->docs[0], 'The first document is not of type stdClass');
165 | }
166 |
167 | public function testGetHttpStatusMessage()
168 | {
169 | $fixture = self::get200Response();
170 |
171 | $this->assertEquals("OK", $fixture->getHttpStatusMessage());
172 | }
173 |
174 | public function testMagicGetReturnsNullForUndefinedData()
175 | {
176 | $fixture = self::get200Response();
177 |
178 | $this->assertNull($fixture->doesnotexist);
179 | }
180 |
181 | public function testMagicIssetForDefinedProperty()
182 | {
183 | $fixture = self::get200Response();
184 |
185 | $this->assertTrue(isset($fixture->responseHeader));
186 | }
187 |
188 | public function testMagicIssetForUndefinedProperty()
189 | {
190 | $fixture = self::get200Response();
191 |
192 | $this->assertFalse(isset($fixture->doesnotexist));
193 | }
194 | }
195 |
--------------------------------------------------------------------------------
/tests/Apache/Solr/Service/BalancerTest.php:
--------------------------------------------------------------------------------
1 |
36 | */
37 |
38 | /**
39 | * Apache_Solr_Service_Balancer Unit Tests
40 | */
41 | class Apache_Solr_Service_BalancerTest extends Apache_Solr_ServiceAbstractTest
42 | {
43 | public function getFixture()
44 | {
45 | return new Apache_Solr_Service_Balancer();
46 | }
47 | }
--------------------------------------------------------------------------------
/tests/Apache/Solr/ServiceAbstractTest.php:
--------------------------------------------------------------------------------
1 |
36 | */
37 |
38 | /**
39 | * Provides base funcationality test for both Apache_Solr_Service and the
40 | * Apache_Solr_Service_Balancer classes.
41 | */
42 | abstract class Apache_Solr_ServiceAbstractTest extends PHPUnit_Framework_TestCase
43 | {
44 | /**
45 | * Method that gets the appropriate instance for testing
46 | */
47 | abstract public function getFixture();
48 |
49 | /**
50 | * @dataProvider testEscapeDataProvider
51 | */
52 | public function testEscape($input, $expectedOutput)
53 | {
54 | $fixture = $this->getFixture();
55 |
56 | $this->assertEquals($expectedOutput, $fixture->escape($input));
57 | }
58 |
59 | public function testEscapeDataProvider()
60 | {
61 | return array(
62 | array(
63 | "I should look the same",
64 | "I should look the same"
65 | ),
66 |
67 | array(
68 | "(There) are: ^lots \\ && of spec!al charaters",
69 | "\\(There\\) are\\: \\^lots \\\\ \\&& of spec\\!al charaters"
70 | )
71 | );
72 | }
73 |
74 | /**
75 | * @dataProvider testEscapePhraseDataProvider
76 | */
77 | public function testEscapePhrase($input, $expectedOutput)
78 | {
79 | $fixture = $this->getFixture();
80 |
81 | $this->assertEquals($expectedOutput, $fixture->escapePhrase($input));
82 | }
83 |
84 | public function testEscapePhraseDataProvider()
85 | {
86 | return array(
87 | array(
88 | "I'm a simple phrase",
89 | "I'm a simple phrase"
90 | ),
91 |
92 | array(
93 | "I have \"phrase\" characters",
94 | 'I have \\"phrase\\" characters'
95 | )
96 | );
97 | }
98 |
99 | /**
100 | * @dataProvider testPhraseDataProvider
101 | */
102 | public function testPhrase($input, $expectedOutput)
103 | {
104 | $fixture = $this->getFixture();
105 |
106 | $this->assertEquals($expectedOutput, $fixture->phrase($input));
107 | }
108 |
109 | public function testPhraseDataProvider()
110 | {
111 | return array(
112 | array(
113 | "I'm a simple phrase",
114 | '"I\'m a simple phrase"'
115 | ),
116 |
117 | array(
118 | "I have \"phrase\" characters",
119 | '"I have \\"phrase\\" characters"'
120 | )
121 | );
122 | }
123 |
124 | public function testGetCreateDocumentWithDefaultConstructor()
125 | {
126 | $fixture = $this->getFixture();
127 |
128 | $this->assertTrue($fixture->getCreateDocuments());
129 | }
130 |
131 | public function testSetCreateDocuments()
132 | {
133 | $fixture = $this->getFixture();
134 |
135 | $fixture->setCreateDocuments(false);
136 |
137 | $this->assertFalse($fixture->getCreateDocuments());
138 | }
139 | }
--------------------------------------------------------------------------------
/tests/README:
--------------------------------------------------------------------------------
1 | Use the run.php script included in this directory to run all unit tests for the
2 | Solr PHP Client library. Your system will require phpunit PEAR package - which
3 | you can get install instructions for at:
4 |
5 | http://www.phpunit.de/
6 |
7 | To generate the code coverage report, you will also need the XDebug pecl package
8 | installed, typically this can be done with a simple:
9 |
10 | pecl install xdebug
11 |
12 | If you need more information on installation, then please see the official website:
13 |
14 | http://www.xdebug.org
15 |
16 | The scripts, configuration, and test files in this directory have been confirmed to
17 | work with the following versions:
18 |
19 | phpunit: 3.3.16
20 | xdebug: 2.0.4
--------------------------------------------------------------------------------
/tests/phpunit.bootstrap.inc:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | ../Apache
10 |
11 | ./run.php
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------