Commit 3f5b7ddf authored by Dorian Villet's avatar Dorian Villet

Fixing tests.

parent 1978f2cb
......@@ -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()
{
......
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment