Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
3f5b7ddf
Commit
3f5b7ddf
authored
Sep 11, 2013
by
Dorian Villet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing tests.
parent
1978f2cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
14 deletions
+33
-14
library/Solarium/QueryType/Analysis/Query/Document.php
library/Solarium/QueryType/Analysis/Query/Document.php
+19
-11
tests/Solarium/Tests/QueryType/Update/Query/Command/AddTest.php
...Solarium/Tests/QueryType/Update/Query/Command/AddTest.php
+14
-3
No files found.
library/Solarium/QueryType/Analysis/Query/Document.php
View file @
3f5b7ddf
...
...
@@ -42,17 +42,18 @@ use Solarium\Exception\RuntimeException;
use
Solarium\QueryType\Analysis\ResponseParser\Document
as
ResponseParser
;
use
Solarium\QueryType\Analysis\RequestBuilder\Document
as
RequestBuilder
;
use
Solarium\QueryType\Select\Result\DocumentInterface
;
use
Solarium\QueryType\Update\Query\Document\DocumentInterface
as
UpdateDocumentInterface
;
/**
* Analysis document query
*/
class
Document
extends
Query
implements
DocumentInterface
class
Document
extends
Query
{
/**
* Documents to analyze
*
* @var DocumentInterface[]
* @var
self[]|
DocumentInterface[]
*/
protected
$documents
=
array
();
...
...
@@ -100,10 +101,11 @@ class Document extends Query implements DocumentInterface
/**
* Add a single document
*
* @param DocumentInterface $document
* @return self Provides fluent interface
*
* @param self|DocumentInterface $document
* @return self Provides fluent interface
*/
public
function
addDocument
(
DocumentInterface
$document
)
public
function
addDocument
(
$document
)
{
$this
->
documents
[]
=
$document
;
...
...
@@ -113,15 +115,21 @@ class Document extends Query implements DocumentInterface
/**
* Add multiple documents
*
* @param DocumentInterface[] $documents
* @return self Provides fluent interface
* @throws RuntimeException If any of the given documents does not implement DocumentInterface
* @param
self|
DocumentInterface[] $documents
* @return self
Provides fluent interface
* @throws RuntimeException
If any of the given documents does not implement DocumentInterface
*/
public
function
addDocuments
(
$documents
)
{
foreach
(
$documents
as
$document
)
{
if
(
!
(
$document
instanceof
DocumentInterface
))
{
throw
new
RuntimeException
(
'Documents must implement DocumentInterface.'
);
if
(
!
(
$document
instanceof
$this
)
&&
!
(
$document
instanceof
DocumentInterface
)
&&
!
(
$document
instanceof
UpdateDocumentInterface
)
)
{
throw
new
RuntimeException
(
'Documents must either implement one of the DocumentInterface or be an instance of '
.
get_called_class
()
);
}
}
...
...
@@ -133,7 +141,7 @@ class Document extends Query implements DocumentInterface
/**
* Get all documents
*
* @return DocumentInterface[]
* @return
self[]|
DocumentInterface[]
*/
public
function
getDocuments
()
{
...
...
tests/Solarium/Tests/QueryType/Update/Query/Command/AddTest.php
View file @
3f5b7ddf
...
...
@@ -63,9 +63,20 @@ class AddTest extends \PHPUnit_Framework_TestCase
public
function
testAddDocumentWithInvalidDocument
()
{
$doc
=
new
\StdClass
();
$this
->
setExpectedException
(
'Solarium\Exception\RuntimeException'
);
$this
->
command
->
addDocument
(
$doc
);
try
{
$doc
=
new
\StdClass
();
$this
->
command
->
addDocument
(
$doc
);
$this
->
fail
(
'The addDocument() method should not accept anything else than DocumentInterface instances.'
);
}
catch
(
\PHPUnit_Framework_Error
$e
)
{
$this
->
assertContains
(
'Argument 1 passed to '
.
get_class
(
$this
->
command
)
.
'::addDocument() must implement interface '
.
'Solarium\QueryType\Update\Query\Document\DocumentInterface, instance of stdClass given'
,
$e
->
getMessage
()
);
}
}
public
function
testAddDocuments
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment