Commit 806a1ec0 authored by Bas de Nooijer's avatar Bas de Nooijer

Merge branch 'develop' into feature/nextgen

Conflicts:
	library/Solarium/Client/Client.php
	library/Solarium/Client/RequestBuilder/Select/Component/Highlighting.php
	library/Solarium/Client/ResponseParser/Analysis/Field.php
	library/Solarium/Plugin/AbstractPlugin.php
	library/Solarium/Query/Helper.php
	library/Solarium/Result/Result.php
	library/Solarium/Result/Select/Debug/Debug.php
	tests/Solarium/Tests/Client/RequestBuilder/Select/Component/FacetSetTest.php
parents 475e2675 630ee35d
<?php
require('init.php');
// this very simple plugin is used to show some events
class simpleDebug extends \Solarium\Plugin\AbstractPlugin
{
protected $_output = array();
public function display()
{
echo implode('<br/>', $this->_output);
}
public function eventBufferedAddFlushStart($buffer) {
$this->_output[] = 'Flushing buffer (' . count($buffer) . 'docs)';
}
}
htmlHeader();
// create a client instance and autoload the buffered add plugin
$client = new Solarium\Client\Client($config);
$buffer = $client->getPlugin('bufferedadd');
$buffer->setBufferSize(10); // this is quite low, in most cases you can use a much higher value
// also register a plugin for outputting events
$debug = new simpleDebug();
$client->registerPlugin('debugger', $debug);
// let's insert 25 docs
for ($i=1; $i<=25; $i++) {
// create a new document with dummy data and add it to the buffer
$data = array(
'id' => 'test_'.$i,
'name' => 'test for buffered add',
'price' => $i,
);
$buffer->createDocument($data);
// alternatively you could create document instances yourself and use the addDocument(s) method
}
// At this point two flushes will already have been done by the buffer automatically (at the 10th and 20th doc), now
// manually flush the remainder. Alternatively you can use the commit method if you want to include a commit command.
$buffer->flush();
// In total 3 flushes (requests) have been sent to Solr. This should be visible in this output:
$debug->display();
htmlFooter();
\ No newline at end of file
<?php
require('init.php');
htmlHeader();
// create a client instance
$client = new Solarium\Client\Client($config);
// get a select query instance
$query = $client->createSelect();
$query->setFields(array('id'));
// get a plugin instance and apply settings
$prefetch = $client->getPlugin('prefetchiterator');
$prefetch->setPrefetch(2); //fetch 5 rows per query (for real world use this can be way higher)
$prefetch->setQuery($query);
// display the total number of documents found by solr
echo 'NumFound: ' . count($prefetch);
// show document IDs using the resultset iterator
foreach ($prefetch as $document) {
echo '<hr/>ID: '. $document->id;
}
htmlFooter();
\ No newline at end of file
...@@ -124,6 +124,8 @@ ...@@ -124,6 +124,8 @@
<li><a href="7.2-plugin-postbigrequest.php">7.2 Post Big Requests</a></li> <li><a href="7.2-plugin-postbigrequest.php">7.2 Post Big Requests</a></li>
<li><a href="7.3-plugin-customizerequest.php">7.3 Customize Requests</a></li> <li><a href="7.3-plugin-customizerequest.php">7.3 Customize Requests</a></li>
<li><a href="7.4-plugin-parallelexecution.php">7.4 Parallel Execution</a></li> <li><a href="7.4-plugin-parallelexecution.php">7.4 Parallel Execution</a></li>
<li><a href="7.5-plugin-bufferedadd.php">7.5 Buffered Add for documents</a></li>
<li><a href="7.6-plugin-prefetchiterator.php">7.6 Prefetch iterator for select queries</a></li>
</ul> </ul>
</ul> </ul>
......
...@@ -96,6 +96,13 @@ class Curl extends Adapter ...@@ -96,6 +96,13 @@ class Curl extends Adapter
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
/**
* Get the response for a curl handle
*
* @param resource $handle
* @param string $httpResponse
* @return Solarium_Client_Response
*/
public function getResponse($handle, $httpResponse) public function getResponse($handle, $httpResponse)
{ {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
......
...@@ -170,6 +170,8 @@ class Client extends Solarium\Configurable ...@@ -170,6 +170,8 @@ class Client extends Solarium\Configurable
'postbigrequest' => 'Solarium\Plugin\PostBigRequest', 'postbigrequest' => 'Solarium\Plugin\PostBigRequest',
'customizerequest' => 'Solarium\Plugin\CustomizeRequest\CustomizeRequest', 'customizerequest' => 'Solarium\Plugin\CustomizeRequest\CustomizeRequest',
'parallelexecution' => 'Solarium\Plugin\ParallelExecution', 'parallelexecution' => 'Solarium\Plugin\ParallelExecution',
'bufferedadd' => 'Solarium\Plugin\BufferedAdd',
'prefetchiterator' => 'Solarium\Plugin\PrefetchIterator',
); );
/** /**
...@@ -396,7 +398,7 @@ class Client extends Solarium\Configurable ...@@ -396,7 +398,7 @@ class Client extends Solarium\Configurable
} }
/** /**
* Get all registered querytypes * Get all registered plugins
* *
* @return array * @return array
*/ */
......
...@@ -116,12 +116,29 @@ class Field extends \Solarium\Client\ResponseParser\ResponseParser ...@@ -116,12 +116,29 @@ class Field extends \Solarium\Client\ResponseParser\ResponseParser
$class = $typeData[$counter]; $class = $typeData[$counter];
$analysis = $typeData[$counter+1]; $analysis = $typeData[$counter+1];
$items = array(); if (is_string($analysis)) {
foreach ($analysis AS $itemData) {
$items[] = new Analysis\Item($itemData); $item = new Analysis\Item(array(
'text' => $analysis,
'start' => null,
'end' => null,
'position' => null,
'positionHistory' => null,
'type' => null,
));
$classes[] = new Analysis\ResultList($class, array($item));
} else {
$items = array();
foreach ($analysis as $itemData) {
$items[] = new Analysis\Item($itemData);
}
$classes[] = new Analysis\ResultList($class, $items);
} }
$classes[] = new Analysis\ResultList($class, $items);
$counter += 2; $counter += 2;
} }
......
...@@ -75,7 +75,7 @@ abstract class AbstractPlugin extends \Solarium\Configurable ...@@ -75,7 +75,7 @@ abstract class AbstractPlugin extends \Solarium\Configurable
/** /**
* Plugin init function * Plugin init function
* *
* This is an extension point for plugin implemenations. * This is an extension point for plugin implementations.
* Will be called as soon as $this->_client and options have been set. * Will be called as soon as $this->_client and options have been set.
* *
* @return void * @return void
......
<?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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
*/
/**
* @namespace
*/
namespace Solarium\Plugin;
use Solarium\Client;
/**
* Buffered add plugin
*
* If you need to add (or update) a big number of documents to Solr it's much more efficient to do so in batches.
* This plugin makes this as easy as possible.
*
* @package Solarium
* @subpackage Plugin
*/
class BufferedAdd extends AbstractPlugin
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
'buffersize' => 100,
);
/**
* Update query instance
*
* @var Solarium_Query_Update
*/
protected $_updateQuery;
/**
* Buffered documents
*
* @var array
*/
protected $_buffer = array();
/**
* Plugin init function
*
* This is an extension point for plugin implementations.
* Will be called as soon as $this->_client and options have been set.
*
* @return void
*/
protected function _initPlugin()
{
$this->_updateQuery = $this->_client->createUpdate();
}
/**
* Set buffer size option
*
* @param int $size
* @return Solarium_Configurable
*/
public function setBufferSize($size)
{
return $this->_setOption('buffersize', $size);
}
/**
* Get buffer size option value
*
* @return int
*/
public function getBufferSize()
{
return $this->getOption('buffersize');
}
/**
* Create a document object instance and add it to the buffer
*
* @param array $fields
* @param array $boosts
* @return self Provides fluent interface
*/
public function createDocument($fields, $boosts = array())
{
$doc = $this->_updateQuery->createDocument($fields, $boosts);
$this->addDocument($doc);
return $this;
}
/**
* Add a document
*
* @param Solarium\Document\ReadOnly $document
* @return self Provides fluent interface
*/
public function addDocument($document)
{
$this->_buffer[] = $document;
if (count($this->_buffer) == $this->_options['buffersize']) {
$this->flush();
}
return $this;
}
/**
* Add multiple documents
*
* @param array
* @return self Provides fluent interface
*/
public function addDocuments($documents)
{
foreach ($documents as $document) {
$this->addDocument($document);
}
return $this;
}
/**
* Get all documents currently in the buffer
*
* Any previously flushed documents will not be included!
*
* @return array
*/
public function getDocuments()
{
return $this->_buffer;
}
/**
* Clear any buffered documents
*
* @return self Provides fluent interface
*/
public function clear()
{
$this->_updateQuery = $this->_client->createUpdate();
$this->_buffer = array();
return $this;
}
/**
* Flush any buffered documents to Solr
*
* @param boolean $overwrite
* @param int $commitWithin
* @return boolean|Solarium\Result\Update
*/
public function flush($overwrite = null, $commitWithin = null)
{
if (count($this->_buffer) == 0) {
// nothing to do
return false;
}
$this->_client->triggerEvent('BufferedAddFlushStart', array($this->_buffer));
$this->_updateQuery->addDocuments($this->_buffer, $overwrite, $commitWithin);
$result = $this->_client->update($this->_updateQuery);
$this->clear();
$this->_client->triggerEvent('BufferedAddFlushEnd', array($result));
return $result;
}
/**
* Commit changes
*
* Any remaining documents in the buffer will also be flushed
*
* @param boolean $overwrite
* @param boolean $waitFlush
* @param boolean $waitSearcher
* @param boolean $expungeDeletes
* @return Solarium\Result\Update
*/
public function commit($overwrite = null, $waitFlush = null, $waitSearcher = null, $expungeDeletes = null)
{
$this->_client->triggerEvent('BufferedAddCommitStart', array($this->_buffer));
$this->_updateQuery->addDocuments($this->_buffer, $overwrite);
$this->_updateQuery->addCommit($waitFlush, $waitSearcher, $expungeDeletes);
$result = $this->_client->update($this->_updateQuery);
$this->clear();
$this->_client->triggerEvent('BufferedAddCommitEnd', array($result));
return $result;
}
}
\ No newline at end of file
...@@ -50,9 +50,13 @@ class Customization extends \Solarium\Configurable ...@@ -50,9 +50,13 @@ class Customization extends \Solarium\Configurable
{ {
/** /**
* Type definitions * Type definition for params
*/ */
const TYPE_PARAM = 'param'; const TYPE_PARAM = 'param';
/**
* Type definition for headers
*/
const TYPE_HEADER = 'header'; const TYPE_HEADER = 'header';
/** /**
......
...@@ -74,7 +74,7 @@ class ParallelExecution extends AbstractPlugin ...@@ -74,7 +74,7 @@ class ParallelExecution extends AbstractPlugin
// create handles and add all handles to the multihandle // create handles and add all handles to the multihandle
$multiHandle = curl_multi_init(); $multiHandle = curl_multi_init();
$handles = array(); $handles = array();
foreach($queries as $key => $query) { foreach ($queries as $key => $query) {
$request = $this->_client->createRequest($query); $request = $this->_client->createRequest($query);
$handle = $adapter->createHandle($request); $handle = $adapter->createHandle($request);
curl_multi_add_handle($multiHandle, $handle); curl_multi_add_handle($multiHandle, $handle);
......
<?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.
*
* @copyright Copyright 2011 Bas de Nooijer <solarium@raspberry.nl>
* @license http://github.com/basdenooijer/solarium/raw/master/COPYING
* @link http://www.solarium-project.org/
*
* @package Solarium
*/
/**
* @namespace
*/
namespace Solarium\Plugin;
use Solarium\Client;
/**
* Prefetch plugin
*
* This plugin can be used to create an 'endless' iterator over a complete resultset. The iterator will take care of
* fetching the data in sets (sequential prefetching).
*
* @package Solarium
* @subpackage Plugin
*/
class PrefetchIterator extends AbstractPlugin implements \Iterator, \Countable
{
/**
* Default options
*
* @var array
*/
protected $_options = array(
'prefetch' => 100,
);
/**
* Query instance to execute
*
* @var Solarium\Query\Select
*/
protected $_query;
/**
* Start position (offset)
*
* @var int
*/
protected $_start = 0;
/**
* Last resultset from the query instance
*
* @var Solarium\Result\Select
*/
protected $_result;
/**
* Iterator position
*
* @var int
*/
protected $_position;
/**
* Documents from the last resultset
*
* @var array
*/
protected $_documents;
/**
* Set prefetch option
*
* @param integer $value
* @return self Provides fluent interface
*/
public function setPrefetch($value)
{
return $this->_setOption('prefetch', $value);
}
/**
* Get prefetch option
*
* @return integer
*/
public function getPrefetch()
{
return $this->getOption('prefetch');
}
/**
* Set query to use for prefetching
*
* @param Solarium\Query\Select $query
* @return self Provides fluent interface
*/
public function setQuery($query)
{
$this->_query = $query;
return $this;
}
/**
* Get the query object used
*
* @return Solarium\Query\Select
*/
public function getQuery()
{
return $this->_query;
}
/**
* Countable implementation
*
* @return int
*/
public function count()
{
// if no results are available yet, get them now
if (null == $this->_result) $this->_fetchNext();
return $this->_result->getNumFound();
}
/**
* Iterator implementation
*/
function rewind()
{
$this->_position = 0;
// this condition prevent useless re-fetching of data if a count is done before the iterator is used
if ($this->_start !== $this->_options['prefetch']) {
$this->_start = 0;
}
}
/**
* Iterator implementation
*/
function current()
{
$adjustedIndex = $this->_position % $this->_options['prefetch'];
return $this->_documents[$adjustedIndex];
}
/**
* Iterator implementation
*
* @return int
*/
function key()
{
return $this->_position;
}
/**
* Iterator implementation
*/
function next()
{
++$this->_position;
}
/**
* Iterator implementation
*
* @return boolean
*/
function valid()
{
$adjustedIndex = $this->_position % $this->_options['prefetch'];
// this condition prevent useless re-fetching of data if a count is done before the iterator is used
if ($adjustedIndex == 0 && ($this->_position !== 0 || null == $this->_result)) {
$this->_fetchNext();
}
return isset($this->_documents[$adjustedIndex]);
}
/**
* Fetch the next set of results
*
* @return void
*/
protected function _fetchNext()
{
$this->_query->setStart($this->_start)->setRows($this->getPrefetch());
$this->_result = $this->_client->execute($this->_query);
$this->_documents = $this->_result->getDocuments();
$this->_start += $this->getPrefetch();
}
}
\ No newline at end of file
...@@ -74,7 +74,10 @@ class Helper ...@@ -74,7 +74,10 @@ class Helper
protected $_derefencedParamsLastKey = 0; protected $_derefencedParamsLastKey = 0;
/** /**
* @var Solarium\Query * Solarium_Query instance, optional.
* Used for dereferenced params.
*
* @var Solarium\Query\Query
*/ */
protected $_query; protected $_query;
...@@ -83,7 +86,8 @@ class Helper ...@@ -83,7 +86,8 @@ class Helper
* *
* @param Solarium\Query $query * @param Solarium\Query $query
*/ */
public function __construct($query = null) { public function __construct($query = null)
{
$this->_query = $query; $this->_query = $query;
} }
...@@ -128,6 +132,68 @@ class Helper ...@@ -128,6 +132,68 @@ class Helper
return '"' . preg_replace('/("|\\\)/', '\\\$1', $input) . '"'; return '"' . preg_replace('/("|\\\)/', '\\\$1', $input) . '"';
} }
/**
* Format a date to the expected formatting used in SOLR
*
* This format was derived to be standards compliant (ISO 8601)
* A date field shall be of the form 1995-12-31T23:59:59Z The trailing "Z" designates UTC time and is mandatory
*
* @see http://lucene.apache.org/solr/api/org/apache/solr/schema/DateField.html
*
* @param int|string|DateTime $input accepted formats: timestamp, date string or DateTime
* @return string|false false is returned in case of invalid input
*/
public function formatDate($input)
{
switch(true){
// input of datetime object
case $input instanceof \DateTime:
// no work needed
break;
// input of timestamp or date/time string
case is_string($input) || is_numeric($input):
// if date/time string: convert to timestamp first
if (is_string($input)) $input = strtotime($input);
// now try converting the timestamp to a datetime instance, on failure return false
try {
$input = new \DateTime('@' . $input);
} catch (\Exception $e) {
$input = false;
}
break;
// any other input formats can be added in additional cases here...
// case $input instanceof Zend_Date:
// unsupported input format
default:
$input = false;
break;
}
// handle the filtered input
if ($input) {
// when we get here the input is always a datetime object
$input->setTimezone(new \DateTimeZone('UTC'));
$iso8601 = $input->format(\DateTime::ISO8601);
$iso8601 = strstr($iso8601, '+', true); //strip timezone
$iso8601 .= 'Z';
return $iso8601;
} else {
// unsupported input
return false;
}
}
/** /**
* Render a range query * Render a range query
* *
...@@ -234,14 +300,14 @@ class Helper ...@@ -234,14 +300,14 @@ class Helper
{ {
if ($dereferenced) { if ($dereferenced) {
if(!$this->_query) { if (!$this->_query) {
throw new \Solarium\Exception( throw new \Solarium\Exception(
'Dereferenced params can only be used in a Solarium_Query_Helper instance retrieved from the query ' 'Dereferenced params can only be used in a Solarium_Query_Helper instance retrieved from the query '
. 'by using the getHelper() method, this instance was manually created' . 'by using the getHelper() method, this instance was manually created'
); );
} }
foreach($params as $paramKey => $paramValue) { foreach ($params as $paramKey => $paramValue) {
$this->_derefencedParamsLastKey++; $this->_derefencedParamsLastKey++;
$derefKey = 'deref_' . $this->_derefencedParamsLastKey; $derefKey = 'deref_' . $this->_derefencedParamsLastKey;
$this->_query->addParam($derefKey, $paramValue); $this->_query->addParam($derefKey, $paramValue);
...@@ -351,4 +417,4 @@ class Helper ...@@ -351,4 +417,4 @@ class Helper
return $this->qparser('join', array('from' => $from, 'to' => $to), $dereferenced); return $this->qparser('join', array('from' => $from, 'to' => $to), $dereferenced);
} }
} }
\ No newline at end of file
...@@ -51,41 +51,57 @@ class Item ...@@ -51,41 +51,57 @@ class Item
{ {
/** /**
* Text string
*
* @var string * @var string
*/ */
protected $_text; protected $_text;
/** /**
* RawText string
*
* @var string * @var string
*/ */
protected $_rawText; protected $_rawText;
/** /**
* Start
*
* @var int * @var int
*/ */
protected $_start; protected $_start;
/** /**
* End
*
* @var int * @var int
*/ */
protected $_end; protected $_end;
/** /**
* Position
*
* @var int * @var int
*/ */
protected $_position; protected $_position;
/** /**
* Position history
*
* @var array * @var array
*/ */
protected $_positionHistory; protected $_positionHistory;
/** /**
* Type
*
* @var string * @var string
*/ */
protected $_type; protected $_type;
/** /**
* Match
*
* @var boolean * @var boolean
*/ */
protected $_match = false; protected $_match = false;
......
...@@ -51,11 +51,15 @@ class ResultList implements \IteratorAggregate, \Countable ...@@ -51,11 +51,15 @@ class ResultList implements \IteratorAggregate, \Countable
{ {
/** /**
* List name
*
* @var string * @var string
*/ */
protected $_name; protected $_name;
/** /**
* List items
*
* @var array * @var array
*/ */
protected $_items; protected $_items;
......
...@@ -77,7 +77,9 @@ class Result ...@@ -77,7 +77,9 @@ class Result
protected $_query; protected $_query;
/** /**
* @var Solarium\Client * Solarium client instance
*
* @var \Solarium\Client\Client
*/ */
protected $_client; protected $_client;
......
...@@ -51,36 +51,50 @@ class Debug implements \IteratorAggregate, \Countable ...@@ -51,36 +51,50 @@ class Debug implements \IteratorAggregate, \Countable
{ {
/** /**
* QueryString
*
* @var string * @var string
*/ */
protected $_queryString; protected $_queryString;
/** /**
* ParsedQuery
*
* @var string * @var string
*/ */
protected $_parsedQuery; protected $_parsedQuery;
/** /**
* QueryParser
*
* @var string * @var string
*/ */
protected $_queryParser; protected $_queryParser;
/** /**
* OtherQuery
*
* @var string * @var string
*/ */
protected $_otherQuery; protected $_otherQuery;
/** /**
* Explain instance
*
* @var Solarium\Result\Select\Debug\DocumentSet * @var Solarium\Result\Select\Debug\DocumentSet
*/ */
protected $_explain; protected $_explain;
/** /**
* ExplainOther instance
*
* @var Solarium\Result\Select\Debug\DocumentSet * @var Solarium\Result\Select\Debug\DocumentSet
*/ */
protected $_explainOther; protected $_explainOther;
/** /**
* Timing instance
*
* @var Solarium\Result\Select\Debug\Timing * @var Solarium\Result\Select\Debug\Timing
*/ */
protected $_timing; protected $_timing;
......
...@@ -51,16 +51,22 @@ class Detail ...@@ -51,16 +51,22 @@ class Detail
{ {
/** /**
* Value
*
* @var float * @var float
*/ */
protected $_value; protected $_value;
/** /**
* Match
*
* @var boolean * @var boolean
*/ */
protected $_match; protected $_match;
/** /**
* Description
*
* @var string * @var string
*/ */
protected $_description; protected $_description;
......
...@@ -52,11 +52,15 @@ class Document extends Detail ...@@ -52,11 +52,15 @@ class Document extends Detail
{ {
/** /**
* Key
*
* @var string * @var string
*/ */
protected $_key; protected $_key;
/** /**
* Details
*
* @var array * @var array
*/ */
protected $_details; protected $_details;
...@@ -68,6 +72,7 @@ class Document extends Detail ...@@ -68,6 +72,7 @@ class Document extends Detail
* @param boolean $match * @param boolean $match
* @param float $value * @param float $value
* @param string $description * @param string $description
* @param array $details
*/ */
public function __construct($key, $match, $value, $description, $details) public function __construct($key, $match, $value, $description, $details)
{ {
......
...@@ -51,6 +51,8 @@ class Timing implements \IteratorAggregate, \Countable ...@@ -51,6 +51,8 @@ class Timing implements \IteratorAggregate, \Countable
{ {
/** /**
* Time
*
* @var float * @var float
*/ */
protected $_time; protected $_time;
......
...@@ -52,11 +52,15 @@ class TimingPhase ...@@ -52,11 +52,15 @@ class TimingPhase
{ {
/** /**
* Phase name
*
* @var string * @var string
*/ */
protected $_name; protected $_name;
/** /**
* Phase time
*
* @var float * @var float
*/ */
protected $_time; protected $_time;
......
...@@ -51,16 +51,22 @@ class Collation implements \IteratorAggregate, \Countable ...@@ -51,16 +51,22 @@ class Collation implements \IteratorAggregate, \Countable
{ {
/** /**
* Query
*
* @var string * @var string
*/ */
protected $_query; protected $_query;
/** /**
* Hit count
*
* @var int * @var int
*/ */
protected $_hits; protected $_hits;
/** /**
* Corrections
*
* @var array * @var array
*/ */
protected $_corrections; protected $_corrections;
......
...@@ -65,6 +65,8 @@ class Spellcheck implements \IteratorAggregate, \Countable ...@@ -65,6 +65,8 @@ class Spellcheck implements \IteratorAggregate, \Countable
protected $_collation; protected $_collation;
/** /**
* Correctly spelled?
*
* @var boolean * @var boolean
*/ */
protected $_correctlySpelled; protected $_correctlySpelled;
......
...@@ -126,7 +126,7 @@ class Suggester extends \Solarium\Result\QueryType implements \IteratorAggregate ...@@ -126,7 +126,7 @@ class Suggester extends \Solarium\Result\QueryType implements \IteratorAggregate
/** /**
* Get results for a specific term * Get results for a specific term
* *
* @param string $field * @param string $term
* @return array * @return array
*/ */
public function getTerm($term) public function getTerm($term)
......
...@@ -51,21 +51,29 @@ class Term implements \IteratorAggregate, \Countable ...@@ -51,21 +51,29 @@ class Term implements \IteratorAggregate, \Countable
{ {
/** /**
* NumFound
*
* @var int * @var int
*/ */
protected $_numFound; protected $_numFound;
/** /**
* StartOffset
*
* @var int * @var int
*/ */
protected $_startOffset; protected $_startOffset;
/** /**
* EndOffset
*
* @var int * @var int
*/ */
protected $_endOffset; protected $_endOffset;
/** /**
* Suggestions
*
* @var array * @var array
*/ */
protected $_suggestions; protected $_suggestions;
......
...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component; ...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component;
class DebugTest extends \PHPUnit_Framework_TestCase class DebugTest extends \PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new \Solarium\Client\RequestBuilder\Select\Component\Debug(); $builder = new \Solarium\Client\RequestBuilder\Select\Component\Debug();
$request = new \Solarium\Client\Request(); $request = new \Solarium\Client\Request();
......
...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component; ...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component;
class DisMaxTest extends \PHPUnit_Framework_TestCase class DisMaxTest extends \PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new \Solarium\Client\RequestBuilder\Select\Component\DisMax; $builder = new \Solarium\Client\RequestBuilder\Select\Component\DisMax;
$request = new \Solarium\Client\Request(); $request = new \Solarium\Client\Request();
......
...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component; ...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component;
class DistributedSearchTest extends \PHPUnit_Framework_TestCase class DistributedSearchTest extends \PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new \Solarium\Client\RequestBuilder\Select\Component\DistributedSearch; $builder = new \Solarium\Client\RequestBuilder\Select\Component\DistributedSearch;
$request = new \Solarium\Client\Request(); $request = new \Solarium\Client\Request();
......
...@@ -73,6 +73,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase ...@@ -73,6 +73,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\Field(array('key' => 'f1', 'field' => 'owner'))); $this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\Field(array('key' => 'f1', 'field' => 'owner')));
$this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\Query(array('key' => 'f2', 'query' => 'category:23'))); $this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\Query(array('key' => 'f2', 'query' => 'category:23')));
$this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\MultiQuery(array('key' => 'f3', 'query' => array('f4' => array('query' => 'category:40'))))); $this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\MultiQuery(array('key' => 'f3', 'query' => array('f4' => array('query' => 'category:40')))));
$request = $this->_builder->buildComponent($this->_component, $this->_request); $request = $this->_builder->buildComponent($this->_component, $this->_request);
$this->assertEquals( $this->assertEquals(
...@@ -145,6 +146,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase ...@@ -145,6 +146,7 @@ class FacetSetTest extends \PHPUnit_Framework_TestCase
$this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\Field(array('key' => 'f1', 'field' => 'owner'))); $this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\Field(array('key' => 'f1', 'field' => 'owner')));
$this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\Query(array('key' => 'f2', 'query' => 'category:23'))); $this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\Query(array('key' => 'f2', 'query' => 'category:23')));
$this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\MultiQuery(array('key' => 'f3', 'query' => array('f4' =>array('query' => 'category:40'))))); $this->_component->addFacet(new \Solarium\Query\Select\Component\Facet\MultiQuery(array('key' => 'f3', 'query' => array('f4' =>array('query' => 'category:40')))));
$request = $this->_builder->buildComponent($this->_component, $this->_request); $request = $this->_builder->buildComponent($this->_component, $this->_request);
$this->assertEquals( $this->assertEquals(
......
...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component; ...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component;
class GroupingTest extends \PHPUnit_Framework_TestCase class GroupingTest extends \PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new \Solarium\Client\RequestBuilder\Select\Component\Grouping; $builder = new \Solarium\Client\RequestBuilder\Select\Component\Grouping;
$request = new \Solarium\Client\Request(); $request = new \Solarium\Client\Request();
......
...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component; ...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component;
class HighlightingTest extends \PHPUnit_Framework_TestCase class HighlightingTest extends \PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new \Solarium\Client\RequestBuilder\Select\Component\Highlighting; $builder = new \Solarium\Client\RequestBuilder\Select\Component\Highlighting;
$request = new \Solarium\Client\Request(); $request = new \Solarium\Client\Request();
......
...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component; ...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component;
class MoreLikeThisTest extends \PHPUnit_Framework_TestCase class MoreLikeThisTest extends \PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new \Solarium\Client\RequestBuilder\Select\Component\MoreLikeThis; $builder = new \Solarium\Client\RequestBuilder\Select\Component\MoreLikeThis;
$request = new \Solarium\Client\Request(); $request = new \Solarium\Client\Request();
......
...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component; ...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component;
class SpellcheckTest extends \PHPUnit_Framework_TestCase class SpellcheckTest extends \PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new \Solarium\Client\RequestBuilder\Select\Component\Spellcheck(); $builder = new \Solarium\Client\RequestBuilder\Select\Component\Spellcheck();
$request = new \Solarium\Client\Request(); $request = new \Solarium\Client\Request();
......
...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component; ...@@ -34,7 +34,7 @@ namespace Solarium\Tests\Client\RequestBuilder\Select\Component;
class StatsTest extends \PHPUnit_Framework_TestCase class StatsTest extends \PHPUnit_Framework_TestCase
{ {
public function testBuild() public function testBuildComponent()
{ {
$builder = new \Solarium\Client\RequestBuilder\Select\Component\Stats(); $builder = new \Solarium\Client\RequestBuilder\Select\Component\Stats();
$request = new \Solarium\Client\Request(); $request = new \Solarium\Client\Request();
......
...@@ -42,6 +42,8 @@ class FieldTest extends \PHPUnit_Framework_TestCase ...@@ -42,6 +42,8 @@ class FieldTest extends \PHPUnit_Framework_TestCase
'field1' => array( 'field1' => array(
'type1' => array( 'type1' => array(
array( array(
'org.apache.solr.analysis.PatternReplaceCharFilter',
'string value',
'analysisClass', 'analysisClass',
array( array(
array( array(
...@@ -83,9 +85,11 @@ class FieldTest extends \PHPUnit_Framework_TestCase ...@@ -83,9 +85,11 @@ class FieldTest extends \PHPUnit_Framework_TestCase
$docs = $result['items'][0]->getItems(); $docs = $result['items'][0]->getItems();
$fields = $docs[0]->getItems(); $fields = $docs[0]->getItems();
$types = $fields[0]->getItems(); $types = $fields[0]->getItems();
$classes = $types[0]->getItems(); $class1items = $types[0]->getItems();
$class2items = $types[1]->getItems();
$this->assertEquals('test2', $classes[1]->getText()); $this->assertEquals('string value', $class1items[0]->getText());
$this->assertEquals('test2', $class2items[1]->getText());
} }
public function testParseNoData() public function testParseNoData()
......
<?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\Plugin;
class BufferedAddTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Plugin_BufferedAdd
*/
protected $_plugin;
public function setUp()
{
$this->_plugin = new \Solarium\Plugin\BufferedAdd();
$this->_plugin->init(new \Solarium\Client\Client(), array());
}
public function testSetAndGetBufferSize()
{
$this->_plugin->setBufferSize(500);
$this->assertEquals(500, $this->_plugin->getBufferSize());
}
public function testAddDocument()
{
$doc = new \Solarium\Document\ReadWrite();
$doc->id = '123';
$doc->name = 'test';
$this->_plugin->addDocument($doc);
$this->assertEquals(array($doc), $this->_plugin->getDocuments());
}
public function testCreateDocument()
{
$data = array('id' => '123', 'name' => 'test');
$doc = new \Solarium\Document\ReadWrite($data);
$this->_plugin->createDocument($data);
$this->assertEquals(array($doc), $this->_plugin->getDocuments());
}
public function testAddDocuments()
{
$doc1 = new \Solarium\Document\ReadWrite();
$doc1->id = '123';
$doc1->name = 'test';
$doc2 = new \Solarium\Document\ReadWrite();
$doc2->id = '234';
$doc2->name = 'test2';
$docs = array($doc1, $doc2);
$this->_plugin->addDocuments($docs);
$this->assertEquals($docs, $this->_plugin->getDocuments());
}
public function testAddDocumentAutoFlush()
{
$observer = $this->getMock('Solarium\Plugin\BufferedAdd', array('flush'));
$observer->expects($this->once())->method('flush');
$observer->setBufferSize(1);
$doc1 = new \Solarium\Document\ReadWrite();
$doc1->id = '123';
$doc1->name = 'test';
$doc2 = new \Solarium\Document\ReadWrite();
$doc2->id = '234';
$doc2->name = 'test2';
$docs = array($doc1, $doc2);
$observer->addDocuments($docs);
}
public function testClear()
{
$doc = new \Solarium\Document\ReadWrite();
$doc->id = '123';
$doc->name = 'test';
$this->_plugin->addDocument($doc);
$this->_plugin->clear();
$this->assertEquals(array(), $this->_plugin->getDocuments());
}
public function testFlushEmptyBuffer()
{
$this->assertEquals(false, $this->_plugin->flush());
}
public function testFlush()
{
$data = array('id' => '123', 'name' => 'test');
$doc = new \Solarium\Document\ReadWrite($data);
$mockUpdate = $this->getMock('Solarium\Query\Update', array('addDocuments'));
$mockUpdate->expects($this->once())->method('addDocuments')->with($this->equalTo(array($doc)),$this->equalTo(true),$this->equalTo(12));
$mockClient = $this->getMock('Solarium\Client', array('createUpdate', 'update', 'triggerEvent'));
$mockClient->expects($this->exactly(2))->method('createUpdate')->will($this->returnValue($mockUpdate));
$mockClient->expects($this->once())->method('update')->will($this->returnValue('dummyResult'));
$mockClient->expects($this->exactly(2))->method('triggerEvent');
$plugin = new \Solarium\Plugin\BufferedAdd();
$plugin->init($mockClient, array());
$plugin->addDocument($doc);
$this->assertEquals('dummyResult', $plugin->flush(true,12));
}
public function testCommit()
{
$data = array('id' => '123', 'name' => 'test');
$doc = new \Solarium\Document\ReadWrite($data);
$mockUpdate = $this->getMock('Solarium\Query\Update', array('addDocuments', 'addCommit'));
$mockUpdate->expects($this->once())->method('addDocuments')->with($this->equalTo(array($doc)),$this->equalTo(true));
$mockUpdate->expects($this->once())->method('addCommit')->with($this->equalTo(false),$this->equalTo(true),$this->equalTo(false));
$mockClient = $this->getMock('Solarium\Client\Client', array('createUpdate', 'update', 'triggerEvent'));
$mockClient->expects($this->exactly(2))->method('createUpdate')->will($this->returnValue($mockUpdate));
$mockClient->expects($this->once())->method('update')->will($this->returnValue('dummyResult'));
$mockClient->expects($this->exactly(2))->method('triggerEvent');
$plugin = new \Solarium\Plugin\BufferedAdd();
$plugin->init($mockClient, array());
$plugin->addDocument($doc);
$this->assertEquals('dummyResult', $plugin->commit(true, false, true, false));
}
}
\ 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.
*/
namespace Solarium\Tests\Plugin;
class PrefetchIteratorTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Solarium\Plugin\PrefetchIterator
*/
protected $_plugin;
/**
* @var \Solarium\Client\Client
*/
protected $_client;
/**
* @var \Solarium\Query\Select\Select
*/
protected $_query;
public function setUp()
{
$this->_plugin = new \Solarium\Plugin\PrefetchIterator();
$this->_client = new \Solarium\Client\Client();
$this->_query = $this->_client->createSelect();
}
public function testSetAndGetPrefetch()
{
$this->_plugin->setPrefetch(120);
$this->assertEquals(120, $this->_plugin->getPrefetch());
}
public function testSetAndGetQuery()
{
$this->_plugin->setQuery($this->_query);
$this->assertEquals($this->_query, $this->_plugin->getQuery());
}
public function testCount()
{
$result = $this->_getResult();
$mockClient = $this->getMock('Solarium\Client\Client', array('execute'));
$mockClient->expects($this->exactly(1))->method('execute')->will($this->returnValue($result));
$this->_plugin->init($mockClient, array());
$this->_plugin->setQuery($this->_query);
$this->assertEquals(5, count($this->_plugin));
}
public function testIteratorAndRewind()
{
$result = $this->_getResult();
$mockClient = $this->getMock('Solarium\Client\Client', array('execute'));
$mockClient->expects($this->exactly(1))->method('execute')->will($this->returnValue($result));
$this->_plugin->init($mockClient, array());
$this->_plugin->setQuery($this->_query);
$results1 = array();
foreach($this->_plugin as $doc) {
$results1[] = $doc;
}
// the second foreach will trigger a rewind, this time include keys
$results2 = array();
foreach($this->_plugin as $key => $doc) {
$results2[$key] = $doc;
}
$this->assertEquals($result->getDocuments(), $results1);
$this->assertEquals($result->getDocuments(), $results2);
}
public function _getResult()
{
$numFound = 5;
$docs = array(
new \Solarium\Document\ReadOnly(array('id'=>1,'title'=>'doc1')),
new \Solarium\Document\ReadOnly(array('id'=>2,'title'=>'doc2')),
new \Solarium\Document\ReadOnly(array('id'=>3,'title'=>'doc3')),
new \Solarium\Document\ReadOnly(array('id'=>4,'title'=>'doc4')),
new \Solarium\Document\ReadOnly(array('id'=>5,'title'=>'doc5')),
);
return new SelectDummy(1, 12, $numFound, $docs, array());
}
}
class SelectDummy extends \Solarium\Result\Select\Select
{
protected $_parsed = true;
public function __construct($status, $queryTime, $numfound, $docs, $components)
{
$this->_numfound = $numfound;
$this->_documents = $docs;
$this->_components = $components;
$this->_queryTime = $queryTime;
$this->_status = $status;
}
}
\ No newline at end of file
...@@ -33,7 +33,15 @@ namespace Solarium\Tests\Query; ...@@ -33,7 +33,15 @@ namespace Solarium\Tests\Query;
class HelperTest extends \PHPUnit_Framework_TestCase class HelperTest extends \PHPUnit_Framework_TestCase
{ {
protected $_helper, $_query; /**
* @var Solarium_Query_Helper
*/
protected $_helper;
/**
* @var Solarium_Query_Select
*/
protected $_query;
public function setUp() public function setUp()
{ {
...@@ -187,6 +195,83 @@ class HelperTest extends \PHPUnit_Framework_TestCase ...@@ -187,6 +195,83 @@ class HelperTest extends \PHPUnit_Framework_TestCase
); );
} }
public function testFormatDateInputTimestamp()
{
$this->assertFalse(
$this->_helper->formatDate(strtotime('2011---')),
'Expects invalid strtotime/timestamp input (false) not to be accepted'
);
//allow negative dates.
$this->assertNotEquals(
false,
$this->_helper->formatDate(strtotime('2011-10-01')),
'Expects negative timestamp input to be accepted'
);
//@todo find out if we need to any test for php versions / platforms which do not support negative timestamp
$this->assertFalse(
$this->_helper->formatDate(strtotime('2010-31-02')),
'Expects invalid timestamp input (not in calendar) not to be accepted'
);
$this->assertEquals(
$this->_mockFormatDateOutput(strtotime('2011-10-01')),
$this->_helper->formatDate(strtotime('2011-10-01')),
'Expects formatDate with Timstamp input to output ISO8601 with stripped timezone'
);
}
public function testFormatDateInputString()
{
$this->assertFalse(
$this->_helper->formatDate('2011-13-31'),
'Expects an invalid date string input not to be accepted'
);
$this->assertEquals(
$this->_mockFormatDateOutput(strtotime('2011-10-01')),
$this->_helper->formatDate('2011-10-01'),
'Expects formatDate with String input to output ISO8601 with stripped timezone'
);
}
public function testFormatDateInputDateTime()
{
date_default_timezone_set("UTC"); // prevent timezone differences
$this->assertFalse(
$this->_helper->formatDate(new \stdClass()),
'Expect any other object not to be accepted'
);
$this->assertEquals(
$this->_mockFormatDateOutput(strtotime('2011-10-01')),
$this->_helper->formatDate(new \DateTime('2011-10-01')),
'Expects formatDate with DateTime input to output ISO8601 with stripped timezone'
);
}
public function testFormatDate()
{
//check if timezone is stripped
$expected = strtoupper('Z');
$actual = substr($this->_helper->formatDate(time()), 19, 20);
$this->assertEquals($expected, $actual, 'Expects last charachter to be uppercased Z');
$this->assertEquals(
$this->_mockFormatDateOutput(time()),
$this->_helper->formatDate(time())
);
}
protected function _mockFormatDateOutput($timestamp)
{
$date = new \DateTime('@'.$timestamp);
return strstr($date->format(\DateTime::ISO8601), '+', true) . 'Z';
}
public function testAssemble() public function testAssemble()
{ {
// test single basic placeholder // test single basic placeholder
......
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