Commit f7aaf129 authored by Bas de Nooijer's avatar Bas de Nooijer

Improved unittest coverage

parent d62bd57f
...@@ -60,11 +60,10 @@ class Solarium_Client_ResponseParser_Select_Component_Stats ...@@ -60,11 +60,10 @@ class Solarium_Client_ResponseParser_Select_Component_Stats
$statResults = $data['stats']['stats_fields']; $statResults = $data['stats']['stats_fields'];
foreach ($statResults AS $field => $stats) { foreach ($statResults AS $field => $stats) {
$facets = array();
if (isset($stats['facets'])) { if (isset($stats['facets'])) {
foreach($stats['facets'] as $field => $values) { foreach($stats['facets'] as $facetField => $values) {
foreach ($values as $value => $valueStats) { foreach ($values as $value => $valueStats) {
$stats['facets'][$field][$value] = new Solarium_Result_Select_Stats_FacetValue($value, $valueStats); $stats['facets'][$facetField][$value] = new Solarium_Result_Select_Stats_FacetValue($value, $valueStats);
} }
} }
} }
......
<?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.
*/
class Solarium_Client_RequestBuilder_Select_Component_StatsTest extends PHPUnit_Framework_TestCase
{
public function testBuild()
{
$builder = new Solarium_Client_RequestBuilder_Select_Component_Stats();
$request = new Solarium_Client_Request();
$component = new Solarium_Query_Select_Component_Stats();
$component->createField('fieldA')->addFacet('fieldFacetA');
$component->createField('fieldB');
$component->addFacets(array('facetA', 'facetB'));
$request = $builder->build($component, $request);
$this->assertEquals(
array(
'stats' => true,
'stats.facet' => array(
'facetA',
'facetB',
),
'stats.field' => array(
'fieldA',
'fieldB',
),
'f.fieldA.stats.facet' => 'fieldFacetA',
),
$request->getParams()
);
}
}
\ No newline at end of file
<?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.
*/
class Solarium_Client_ResponseParser_Select_Component_StatsTest extends PHPUnit_Framework_TestCase
{
protected $_parser;
public function setUp()
{
$this->_parser = new Solarium_Client_ResponseParser_Select_Component_Stats();
}
public function testParse()
{
$data = array(
'stats' => array(
'stats_fields' => array(
'fieldA' => array(
'min' => 3,
),
'fieldB' => array(
'min' => 4,
'facets' => array(
'fieldC' => array(
'value1' => array(
'min' => 5,
)
)
)
)
)
)
);
$result = $this->_parser->parse(null, null, $data);
$this->assertEquals(3, $result->getResult('fieldA')->getMin());
$this->assertEquals(4, $result->getResult('fieldB')->getMin());
$facets = $result->getResult('fieldB')->getFacets();
$this->assertEquals(5, $facets['fieldC']['value1']->getMin());
}
public function testParseNoData()
{
$result = $this->_parser->parse(null, null, array());
$this->assertEquals(0, count($result));
}
}
<?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.
*/
class Solarium_Query_Select_Component_Stats_FieldTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Select_Component_Stats_Field
*/
protected $_field;
public function setUp()
{
$this->_field = new Solarium_Query_Select_Component_Stats_Field;
}
public function testConfigMode()
{
$options = array(
'facet' => 'field1, field2',
);
$this->_field->setOptions($options);
$this->assertEquals(array('field1','field2'), $this->_field->getFacets());
}
public function testSetAndGetKey()
{
$this->_field->setKey('testkey');
$this->assertEquals('testkey', $this->_field->getKey());
}
public function testAddFacet()
{
$expectedFacets = $this->_field->getFacets();
$expectedFacets[] = 'newfacet';
$this->_field->addFacet('newfacet');
$this->assertEquals($expectedFacets, $this->_field->getFacets());
}
public function testClearFacets()
{
$this->_field->addFacet('newfacet');
$this->_field->clearFacets();
$this->assertEquals(array(), $this->_field->getFacets());
}
public function testAddFacets()
{
$facets = array('facet1','facet2');
$this->_field->clearFacets();
$this->_field->addFacets($facets);
$this->assertEquals($facets, $this->_field->getFacets());
}
public function testAddFacetsAsStringWithTrim()
{
$this->_field->clearFacets();
$this->_field->addFacets('facet1, facet2');
$this->assertEquals(array('facet1','facet2'), $this->_field->getFacets());
}
public function testRemoveFacet()
{
$this->_field->clearFacets();
$this->_field->addFacets(array('facet1','facet2'));
$this->_field->removeFacet('facet1');
$this->assertEquals(array('facet2'), $this->_field->getFacets());
}
public function testSetFacets()
{
$this->_field->clearFacets();
$this->_field->addFacets(array('facet1','facet2'));
$this->_field->setFacets(array('facet3','facet4'));
$this->assertEquals(array('facet3','facet4'), $this->_field->getFacets());
}
}
<?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.
*/
class Solarium_Query_Select_Component_StatsTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Query_Select_Component_Stats
*/
protected $_stats;
public function setUp()
{
$this->_stats = new Solarium_Query_Select_Component_Stats;
}
public function testGetType()
{
$this->assertEquals(Solarium_Query_Select::COMPONENT_STATS, $this->_stats->getType());
}
public function testConfigMode()
{
$options = array(
'facet' => 'field1, field2',
'field' => array(
'f1' => array(),
'f2' => array(),
)
);
$this->_stats->setOptions($options);
$this->assertEquals(array('field1','field2'), $this->_stats->getFacets());
$this->assertEquals(array('f1','f2'), array_keys($this->_stats->getFields()));
}
public function testCreateFieldWithKey()
{
$field = $this->_stats->createField('mykey');
// check class
$this->assertThat($field, $this->isInstanceOf('Solarium_Query_Select_Component_Stats_Field'));
$this->assertEquals(
'mykey',
$field->getKey()
);
}
public function testCreateFieldWithOptions()
{
$options = array('key' => 'testkey');
$field = $this->_stats->createField($options);
// check class
$this->assertThat($field, $this->isInstanceOf('Solarium_Query_Select_Component_Stats_Field'));
// check option forwarding
$fieldOptions = $field->getOptions();
$this->assertEquals(
$options['key'],
$field->getKey()
);
}
public function testAddAndGetField()
{
$field = new Solarium_Query_Select_Component_Stats_Field;
$field->setKey('f1');
$this->_stats->addField($field);
$this->assertEquals(
$field,
$this->_stats->getField('f1')
);
}
public function testAddFieldWithOptions()
{
$this->_stats->addField(array('key' => 'f1'));
$this->assertEquals(
'f1',
$this->_stats->getField('f1')->getKey()
);
}
public function testAddAndGetFieldWithKey()
{
$key = 'f1';
$fld = $this->_stats->createField($key, true);
$this->assertEquals(
$key,
$fld->getKey()
);
$this->assertEquals(
$fld,
$this->_stats->getField('f1')
);
}
public function testAddFieldWithoutKey()
{
$fld = new Solarium_Query_Select_Component_Stats_Field;
$this->setExpectedException('Solarium_Exception');
$this->_stats->addField($fld);
}
public function testAddFieldWithUsedKey()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f1');
$this->_stats->addField($f1);
$this->setExpectedException('Solarium_Exception');
$this->_stats->addField($f2);
}
public function testGetInvalidField()
{
$this->assertEquals(
null,
$this->_stats->getField('invalidkey')
);
}
public function testAddFields()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f2');
$fields = array('f1' => $f1, 'f2' => $f2);
$this->_stats->addFields($fields);
$this->assertEquals(
$fields,
$this->_stats->getFields()
);
}
public function testAddFieldsWithOptions()
{
$fields = array(
'f1' => array(''),
array('key' => 'f2')
);
$this->_stats->addFields($fields);
$fields = $this->_stats->getFields();
$this->assertEquals( array('f1', 'f2'), array_keys($fields));
}
public function testRemoveField()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f2');
$fields = array('f1' => $f1, 'f2' => $f2);
$this->_stats->addFields($fields);
$this->_stats->removeField('f1');
$this->assertEquals(
array('f2' => $f2),
$this->_stats->getFields()
);
}
public function testRemoveFieldWithObjectInput()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f2');
$fields = array($f1, $f2);
$this->_stats->addFields($fields);
$this->_stats->removeField($f1);
$this->assertEquals(
array('f2' => $f2),
$this->_stats->getFields()
);
}
public function testRemoveInvalidField()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f2');
$fields = array('f1' => $f1, 'f2' => $f2);
$this->_stats->addFields($fields);
$this->_stats->removeField('f3'); //continue silently
$this->assertEquals(
$fields,
$this->_stats->getFields()
);
}
public function testClearFields()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f2');
$fields = array($f1, $f2);
$this->_stats->addFields($fields);
$this->_stats->clearFields();
$this->assertEquals(
array(),
$this->_stats->getFields()
);
}
public function testSetFields()
{
$f1 = new Solarium_Query_Select_Component_Stats_Field;
$f1->setKey('f1');
$f2 = new Solarium_Query_Select_Component_Stats_Field;
$f2->setKey('f2');
$fields = array($f1, $f2);
$this->_stats->addFields($fields);
$f3 = new Solarium_Query_Select_Component_Stats_Field;
$f3->setKey('f3');
$f4 = new Solarium_Query_Select_Component_Stats_Field;
$f4->setKey('f4');
$fields2 = array('f3' => $f3, 'f4' => $f4);
$this->_stats->setFields($fields2);
$this->assertEquals(
$fields2,
$this->_stats->getFields()
);
}
public function testAddFacet()
{
$expectedFacets = $this->_stats->getFacets();
$expectedFacets[] = 'newfacet';
$this->_stats->addFacet('newfacet');
$this->assertEquals($expectedFacets, $this->_stats->getFacets());
}
public function testClearFacets()
{
$this->_stats->addFacet('newfacet');
$this->_stats->clearFacets();
$this->assertEquals(array(), $this->_stats->getFacets());
}
public function testAddFacets()
{
$facets = array('facet1','facet2');
$this->_stats->clearFacets();
$this->_stats->addFacets($facets);
$this->assertEquals($facets, $this->_stats->getFacets());
}
public function testAddFacetsAsStringWithTrim()
{
$this->_stats->clearFacets();
$this->_stats->addFacets('facet1, facet2');
$this->assertEquals(array('facet1','facet2'), $this->_stats->getFacets());
}
public function testRemoveFacet()
{
$this->_stats->clearFacets();
$this->_stats->addFacets(array('facet1','facet2'));
$this->_stats->removeFacet('facet1');
$this->assertEquals(array('facet2'), $this->_stats->getFacets());
}
public function testSetFacets()
{
$this->_stats->clearFacets();
$this->_stats->addFacets(array('facet1','facet2'));
$this->_stats->setFacets(array('facet3','facet4'));
$this->assertEquals(array('facet3','facet4'), $this->_stats->getFacets());
}
}
...@@ -601,4 +601,14 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase ...@@ -601,4 +601,14 @@ class Solarium_Query_SelectTest extends PHPUnit_Framework_TestCase
get_class($spellcheck) get_class($spellcheck)
); );
} }
public function testGetStats()
{
$stats = $this->_query->getStats();
$this->assertEquals(
'Solarium_Query_Select_Component_Stats',
get_class($stats)
);
}
} }
<?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.
*/
class Solarium_Result_Select_Stats_FacetValueTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Stats_FacetValue
*/
protected $_result;
protected $_value, $_stats;
public function setUp()
{
$this->_value = 'myvalue';
$this->_stats = array(
'min' => 'dummyMin',
'max' => 'dummyMax',
'sum' => 'dummySum',
'count' => 'dummyCount',
'missing' => 'dummyMissing',
'sumOfSquares' => 'dummySos',
'mean' => 'dummyMean',
'stddev' => 'dummyStddev',
'facets' => 'dummyFacets',
);
$this->_result = new Solarium_Result_Select_Stats_FacetValue($this->_value, $this->_stats);
}
public function testGetValue()
{
$this->assertEquals($this->_value, $this->_result->getValue());
}
public function testGetMin()
{
$this->assertEquals($this->_stats['min'], $this->_result->getMin());
}
public function testGetMax()
{
$this->assertEquals($this->_stats['max'], $this->_result->getMax());
}
public function testGetSum()
{
$this->assertEquals($this->_stats['sum'], $this->_result->getSum());
}
public function testGetCount()
{
$this->assertEquals($this->_stats['count'], $this->_result->getCount());
}
public function testGetMissing()
{
$this->assertEquals($this->_stats['missing'], $this->_result->getMissing());
}
public function testGetSumOfSquares()
{
$this->assertEquals($this->_stats['sumOfSquares'], $this->_result->getSumOfSquares());
}
public function testGetMean()
{
$this->assertEquals($this->_stats['mean'], $this->_result->getMean());
}
public function testGetStddev()
{
$this->assertEquals($this->_stats['stddev'], $this->_result->getStddev());
}
public function testGetFacets()
{
$this->assertEquals($this->_stats['facets'], $this->_result->getFacets());
}
}
<?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.
*/
class Solarium_Result_Select_Stats_ResultTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Stats_Result
*/
protected $_result;
protected $_field, $_stats;
public function setUp()
{
$this->_field = 'myfield';
$this->_stats = array(
'min' => 'dummyMin',
'max' => 'dummyMax',
'sum' => 'dummySum',
'count' => 'dummyCount',
'missing' => 'dummyMissing',
'sumOfSquares' => 'dummySos',
'mean' => 'dummyMean',
'stddev' => 'dummyStddev',
'facets' => 'dummyFacets',
);
$this->_result = new Solarium_Result_Select_Stats_Result($this->_field, $this->_stats);
}
public function testGetName()
{
$this->assertEquals($this->_field, $this->_result->getName());
}
public function testGetMin()
{
$this->assertEquals($this->_stats['min'], $this->_result->getMin());
}
public function testGetMax()
{
$this->assertEquals($this->_stats['max'], $this->_result->getMax());
}
public function testGetSum()
{
$this->assertEquals($this->_stats['sum'], $this->_result->getSum());
}
public function testGetCount()
{
$this->assertEquals($this->_stats['count'], $this->_result->getCount());
}
public function testGetMissing()
{
$this->assertEquals($this->_stats['missing'], $this->_result->getMissing());
}
public function testGetSumOfSquares()
{
$this->assertEquals($this->_stats['sumOfSquares'], $this->_result->getSumOfSquares());
}
public function testGetMean()
{
$this->assertEquals($this->_stats['mean'], $this->_result->getMean());
}
public function testGetStddev()
{
$this->assertEquals($this->_stats['stddev'], $this->_result->getStddev());
}
public function testGetFacets()
{
$this->assertEquals($this->_stats['facets'], $this->_result->getFacets());
}
}
<?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.
*/
class Solarium_Result_Select_StatsTest extends PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Result_Select_Stats
*/
protected $_result;
public function setUp()
{
$this->_data = array(
'key1' => 'value1',
'key2' => 'value2',
);
$this->_result = new Solarium_Result_Select_Stats($this->_data);
}
public function testGetResult()
{
$this->assertEquals($this->_data['key1'], $this->_result->getResult('key1'));
}
public function testGetInvalidResult()
{
$this->assertEquals(null, $this->_result->getResult('key3'));
}
public function testGetResults()
{
$this->assertEquals($this->_data, $this->_result->getResults());
}
public function testIterator()
{
$items = array();
foreach($this->_result AS $key => $item)
{
$items[$key] = $item;
}
$this->assertEquals($this->_data, $items);
}
public function testCount()
{
$this->assertEquals(count($this->_data), count($this->_result));
}
}
...@@ -37,7 +37,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase ...@@ -37,7 +37,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
*/ */
protected $_result; protected $_result;
protected $_numFound, $_docs, $_components, $_facetSet, $_moreLikeThis, $_highlighting, $_grouping; protected $_numFound, $_docs, $_components, $_facetSet, $_moreLikeThis, $_highlighting, $_grouping, $_stats;
public function setUp() public function setUp()
{ {
...@@ -53,6 +53,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase ...@@ -53,6 +53,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
$this->_highlighting = 'dummy-highlighting-value'; $this->_highlighting = 'dummy-highlighting-value';
$this->_grouping = 'dummy-grouping-value'; $this->_grouping = 'dummy-grouping-value';
$this->_spellcheck = 'dummy-grouping-value'; $this->_spellcheck = 'dummy-grouping-value';
$this->_stats = 'dummy-stats-value';
$this->_components = array( $this->_components = array(
Solarium_Query_Select::COMPONENT_FACETSET => $this->_facetSet, Solarium_Query_Select::COMPONENT_FACETSET => $this->_facetSet,
...@@ -60,6 +61,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase ...@@ -60,6 +61,7 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
Solarium_Query_Select::COMPONENT_HIGHLIGHTING => $this->_highlighting, Solarium_Query_Select::COMPONENT_HIGHLIGHTING => $this->_highlighting,
Solarium_Query_Select::COMPONENT_GROUPING => $this->_grouping, Solarium_Query_Select::COMPONENT_GROUPING => $this->_grouping,
Solarium_Query_Select::COMPONENT_SPELLCHECK => $this->_spellcheck, Solarium_Query_Select::COMPONENT_SPELLCHECK => $this->_spellcheck,
Solarium_Query_Select::COMPONENT_STATS => $this->_stats,
); );
$this->_result = new Solarium_Result_SelectDummy(1, 12, $this->_numFound, $this->_docs, $this->_components); $this->_result = new Solarium_Result_SelectDummy(1, 12, $this->_numFound, $this->_docs, $this->_components);
...@@ -138,6 +140,14 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase ...@@ -138,6 +140,14 @@ class Solarium_Result_SelectTest extends PHPUnit_Framework_TestCase
); );
} }
public function testGetStats()
{
$this->assertEquals(
$this->_components[Solarium_Query_Select::COMPONENT_STATS],
$this->_result->getStats()
);
}
public function testIterator() public function testIterator()
{ {
$docs = array(); $docs = array();
......
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