Commit 6af1b2da authored by Robin Kunde's avatar Robin Kunde

rewrote tests that inherited from other tests by moved shared functionality to...

rewrote tests that inherited from other tests by moved shared functionality to abstract base test classes
parent a9d8a52b
...@@ -33,9 +33,9 @@ namespace Solarium\Tests\Plugin\MinimumScoreFilter; ...@@ -33,9 +33,9 @@ namespace Solarium\Tests\Plugin\MinimumScoreFilter;
use Solarium\QueryType\Select\Result\Document; use Solarium\QueryType\Select\Result\Document;
use Solarium\Plugin\MinimumScoreFilter\Document as FilterDocument; use Solarium\Plugin\MinimumScoreFilter\Document as FilterDocument;
use Solarium\Tests\QueryType\Select\Result\DocumentTest as SelectDocumentTest; use Solarium\Tests\QueryType\Select\Result\AbstractDocumentTest;
class DocumentTest extends SelectDocumentTest class DocumentTest extends AbstractDocumentTest
{ {
protected function setUp() protected function setUp()
{ {
......
...@@ -32,11 +32,10 @@ ...@@ -32,11 +32,10 @@
namespace Solarium\Tests\Plugin\MinimumScoreFilter; namespace Solarium\Tests\Plugin\MinimumScoreFilter;
use Solarium\Plugin\MinimumScoreFilter\Query; use Solarium\Plugin\MinimumScoreFilter\Query;
use Solarium\Tests\QueryType\Select\Query\QueryTest as SelectQueryTest; use Solarium\Tests\QueryType\Select\Query\AbstractQueryTest;
class QueryTest extends SelectQueryTest class QueryTest extends AbstractQueryTest
{ {
public function setUp() public function setUp()
{ {
$this->query = new Query; $this->query = new Query;
......
...@@ -34,9 +34,9 @@ namespace Solarium\Tests\Plugin\MinimumScoreFilter; ...@@ -34,9 +34,9 @@ namespace Solarium\Tests\Plugin\MinimumScoreFilter;
use Solarium\Plugin\MinimumScoreFilter\Query; use Solarium\Plugin\MinimumScoreFilter\Query;
use Solarium\Plugin\MinimumScoreFilter\Result; use Solarium\Plugin\MinimumScoreFilter\Result;
use Solarium\QueryType\Select\Result\Document; use Solarium\QueryType\Select\Result\Document;
use Solarium\Tests\QueryType\Select\Result\ResultTest as SelectResultTest; use Solarium\Tests\QueryType\Select\Result\AbstractResultTest;
class ResultTest extends SelectResultTest class ResultTest extends AbstractResultTest
{ {
public function setUp() public function setUp()
{ {
......
...@@ -31,10 +31,10 @@ ...@@ -31,10 +31,10 @@
namespace Solarium\Tests\QueryType\Extract; namespace Solarium\Tests\QueryType\Extract;
use Solarium\Tests\QueryType\Update\ResultTest as UpdateResultTest;
use Solarium\QueryType\Extract\Result as ExtractResult; use Solarium\QueryType\Extract\Result as ExtractResult;
use Solarium\Tests\QueryType\Update\AbstractResultTest;
class ResultTest extends UpdateResultTest class ResultTest extends AbstractResultTest
{ {
public function setUp() public function setUp()
{ {
......
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Select\Result;
abstract class AbstractDocumentTest extends \PHPUnit_Framework_TestCase
{
protected $doc;
protected $fields = array(
'id' => 123,
'name' => 'Test document',
'categories' => array(1, 2, 3),
'empty_field' => '',
);
public function testGetFields()
{
$this->assertEquals($this->fields, $this->doc->getFields());
}
public function testGetFieldAsProperty()
{
$this->assertEquals(
$this->fields['categories'],
$this->doc->categories
);
$this->assertEquals(
null,
$this->doc->invalidfieldname
);
}
public function testSetField()
{
$this->setExpectedException('Solarium\Exception\RuntimeException');
$this->doc->newField = 'new value';
}
public function testIterator()
{
$fields = array();
foreach ($this->doc as $key => $field) {
$fields[$key] = $field;
}
$this->assertEquals($this->fields, $fields);
}
public function testArrayGet()
{
$this->assertEquals(
$this->fields['categories'],
$this->doc['categories']
);
$this->assertEquals(
null,
$this->doc['invalidfieldname']
);
}
public function testArrayIsset()
{
$this->assertTrue(
isset($this->doc['categories'])
);
$this->assertFalse(
isset($this->doc['invalidfieldname'])
);
}
public function testArrayEmpty()
{
$this->assertTrue(
empty($this->doc['empty_field'])
);
$this->assertFalse(
empty($this->doc['categories'])
);
}
public function testArraySet()
{
$this->setExpectedException('Solarium\Exception\RuntimeException');
$this->doc['newField'] = 'new value';
}
public function testArrayUnset()
{
$this->setExpectedException('Solarium\Exception\RuntimeException');
unset($this->doc['newField']);
}
public function testCount()
{
$this->assertEquals(count($this->fields), count($this->doc));
}
}
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Select\Result;
use Solarium\QueryType\Select\Result\Document;
use Solarium\QueryType\Select\Query\Query;
use Solarium\QueryType\Select\Result\Result;
abstract class AbstractResultTest extends \PHPUnit_Framework_TestCase
{
/**
* @var SelectDummy
*/
protected $result;
protected $numFound;
protected $maxScore;
protected $docs;
protected $components;
protected $facetSet;
protected $moreLikeThis;
protected $highlighting;
protected $grouping;
protected $stats;
protected $debug;
protected $spellcheck;
public function setUp()
{
$this->numFound = 11;
$this->maxScore = 0.91;
$this->docs = array(
new Document(array('id'=>1, 'title'=>'doc1')),
new Document(array('id'=>1, 'title'=>'doc1')),
);
$this->facetSet = 'dummy-facetset-value';
$this->moreLikeThis = 'dummy-facetset-value';
$this->highlighting = 'dummy-highlighting-value';
$this->grouping = 'dummy-grouping-value';
$this->spellcheck = 'dummy-grouping-value';
$this->stats = 'dummy-stats-value';
$this->debug = 'dummy-debug-value';
$this->components = array(
Query::COMPONENT_FACETSET => $this->facetSet,
Query::COMPONENT_MORELIKETHIS => $this->moreLikeThis,
Query::COMPONENT_HIGHLIGHTING => $this->highlighting,
Query::COMPONENT_GROUPING => $this->grouping,
Query::COMPONENT_SPELLCHECK => $this->spellcheck,
Query::COMPONENT_STATS => $this->stats,
Query::COMPONENT_DEBUG => $this->debug,
);
$this->result = new SelectDummy(1, 12, $this->numFound, $this->maxScore, $this->docs, $this->components);
}
public function testGetNumFound()
{
$this->assertEquals($this->numFound, $this->result->getNumFound());
}
public function testGetMaxScore()
{
$this->assertEquals($this->maxScore, $this->result->getMaxScore());
}
public function testGetDocuments()
{
$this->assertEquals($this->docs, $this->result->getDocuments());
}
public function testGetFacetSet()
{
$this->assertEquals($this->facetSet, $this->result->getFacetSet());
}
public function testCount()
{
$this->assertEquals(count($this->docs), count($this->result));
}
public function testGetComponents()
{
$this->assertEquals($this->components, $this->result->getComponents());
}
public function testGetComponent()
{
$this->assertEquals(
$this->components[Query::COMPONENT_MORELIKETHIS],
$this->result->getComponent(Query::COMPONENT_MORELIKETHIS)
);
}
public function testGetInvalidComponent()
{
$this->assertEquals(
null,
$this->result->getComponent('invalid')
);
}
public function testGetMoreLikeThis()
{
$this->assertEquals(
$this->components[Query::COMPONENT_MORELIKETHIS],
$this->result->getMoreLikeThis()
);
}
public function testGetHighlighting()
{
$this->assertEquals(
$this->components[Query::COMPONENT_HIGHLIGHTING],
$this->result->getHighlighting()
);
}
public function testGetGrouping()
{
$this->assertEquals(
$this->components[Query::COMPONENT_GROUPING],
$this->result->getGrouping()
);
}
public function testGetSpellcheck()
{
$this->assertEquals(
$this->components[Query::COMPONENT_SPELLCHECK],
$this->result->getSpellcheck()
);
}
public function testGetStats()
{
$this->assertEquals(
$this->components[Query::COMPONENT_STATS],
$this->result->getStats()
);
}
public function testGetDebug()
{
$this->assertEquals(
$this->components[Query::COMPONENT_DEBUG],
$this->result->getDebug()
);
}
public function testIterator()
{
$docs = array();
foreach ($this->result as $key => $doc) {
$docs[$key] = $doc;
}
$this->assertEquals($this->docs, $docs);
}
public function testGetStatus()
{
$this->assertEquals(
1,
$this->result->getStatus()
);
}
public function testGetQueryTime()
{
$this->assertEquals(
12,
$this->result->getQueryTime()
);
}
}
class SelectDummy extends Result
{
protected $parsed = true;
public function __construct($status, $queryTime, $numfound, $maxscore, $docs, $components)
{
$this->numfound = $numfound;
$this->maxscore = $maxscore;
$this->documents = $docs;
$this->components = $components;
$this->queryTime = $queryTime;
$this->status = $status;
}
}
...@@ -33,102 +33,10 @@ namespace Solarium\Tests\QueryType\Select\Result; ...@@ -33,102 +33,10 @@ namespace Solarium\Tests\QueryType\Select\Result;
use Solarium\QueryType\Select\Result\Document; use Solarium\QueryType\Select\Result\Document;
class DocumentTest extends \PHPUnit_Framework_TestCase class DocumentTest extends AbstractDocumentTest
{ {
protected $doc;
protected $fields = array(
'id' => 123,
'name' => 'Test document',
'categories' => array(1, 2, 3)
);
protected function setUp() protected function setUp()
{ {
$this->doc = new Document($this->fields); $this->doc = new Document($this->fields);
} }
public function testGetFields()
{
$this->assertEquals($this->fields, $this->doc->getFields());
}
public function testGetFieldAsProperty()
{
$this->assertEquals(
$this->fields['categories'],
$this->doc->categories
);
}
public function testGetInvalidFieldAsProperty()
{
$this->assertEquals(
null,
$this->doc->invalidfieldname
);
}
public function testSetField()
{
$this->setExpectedException('Solarium\Exception\RuntimeException');
$this->doc->newField = 'new value';
}
public function testIterator()
{
$fields = array();
foreach ($this->doc as $key => $field) {
$fields[$key] = $field;
}
$this->assertEquals($this->fields, $fields);
}
public function testArrayGet()
{
$this->assertEquals(
$this->fields['categories'],
$this->doc['categories']
);
}
public function testArrayGetInvalidField()
{
$this->assertEquals(
null,
$this->doc['invalidfield']
);
}
public function testArrayIsset()
{
$this->assertTrue(
isset($this->doc['categories'])
);
}
public function testArrayIssetInvalidField()
{
$this->assertFalse(
isset($this->doc['invalidfield'])
);
}
public function testArraySet()
{
$this->setExpectedException('Solarium\Exception\RuntimeException');
$this->doc['newField'] = 'new value';
}
public function testArrayUnset()
{
$this->setExpectedException('Solarium\Exception\RuntimeException');
unset($this->doc['newField']);
}
public function testCount()
{
$this->assertEquals(count($this->fields), count($this->doc));
}
} }
...@@ -31,192 +31,10 @@ ...@@ -31,192 +31,10 @@
namespace Solarium\Tests\QueryType\Select\Result; namespace Solarium\Tests\QueryType\Select\Result;
use Solarium\QueryType\Select\Result\Document; class ResultTest extends AbstractResultTest
use Solarium\QueryType\Select\Query\Query;
use Solarium\QueryType\Select\Result\Result;
class ResultTest extends \PHPUnit_Framework_TestCase
{ {
/**
* @var SelectDummy
*/
protected $result;
protected $numFound;
protected $maxScore;
protected $docs;
protected $components;
protected $facetSet;
protected $moreLikeThis;
protected $highlighting;
protected $grouping;
protected $stats;
protected $debug;
protected $spellcheck;
public function setUp() public function setUp()
{ {
$this->numFound = 11; parent::setUp();
$this->maxScore = 0.91;
$this->docs = array(
new Document(array('id'=>1, 'title'=>'doc1')),
new Document(array('id'=>1, 'title'=>'doc1')),
);
$this->facetSet = 'dummy-facetset-value';
$this->moreLikeThis = 'dummy-facetset-value';
$this->highlighting = 'dummy-highlighting-value';
$this->grouping = 'dummy-grouping-value';
$this->spellcheck = 'dummy-grouping-value';
$this->stats = 'dummy-stats-value';
$this->debug = 'dummy-debug-value';
$this->components = array(
Query::COMPONENT_FACETSET => $this->facetSet,
Query::COMPONENT_MORELIKETHIS => $this->moreLikeThis,
Query::COMPONENT_HIGHLIGHTING => $this->highlighting,
Query::COMPONENT_GROUPING => $this->grouping,
Query::COMPONENT_SPELLCHECK => $this->spellcheck,
Query::COMPONENT_STATS => $this->stats,
Query::COMPONENT_DEBUG => $this->debug,
);
$this->result = new SelectDummy(1, 12, $this->numFound, $this->maxScore, $this->docs, $this->components);
}
public function testGetNumFound()
{
$this->assertEquals($this->numFound, $this->result->getNumFound());
}
public function testGetMaxScore()
{
$this->assertEquals($this->maxScore, $this->result->getMaxScore());
}
public function testGetDocuments()
{
$this->assertEquals($this->docs, $this->result->getDocuments());
}
public function testGetFacetSet()
{
$this->assertEquals($this->facetSet, $this->result->getFacetSet());
}
public function testCount()
{
$this->assertEquals(count($this->docs), count($this->result));
}
public function testGetComponents()
{
$this->assertEquals($this->components, $this->result->getComponents());
}
public function testGetComponent()
{
$this->assertEquals(
$this->components[Query::COMPONENT_MORELIKETHIS],
$this->result->getComponent(Query::COMPONENT_MORELIKETHIS)
);
}
public function testGetInvalidComponent()
{
$this->assertEquals(
null,
$this->result->getComponent('invalid')
);
}
public function testGetMoreLikeThis()
{
$this->assertEquals(
$this->components[Query::COMPONENT_MORELIKETHIS],
$this->result->getMoreLikeThis()
);
}
public function testGetHighlighting()
{
$this->assertEquals(
$this->components[Query::COMPONENT_HIGHLIGHTING],
$this->result->getHighlighting()
);
}
public function testGetGrouping()
{
$this->assertEquals(
$this->components[Query::COMPONENT_GROUPING],
$this->result->getGrouping()
);
}
public function testGetSpellcheck()
{
$this->assertEquals(
$this->components[Query::COMPONENT_SPELLCHECK],
$this->result->getSpellcheck()
);
}
public function testGetStats()
{
$this->assertEquals(
$this->components[Query::COMPONENT_STATS],
$this->result->getStats()
);
}
public function testGetDebug()
{
$this->assertEquals(
$this->components[Query::COMPONENT_DEBUG],
$this->result->getDebug()
);
}
public function testIterator()
{
$docs = array();
foreach ($this->result as $key => $doc) {
$docs[$key] = $doc;
}
$this->assertEquals($this->docs, $docs);
}
public function testGetStatus()
{
$this->assertEquals(
1,
$this->result->getStatus()
);
}
public function testGetQueryTime()
{
$this->assertEquals(
12,
$this->result->getQueryTime()
);
}
}
class SelectDummy extends Result
{
protected $parsed = true;
public function __construct($status, $queryTime, $numfound, $maxscore, $docs, $components)
{
$this->numfound = $numfound;
$this->maxscore = $maxscore;
$this->documents = $docs;
$this->components = $components;
$this->queryTime = $queryTime;
$this->status = $status;
} }
} }
<?php
/**
* Copyright 2011 Bas de Nooijer. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this listof conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Update;
abstract class AbstractResultTest extends \PHPUnit_Framework_TestCase
{
protected $result;
public function testGetStatus()
{
$this->assertEquals(
1,
$this->result->getStatus()
);
}
public function testGetQueryTime()
{
$this->assertEquals(
12,
$this->result->getQueryTime()
);
}
}
...@@ -33,33 +33,12 @@ namespace Solarium\Tests\QueryType\Update; ...@@ -33,33 +33,12 @@ namespace Solarium\Tests\QueryType\Update;
use Solarium\QueryType\Update\Result as UpdateResult; use Solarium\QueryType\Update\Result as UpdateResult;
class ResultTest extends \PHPUnit_Framework_TestCase class ResultTest extends AbstractResultTest
{ {
/**
* @var UpdateDummy
*/
protected $result;
public function setUp() public function setUp()
{ {
$this->result = new UpdateDummy(); $this->result = new UpdateDummy();
} }
public function testGetStatus()
{
$this->assertEquals(
1,
$this->result->getStatus()
);
}
public function testGetQueryTime()
{
$this->assertEquals(
12,
$this->result->getQueryTime()
);
}
} }
class UpdateDummy extends UpdateResult class UpdateDummy extends UpdateResult
......
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