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

Updated unittests for the reorganized library files. Also added use statements...

Updated unittests for the reorganized library files. Also added use statements for namespaces and added a few tests.
parent 8afa3f4e
......@@ -30,71 +30,73 @@
*/
namespace Solarium\Tests;
use Solarium\Client;
class VersionTest extends \PHPUnit_Framework_TestCase
class ClientTest extends \PHPUnit_Framework_TestCase
{
public function testVersion()
{
$version = \Solarium\Version::VERSION;
$version = Client::VERSION;
$this->assertNotNull($version);
}
public function testCheckExact()
{
$this->assertTrue(
\Solarium\Version::checkExact(\Solarium\Version::VERSION)
Client::checkExact(Client::VERSION)
);
}
public function testCheckExactPartial()
{
$this->assertTrue(
\Solarium\Version::checkExact(substr(\Solarium\Version::VERSION,0,1))
Client::checkExact(substr(Client::VERSION,0,1))
);
}
public function testCheckExactLower()
{
$this->assertFalse(
\Solarium\Version::checkExact('0.1')
Client::checkExact('0.1')
);
}
public function testCheckExactHigher()
{
$this->assertFalse(
\Solarium\Version::checkExact('99.0')
Client::checkExact('99.0')
);
}
public function testCheckMinimal()
{
$this->assertTrue(
\Solarium\Version::checkMinimal(\Solarium\Version::VERSION)
Client::checkMinimal(Client::VERSION)
);
}
public function testCheckMinimalPartial()
{
$version = substr(\Solarium\Version::VERSION,0,1);
$version = substr(Client::VERSION,0,1);
$this->assertTrue(
\Solarium\Version::checkMinimal($version)
Client::checkMinimal($version)
);
}
public function testCheckMinimalLower()
{
$this->assertTrue(
\Solarium\Version::checkMinimal('0.1.0')
Client::checkMinimal('0.1.0')
);
}
public function testCheckMinimalHigher()
{
$this->assertFalse(
\Solarium\Version::checkMinimal('99.0')
Client::checkMinimal('99.0')
);
}
......
......@@ -29,18 +29,22 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\Client\Adapter;
namespace Solarium\Tests\Core\Client\Adapter;
use Solarium\Core\Client\Adapter\Adapter;
use Solarium\Core\Client\Request;
use Solarium\Core\Exception;
use Solarium\Core\Client\HttpException;
class AdapterTest extends \PHPUnit_Framework_TestCase
{
/**
* @var TestAdapter
*/
protected $_adapter;
protected $adapter;
public function setUp()
{
$this->_adapter = new TestAdapter();
$this->adapter = new TestAdapter();
}
public function testConfigMode()
......@@ -52,66 +56,66 @@ class AdapterTest extends \PHPUnit_Framework_TestCase
'core' => 'mycore',
'timeout' => 3,
);
$this->_adapter->setOptions($options);
$this->adapter->setOptions($options);
$options['path'] = '/mysolr'; //expected trimming of trailing slash
$this->assertEquals($options, $this->_adapter->getOptions());
$this->assertEquals($options, $this->adapter->getOptions());
}
public function testSetAndGetHost()
{
$this->_adapter->setHost('myhost');
$this->assertEquals('myhost', $this->_adapter->getHost());
$this->adapter->setHost('myhost');
$this->assertEquals('myhost', $this->adapter->getHost());
}
public function testSetAndGetPort()
{
$this->_adapter->setPort(8080);
$this->assertEquals(8080, $this->_adapter->getPort());
$this->adapter->setPort(8080);
$this->assertEquals(8080, $this->adapter->getPort());
}
public function testSetAndGetPath()
{
$this->_adapter->setPath('/mysolr');
$this->assertEquals('/mysolr', $this->_adapter->getPath());
$this->adapter->setPath('/mysolr');
$this->assertEquals('/mysolr', $this->adapter->getPath());
}
public function testSetAndGetPathWithTrailingSlash()
{
$this->_adapter->setPath('/mysolr/');
$this->assertEquals('/mysolr', $this->_adapter->getPath());
$this->adapter->setPath('/mysolr/');
$this->assertEquals('/mysolr', $this->adapter->getPath());
}
public function testSetAndGetCore()
{
$this->_adapter->setCore('core1');
$this->assertEquals('core1', $this->_adapter->getCore());
$this->adapter->setCore('core1');
$this->assertEquals('core1', $this->adapter->getCore());
}
public function testSetAndGetTimeout()
{
$this->_adapter->setTimeout(7);
$this->assertEquals(7, $this->_adapter->getTimeout());
$this->adapter->setTimeout(7);
$this->assertEquals(7, $this->adapter->getTimeout());
}
public function testGetBaseUri()
{
$this->_adapter->setHost('myserver')->setPath('/mypath')->setPort(123);
$this->adapter->setHost('myserver')->setPath('/mypath')->setPort(123);
$this->assertEquals('http://myserver:123/mypath/', $this->_adapter->getBaseUri());
$this->assertEquals('http://myserver:123/mypath/', $this->adapter->getBaseUri());
}
public function testGetBaseUriWithCore()
{
$this->_adapter->setHost('myserver')->setPath('/mypath')->setPort(123)->setCore('mycore');
$this->adapter->setHost('myserver')->setPath('/mypath')->setPort(123)->setCore('mycore');
$this->assertEquals('http://myserver:123/mypath/mycore/', $this->_adapter->getBaseUri());
$this->assertEquals('http://myserver:123/mypath/mycore/', $this->adapter->getBaseUri());
}
}
class TestAdapter extends \Solarium\Client\Adapter\Adapter
class TestAdapter extends Adapter
{
public function execute($request)
......
......@@ -29,14 +29,18 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\Client\Adapter;
namespace Solarium\Tests\Core\Client\Adapter;
use Solarium\Core\Client\Adapter\Curl as CurlAdapter;
use Solarium\Core\Client\Request;
use Solarium\Core\Exception;
use Solarium\Core\Client\HttpException;
class CurlTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Client\Adapter\Curl
* @var CurlAdapter
*/
protected $_adapter;
protected $adapter;
public function setUp()
{
......@@ -44,7 +48,7 @@ class CurlTest extends \PHPUnit_Framework_TestCase
$this->markTestSkipped('Curl not available, skipping Curl adapter tests');
}
$this->_adapter = new \Solarium\Client\Adapter\Curl();
$this->adapter = new CurlAdapter();
}
public function testCheck()
......@@ -53,13 +57,13 @@ class CurlTest extends \PHPUnit_Framework_TestCase
$headers = array('X-dummy: data');
// this should be ok, no exception
$this->_adapter->check($data, $headers);
$this->adapter->check($data, $headers);
$data = '';
$headers = array();
$this->setExpectedException('Solarium\Exception');
$this->_adapter->check($data, $headers);
$this->setExpectedException('Solarium\Core\Exception');
$this->adapter->check($data, $headers);
}
public function testExecute()
......@@ -68,11 +72,11 @@ class CurlTest extends \PHPUnit_Framework_TestCase
$body = 'data';
$data = array($body, $headers);
$request = new \Solarium\Client\Request();
$request = new Request();
$mock = $this->getMock('Solarium\Client\Adapter\Curl', array('_getData'));
$mock = $this->getMock('Solarium\Core\Client\Adapter\Curl', array('getData'));
$mock->expects($this->once())
->method('_getData')
->method('getData')
->with($request)
->will($this->returnValue($data));
......
......@@ -29,30 +29,34 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\Client\Adapter;
namespace Solarium\Tests\Core\Client\Adapter;
use Solarium\Core\Client\Adapter\Http as HttpAdapter;
use Solarium\Core\Client\Request;
use Solarium\Core\Exception;
use Solarium\Core\Client\HttpException;
class HttpTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Client\Adapter\Http
* @var HttpAdapter
*/
protected $_adapter;
protected $adapter;
public function setUp()
{
$this->_adapter = new \Solarium\Client\Adapter\Http();
$this->adapter = new HttpAdapter();
}
public function testExecute()
{
$data = 'test123';
$request = new \Solarium\Client\Request();
$request->setMethod(\Solarium\Client\Request::METHOD_GET);
$request = new Request();
$request->setMethod(Request::METHOD_GET);
$mock = $this->getMock('Solarium\Client\Adapter\Http', array('_getData','check'));
$mock = $this->getMock('Solarium\Core\Client\Adapter\Http', array('getData','check'));
$mock->expects($this->once())
->method('_getData')
->method('getData')
->with($this->equalTo('http://127.0.0.1:8983/solr/?'), $this->isType('resource'))
->will($this->returnValue(array($data, array('HTTP 1.1 200 OK'))));
......@@ -63,31 +67,31 @@ class HttpTest extends \PHPUnit_Framework_TestCase
{
$data = 'test123';
$request = new \Solarium\Client\Request();
$request = new Request();
$mock = $this->getMock('Solarium\Client\Adapter\Http', array('_getData','check'));
$mock = $this->getMock('Solarium\Core\Client\Adapter\Http', array('getData','check'));
$mock->expects($this->once())
->method('_getData')
->method('getData')
->with($this->equalTo('http://127.0.0.1:8983/solr/?'), $this->isType('resource'))
->will($this->returnValue(array($data, array('HTTP 1.1 200 OK'))));
$mock->expects($this->once())
->method('check')
->will($this->throwException(new \Solarium\Client\HttpException("HTTP request failed")));
->will($this->throwException(new HttpException("HTTP request failed")));
$this->setExpectedException('Solarium\Client\HttpException');
$this->setExpectedException('Solarium\Core\Client\HttpException');
$mock->execute($request);
}
public function testCheckError()
{
$this->setExpectedException('Solarium\Client\HttpException');
$this->_adapter->check(false, array());
$this->setExpectedException('Solarium\Core\Client\HttpException');
$this->adapter->check(false, array());
}
public function testCheckOk()
{
$value = $this->_adapter->check('dummydata',array('HTTP 1.1 200 OK'));
$value = $this->adapter->check('dummydata',array('HTTP 1.1 200 OK'));
$this->assertEquals(
null,
......@@ -98,13 +102,13 @@ class HttpTest extends \PHPUnit_Framework_TestCase
public function testCreateContextGetRequest()
{
$timeout = 13;
$method = \Solarium\Client\Request::METHOD_HEAD;
$method = Request::METHOD_HEAD;
$request = new \Solarium\Client\Request();
$request = new Request();
$request->setMethod($method);
$this->_adapter->setTimeout($timeout);
$this->adapter->setTimeout($timeout);
$context = $this->_adapter->createContext($request);
$context = $this->adapter->createContext($request);
$this->assertEquals(
array('http' => array('method' => $method, 'timeout' => $timeout)),
......@@ -115,17 +119,17 @@ class HttpTest extends \PHPUnit_Framework_TestCase
public function testCreateContextWithHeaders()
{
$timeout = 13;
$method = \Solarium\Client\Request::METHOD_HEAD;
$method = Request::METHOD_HEAD;
$header1 = 'Content-Type: text/xml; charset=UTF-8';
$header2 = 'X-MyHeader: dummyvalue';
$request = new \Solarium\Client\Request();
$request = new Request();
$request->setMethod($method);
$request->addHeader($header1);
$request->addHeader($header2);
$this->_adapter->setTimeout($timeout);
$this->adapter->setTimeout($timeout);
$context = $this->_adapter->createContext($request);
$context = $this->adapter->createContext($request);
$this->assertEquals(
array('http' => array('method' => $method, 'timeout' => $timeout, 'header' => $header1."\r\n".$header2)),
......@@ -136,15 +140,15 @@ class HttpTest extends \PHPUnit_Framework_TestCase
public function testCreateContextPostRequest()
{
$timeout = 13;
$method = \Solarium\Client\Request::METHOD_POST;
$method = Request::METHOD_POST;
$data = 'test123';
$request = new \Solarium\Client\Request();
$request = new Request();
$request->setMethod($method);
$request->setRawData($data);
$this->_adapter->setTimeout($timeout);
$this->adapter->setTimeout($timeout);
$context = $this->_adapter->createContext($request);
$context = $this->adapter->createContext($request);
$this->assertEquals(
array('http' => array('method' => $method, 'timeout' => $timeout, 'content' => $data, 'header' => 'Content-Type: text/xml; charset=UTF-8')),
......
......@@ -29,14 +29,18 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\Client\Adapter;
namespace Solarium\Tests\Core\Client\Adapter;
use Solarium\Core\Client\Adapter\PeclHttp as PeclHttpAdapter;
use Solarium\Core\Client\Request;
use Solarium\Core\Exception;
use Solarium\Core\Client\HttpException;
class PeclHttpTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Client\Adapter\PeclHttp
* @var PeclHttpAdapter
*/
protected $_adapter;
protected $adapter;
public function setUp()
{
......@@ -44,7 +48,7 @@ class PeclHttpTest extends \PHPUnit_Framework_TestCase
$this->markTestSkipped('Pecl_http not available, skipping PeclHttp adapter tests');
}
$this->_adapter = new \Solarium\Client\Adapter\PeclHttp(array('timeout' => 10));
$this->adapter = new PeclHttpAdapter(array('timeout' => 10));
}
/**
......@@ -53,9 +57,9 @@ class PeclHttpTest extends \PHPUnit_Framework_TestCase
public function testToHttpRequestWithMethod($request, $method, $support)
{
try {
$httpRequest = $this->_adapter->toHttpRequest($request);
$httpRequest = $this->adapter->toHttpRequest($request);
$this->assertEquals($httpRequest->getMethod(), $method);
} catch (\Solarium\Exception $e) {
} catch (Exception $e) {
if ($support) {
$this->fail("Unsupport method: {$request->getMethod()}");
}
......@@ -67,15 +71,15 @@ class PeclHttpTest extends \PHPUnit_Framework_TestCase
// prevents undefined constants errors
if (function_exists('http_get')) {
$methods = array(
\Solarium\Client\Request::METHOD_GET => array(
Request::METHOD_GET => array(
'method' => HTTP_METH_GET,
'support' => true
),
\Solarium\Client\Request::METHOD_POST => array(
Request::METHOD_POST => array(
'method' => HTTP_METH_POST,
'support' => true
),
\Solarium\Client\Request::METHOD_HEAD => array(
Request::METHOD_HEAD => array(
'method' => HTTP_METH_HEAD,
'support' => true
),
......@@ -89,8 +93,9 @@ class PeclHttpTest extends \PHPUnit_Framework_TestCase
),
);
$data = array();
foreach ($methods as $method => $options) {
$request = new \Solarium\Client\Request;
$request = new Request;
$request->setMethod($method);
$data[] = array_merge(array($request), $options);
}
......@@ -101,14 +106,14 @@ class PeclHttpTest extends \PHPUnit_Framework_TestCase
public function testToHttpRequestWithHeaders()
{
$request = new \Solarium\Client\Request(array(
$request = new Request(array(
'header' => array(
'Content-Type: application/json',
'User-Agent: Foo'
)
));
$httpRequest = $this->_adapter->toHttpRequest($request);
$httpRequest = $this->adapter->toHttpRequest($request);
$this->assertEquals(array(
'timeout' => 10,
'headers' => array(
......@@ -120,10 +125,10 @@ class PeclHttpTest extends \PHPUnit_Framework_TestCase
public function testToHttpRequestWithDefaultContentType()
{
$request = new \Solarium\Client\Request;
$request->setMethod(\Solarium\Client\Request::METHOD_POST);
$request = new Request;
$request->setMethod(Request::METHOD_POST);
$httpRequest = $this->_adapter->toHttpRequest($request);
$httpRequest = $this->adapter->toHttpRequest($request);
$this->assertEquals(array(
'timeout' => 10,
'headers' => array(
......@@ -143,13 +148,13 @@ X-Foo: test
$body
EOF;
$request = new \Solarium\Client\Request();
$request = new Request();
$mockHttpRequest = $this->getMock('HttpRequest');
$mockHttpRequest->expects($this->once())
->method('send')
->will($this->returnValue(\HttpMessage::factory($data)));
$mock = $this->getMock('Solarium\Client\Adapter\PeclHttp', array('toHttpRequest'));
$mock = $this->getMock('Solarium\Core\Client\Adapter\PeclHttp', array('toHttpRequest'));
$mock->expects($this->once())
->method('toHttpRequest')
->with($request)
......@@ -162,13 +167,13 @@ EOF;
}
/**
* @expectedException Solarium\Client\HttpException
* @expectedException Solarium\Core\Client\HttpException
*/
public function testExecuteWithException()
{
$this->_adapter->setPort(-1); // this forces an error
$request = new \Solarium\Client\Request();
$this->_adapter->execute($request);
$this->adapter->setPort(-1); // this forces an error
$request = new Request();
$this->adapter->execute($request);
}
}
......@@ -29,14 +29,16 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\Client\Adapter;
namespace Solarium\Tests\Core\Client\Adapter;
use Solarium\Core\Client\Adapter\ZendHttp as ZendHttpAdapter;
use Solarium\Core\Client\Request;
class ZendHttpTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Client\Adapter\ZendHttp
* @var ZendHttpAdapter
*/
protected $_adapter;
protected $adapter;
public function setUp()
{
......@@ -46,7 +48,7 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
\Zend_Loader_Autoloader::getInstance();
$this->_adapter = new \Solarium\Client\Adapter\ZendHttp();
$this->adapter = new ZendHttpAdapter();
}
public function testForwardingToZendHttpInSetOptions()
......@@ -59,34 +61,34 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
->method('setConfig')
->with($this->equalTo($adapterOptions));
$this->_adapter->setZendHttp($mock);
$this->_adapter->setOptions($options);
$this->adapter->setZendHttp($mock);
$this->adapter->setOptions($options);
}
public function testSetAndGetZendHttp()
{
$dummy = new \stdClass();
$this->_adapter->setZendHttp($dummy);
$this->adapter->setZendHttp($dummy);
$this->assertEquals(
$dummy,
$this->_adapter->getZendHttp()
$this->adapter->getZendHttp()
);
}
public function testGetZendHttpAutoload()
{
$options = array('timeout' => 10, 'optionZ' => 123, 'options' => array('adapter' => 'Zend_Http_Client_Adapter_Curl'));
$this->_adapter->setOptions($options);
$this->adapter->setOptions($options);
$zendHttp = $this->_adapter->getZendHttp();
$zendHttp = $this->adapter->getZendHttp();
$this->assertThat($zendHttp, $this->isInstanceOf('Zend_Http_Client'));
}
public function testExecute()
{
$method = \Solarium\Client\Request::METHOD_GET;
$method = Request::METHOD_GET;
$rawData = 'xyz';
$responseData = 'abc';
$handler = 'myhandler';
......@@ -94,7 +96,7 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
'Content-Type: application/x-www-form-urlencoded'
);
$request = new \Solarium\Client\Request();
$request = new Request();
$request->setMethod($method);
$request->setHandler($handler);
$request->setHeaders($headers);
......@@ -119,8 +121,8 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
->method('request')
->will($this->returnValue($response));
$this->_adapter->setZendHttp($mock);
$adapterResponse = $this->_adapter->execute($request);
$this->adapter->setZendHttp($mock);
$adapterResponse = $this->adapter->execute($request);
$this->assertEquals(
$responseData,
......@@ -130,7 +132,7 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
public function testExecuteErrorResponse()
{
$request = new \Solarium\Client\Request();
$request = new Request();
$response = new \Zend_Http_Response(404, array(), '');
$mock = $this->getMock('Zend_Http_Client');
......@@ -138,17 +140,17 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
->method('request')
->will($this->returnValue($response));
$this->_adapter->setZendHttp($mock);
$this->adapter->setZendHttp($mock);
$this->setExpectedException('Solarium\Client\HttpException');
$this->_adapter->execute($request);
$this->setExpectedException('Solarium\Core\Client\HttpException');
$this->adapter->execute($request);
}
public function testExecuteHeadRequestReturnsNoData()
{
$request = new \Solarium\Client\Request();
$request->setMethod(\Solarium\Client\Request::METHOD_HEAD);
$request = new Request();
$request->setMethod(Request::METHOD_HEAD);
$response = new \Zend_Http_Response(200, array('status' => 'HTTP 1.1 200 OK'), 'data');
$mock = $this->getMock('Zend_Http_Client');
......@@ -156,8 +158,8 @@ class ZendHttpTest extends \PHPUnit_Framework_TestCase
->method('request')
->will($this->returnValue($response));
$this->_adapter->setZendHttp($mock);
$response = $this->_adapter->execute($request);
$this->adapter->setZendHttp($mock);
$response = $this->adapter->execute($request);
$this->assertEquals(
'',
......
......@@ -29,14 +29,15 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\Client;
namespace Solarium\Tests\Core\Client;
use Solarium\Core\Client\HttpException;
class HttpExceptionTest extends \PHPUnit_Framework_TestCase
{
public function testConstructor()
{
$exception = new \Solarium\Client\HttpException('message text', 123);
$exception = new HttpException('message text', 123);
$this->assertEquals(
'Solr HTTP error: message text (123)',
......@@ -46,7 +47,7 @@ class HttpExceptionTest extends \PHPUnit_Framework_TestCase
public function testGetMessage()
{
$exception = new \Solarium\Client\HttpException('message text', 123);
$exception = new HttpException('message text', 123);
$this->assertEquals(
'message text',
......@@ -56,7 +57,7 @@ class HttpExceptionTest extends \PHPUnit_Framework_TestCase
public function testConstructorNoCode()
{
$exception = new \Solarium\Client\HttpException('message text');
$exception = new HttpException('message text');
$this->assertEquals(
'Solr HTTP error: message text',
......
......@@ -29,51 +29,52 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\Client;
namespace Solarium\Tests\Core\Client;
use Solarium\Core\Client\Response;
class ResponseTest extends \PHPUnit_Framework_TestCase
{
protected $_headers, $_data;
protected $headers, $data;
/**
* @var Solarium\Client\Response
* @var Response
*/
protected $_response;
protected $response;
public function setUp()
{
$this->_headers = array('HTTP/1.0 304 Not Modified');
$this->_data = '{"responseHeader":{"status":0,"QTime":1,"params":{"wt":"json","q":"mdsfgdsfgdf"}},"response":{"numFound":0,"start":0,"docs":[]}}';
$this->_response = new \Solarium\Client\Response($this->_data, $this->_headers);
$this->headers = array('HTTP/1.0 304 Not Modified');
$this->data = '{"responseHeader":{"status":0,"QTime":1,"params":{"wt":"json","q":"mdsfgdsfgdf"}},"response":{"numFound":0,"start":0,"docs":[]}}';
$this->response = new Response($this->data, $this->headers);
}
public function testGetStatusCode()
{
$this->assertEquals(304, $this->_response->getStatusCode());
$this->assertEquals(304, $this->response->getStatusCode());
}
public function testGetStatusMessage()
{
$this->assertEquals('Not Modified', $this->_response->getStatusMessage());
$this->assertEquals('Not Modified', $this->response->getStatusMessage());
}
public function testGetHeaders()
{
$this->assertEquals($this->_headers, $this->_response->getHeaders());
$this->assertEquals($this->headers, $this->response->getHeaders());
}
public function testGetBody()
{
$this->assertEquals($this->_data, $this->_response->getBody());
$this->assertEquals($this->data, $this->response->getBody());
}
public function testMissingHeader()
{
$headers = array();
$this->setExpectedException('Solarium\Exception');
new \Solarium\Client\Response($this->_data, $headers);
$this->setExpectedException('Solarium\Core\Exception');
new Response($this->data, $headers);
}
}
\ No newline at end of file
......@@ -29,7 +29,10 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests;
namespace Solarium\Tests\Core;
use Solarium\Core\Client\Client;
use Solarium\Core\Exception;
use Solarium\Core\Configurable;
class ConfigurableTest extends \PHPUnit_Framework_TestCase
{
......@@ -76,11 +79,11 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($expectedOptions, $configTest->getOptions());
}
public function testConstructorWithInvalidConfig()
{
$this->setExpectedException('Solarium\Exception');
new \Solarium\Client\Client('invalid');
$this->setExpectedException('Solarium\Core\Exception');
new Client('invalid');
}
public function testGetOption()
......@@ -97,7 +100,7 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase
public function testInitialisation()
{
$this->setExpectedException('Solarium\Exception');
$this->setExpectedException('Solarium\Core\Exception');
new ConfigTestInit;
}
......@@ -124,10 +127,10 @@ class ConfigurableTest extends \PHPUnit_Framework_TestCase
}
}
class ConfigTest extends \Solarium\Configurable
class ConfigTest extends Configurable
{
protected $_options = array(
protected $options = array(
'option1' => 1,
'option2' => 'value 2',
);
......@@ -137,9 +140,9 @@ class ConfigTest extends \Solarium\Configurable
class ConfigTestInit extends ConfigTest
{
protected function _init()
protected function init()
{
throw new \Solarium\Exception('test init');
throw new Exception('test init');
}
}
......
......@@ -29,55 +29,62 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\Plugin;
namespace Solarium\Tests\Core;
use Solarium\Core\Plugin;
class AbstractTest extends \PHPUnit_Framework_TestCase
class PluginTest extends \PHPUnit_Framework_TestCase
{
protected $_plugin, $_client, $_options;
/**
* @var Plugin
*/
protected $plugin;
protected $client;
protected $options;
public function setUp()
{
$this->_client = 'dummy';
$this->_options = array('option1' => 1);
$this->_plugin = new MyPlugin();
$this->_plugin->init($this->_client, $this->_options);
$this->client = 'dummy';
$this->options = array('option1' => 1);
$this->plugin = new MyPlugin();
$this->plugin->initPlugin($this->client, $this->options);
}
public function testConstructor()
{
$this->assertEquals(
$this->_client,
$this->_plugin->getClient()
$this->client,
$this->plugin->getClient()
);
$this->assertEquals(
$this->_options,
$this->_plugin->getOptions()
$this->options,
$this->plugin->getOptions()
);
}
public function testEventHooksEmpty()
{
$this->assertEquals(null, $this->_plugin->preCreateRequest(null));
$this->assertEquals(null, $this->_plugin->postCreateRequest(null,null));
$this->assertEquals(null, $this->_plugin->preExecuteRequest(null));
$this->assertEquals(null, $this->_plugin->postExecuteRequest(null,null));
$this->assertEquals(null, $this->_plugin->preExecute(null));
$this->assertEquals(null, $this->_plugin->postExecute(null,null));
$this->assertEquals(null, $this->_plugin->preCreateResult(null,null));
$this->assertEquals(null, $this->_plugin->postCreateResult(null,null,null));
$this->assertEquals(null, $this->_plugin->preCreateQuery(null,null));
$this->assertEquals(null, $this->_plugin->postCreateQuery(null,null,null));
$this->assertEquals(null, $this->plugin->preCreateRequest(null));
$this->assertEquals(null, $this->plugin->postCreateRequest(null,null));
$this->assertEquals(null, $this->plugin->preExecuteRequest(null));
$this->assertEquals(null, $this->plugin->postExecuteRequest(null,null));
$this->assertEquals(null, $this->plugin->preExecute(null));
$this->assertEquals(null, $this->plugin->postExecute(null,null));
$this->assertEquals(null, $this->plugin->preCreateResult(null,null));
$this->assertEquals(null, $this->plugin->postCreateResult(null,null,null));
$this->assertEquals(null, $this->plugin->preCreateQuery(null,null));
$this->assertEquals(null, $this->plugin->postCreateQuery(null,null,null));
}
}
class MyPlugin extends \Solarium\Plugin\AbstractPlugin{
class MyPlugin extends Plugin{
public function getClient()
{
return $this->_client;
return $this->client;
}
}
\ No newline at end of file
......@@ -29,7 +29,8 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\Query;
namespace Solarium\Tests\Core\Query;
use Solarium\Core\Query\Query;
class QueryTest extends \PHPUnit_Framework_TestCase
{
......@@ -54,7 +55,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
$helper = $query->getHelper();
$this->assertEquals(
'Solarium\Query\Helper',
'Solarium\Core\Query\Helper',
get_class($helper)
);
}
......@@ -74,7 +75,7 @@ class QueryTest extends \PHPUnit_Framework_TestCase
}
class TestQuery extends \Solarium\Query\Query
class TestQuery extends Query
{
public function getType()
......
......@@ -29,26 +29,28 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\Client;
namespace Solarium\Tests\Core\Query;
use Solarium\Core\Query\RequestBuilder;
use Solarium\Query\Select\Query\Query as SelectQuery;
class RequestBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var TestRequestBuilder
*/
protected $_builder;
protected $builder;
public function setup()
{
$this->_builder = new TestRequestBuilder;
$this->builder = new TestRequestBuilder;
}
public function testBuild()
{
$query = new \Solarium\QueryType\Select\Query\Query;
$query = new SelectQuery;
$query->addParam('p1','v1');
$query->addParam('p2','v2');
$request = $this->_builder->build($query);
$request = $this->builder->build($query);
$this->assertEquals(
'select?p1=v1&p2=v2&wt=json',
......@@ -62,7 +64,7 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(
'{!tag=mytag ex=exclude1,exclude2}myValue',
$this->_builder->renderLocalParams('myValue', $myParams)
$this->builder->renderLocalParams('myValue', $myParams)
);
}
......@@ -70,12 +72,52 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
{
$this->assertEquals(
'myValue',
$this->_builder->renderLocalParams('myValue')
$this->builder->renderLocalParams('myValue')
);
}
public function testBoolAttribWithNull()
{
$this->assertEquals(
'',
$this->builder->boolAttrib('myattrib', null)
);
}
public function testBoolAttribWithString()
{
$this->assertEquals(
' myattrib="true"',
$this->builder->boolAttrib('myattrib', 'true')
);
}
public function testBoolAttribWithBool()
{
$this->assertEquals(
' myattrib="false"',
$this->builder->boolAttrib('myattrib', false)
);
}
public function testAttribWithNull()
{
$this->assertEquals(
'',
$this->builder->attrib('myattrib', null)
);
}
public function testAttribWithString()
{
$this->assertEquals(
' myattrib="myvalue"',
$this->builder->attrib('myattrib', 'myvalue')
);
}
}
class TestRequestBuilder extends \Solarium\Client\RequestBuilder{
class TestRequestBuilder extends RequestBuilder{
}
\ No newline at end of file
......@@ -29,60 +29,66 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\Result;
namespace Solarium\Tests\Core\Query\Result;
use Solarium\Core\Client\Client;
use Solarium\Core\Client\Response;
use Solarium\Core\Query\Result\QueryType as QueryTypeResult;
use Solarium\Query\Select\Query\Query as SelectQuery;
use Solarium\Query\Update\Query\Query as UpdateQuery;
class QueryTypeTest extends \PHPUnit_Framework_TestCase
{
/**
* @var QueryTypeDummy
*/
protected $_result;
protected $result;
public function setUp()
{
$client = new \Solarium\Client\Client;
$query = new \Solarium\QueryType\Update\Query\Query;
$response = new \Solarium\Client\Response('{"responseHeader":{"status":1,"QTime":12}}',array('HTTP 1.1 200 OK'));
$this->_result = new QueryTypeDummy($client, $query, $response);
$client = new Client;
$query = new UpdateQuery;
$response = new Response('{"responseHeader":{"status":1,"QTime":12}}',array('HTTP 1.1 200 OK'));
$this->result = new QueryTypeDummy($client, $query, $response);
}
public function testParseResponse()
{
$client = new \Solarium\Client\Client;
$client = new Client;
$query = new QueryDummyTest;
$response = new \Solarium\Client\Response('{"responseHeader":{"status":1,"QTime":12}}',array('HTTP 1.1 200 OK'));
$response = new Response('{"responseHeader":{"status":1,"QTime":12}}',array('HTTP 1.1 200 OK'));
$result = new QueryTypeDummy($client, $query, $response);
$this->setExpectedException('Solarium\Exception');
$this->setExpectedException('Solarium\Core\Exception');
$result->parse();
}
public function testParseResponseInvalidQuerytype()
{
$this->_result->parse();
$this->result->parse();
}
public function testParseLazyLoading()
{
$this->assertEquals(0,$this->_result->parseCount);
$this->assertEquals(0,$this->result->parseCount);
$this->_result->parse();
$this->assertEquals(1,$this->_result->parseCount);
$this->result->parse();
$this->assertEquals(1,$this->result->parseCount);
$this->_result->parse();
$this->assertEquals(1,$this->_result->parseCount);
$this->result->parse();
$this->assertEquals(1,$this->result->parseCount);
}
public function testMapData()
{
$this->_result->mapData(array('dummyvar' => 'dummyvalue'));
$this->result->mapData(array('dummyvar' => 'dummyvalue'));
$this->assertEquals('dummyvalue',$this->_result->getVar('dummyvar'));
$this->assertEquals('dummyvalue',$this->result->getVar('dummyvar'));
}
}
class QueryDummyTest extends \Solarium\QueryType\Select\Query\Query
class QueryDummyTest extends SelectQuery
{
public function getType()
{
......@@ -90,30 +96,25 @@ class QueryDummyTest extends \Solarium\QueryType\Select\Query\Query
}
}
class QueryTypeDummy extends \Solarium\Result\QueryType
class QueryTypeDummy extends QueryTypeResult
{
public $parseCount = 0;
public function parse()
{
$this->_parseResponse();
}
public function _mapData($data)
{
$this->parseCount++;
parent::_mapData($data);
$this->parseResponse();
}
public function mapData($data)
{
$this->_mapData($data);
$this->parseCount++;
parent::mapData($data);
}
public function getVar($name)
{
return $this->{'_'.$name};
return $this->$name;
}
}
\ No newline at end of file
......@@ -29,41 +29,50 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\Result;
namespace Solarium\Tests\Core\Query\Result;
use Solarium\Core\Client\Client;
use Solarium\Core\Client\Response;
use Solarium\Core\Query\Result\Result;
use Solarium\Query\Select\Query\Query as SelectQuery;
class ResultTest extends \PHPUnit_Framework_TestCase
{
protected $_client, $_query, $_response, $_result;
/**
* @var Result
*/
protected $result;
protected $client, $query, $response, $headers;
public function setUp()
{
$this->_client = new \Solarium\Client\Client();
$this->_query = new \Solarium\QueryType\Select\Query\Query();
$this->_headers = array('HTTP/1.0 304 Not Modified');
$this->client = new Client();
$this->query = new SelectQuery();
$this->headers = array('HTTP/1.0 304 Not Modified');
$data = '{"responseHeader":{"status":0,"QTime":1,"params":{"wt":"json","q":"xyz"}},"response":{"numFound":0,"start":0,"docs":[]}}';
$this->_response = new \Solarium\Client\Response($data, $this->_headers);
$this->response = new Response($data, $this->headers);
$this->_result = new \Solarium\Result\Result($this->_client, $this->_query, $this->_response);
$this->result = new Result($this->client, $this->query, $this->response);
}
public function testResultWithErrorResponse()
{
$headers = array('HTTP/1.0 404 Not Found');
$response = new \Solarium\Client\Response('', $headers);
$response = new Response('', $headers);
$this->setExpectedException('Solarium\Exception');
new \Solarium\Result\Result($this->_client, $this->_query, $response);
$this->setExpectedException('Solarium\Core\Exception');
new Result($this->client, $this->query, $response);
}
public function testGetResponse()
{
$this->assertEquals($this->_response, $this->_result->getResponse());
$this->assertEquals($this->response, $this->result->getResponse());
}
public function testGetQuery()
{
$this->assertEquals($this->_query, $this->_result->getQuery());
$this->assertEquals($this->query, $this->result->getQuery());
}
public function testGetData()
......@@ -73,17 +82,17 @@ class ResultTest extends \PHPUnit_Framework_TestCase
'response' => array('numFound' => 0, 'start' => 0, 'docs' => array())
);
$this->assertEquals($data, $this->_result->getData());
$this->assertEquals($data, $this->result->getData());
}
public function testGetInvalidData()
{
$data = 'invalid';
$this->_response = new \Solarium\Client\Response($data, $this->_headers);
$this->_result = new \Solarium\Result\Result($this->_client, $this->_query, $this->_response);
$this->response = new Response($data, $this->headers);
$this->result = new Result($this->client, $this->query, $this->response);
$this->setExpectedException('Solarium\Exception');
$this->_result->getData();
$this->setExpectedException('Solarium\Core\Exception');
$this->result->getData();
}
}
\ No newline at end of file
......@@ -30,25 +30,27 @@
*/
namespace Solarium\Tests\Plugin;
use Solarium\QueryType\Update\Query\Document;
use Solarium\Query\Update\Query\Document;
use Solarium\Plugin\BufferedAdd;
use Solarium\Core\Client\Client;
class BufferedAddTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium_Plugin_BufferedAdd
* @var BufferedAdd
*/
protected $_plugin;
protected $plugin;
public function setUp()
{
$this->_plugin = new \Solarium\Plugin\BufferedAdd();
$this->_plugin->init(new \Solarium\Client\Client(), array());
$this->plugin = new BufferedAdd();
$this->plugin->initPlugin(new Client(), array());
}
public function testSetAndGetBufferSize()
{
$this->_plugin->setBufferSize(500);
$this->assertEquals(500, $this->_plugin->getBufferSize());
$this->plugin->setBufferSize(500);
$this->assertEquals(500, $this->plugin->getBufferSize());
}
public function testAddDocument()
......@@ -57,9 +59,9 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
$doc->id = '123';
$doc->name = 'test';
$this->_plugin->addDocument($doc);
$this->plugin->addDocument($doc);
$this->assertEquals(array($doc), $this->_plugin->getDocuments());
$this->assertEquals(array($doc), $this->plugin->getDocuments());
}
public function testCreateDocument()
......@@ -67,9 +69,9 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
$data = array('id' => '123', 'name' => 'test');
$doc = new Document($data);
$this->_plugin->createDocument($data);
$this->plugin->createDocument($data);
$this->assertEquals(array($doc), $this->_plugin->getDocuments());
$this->assertEquals(array($doc), $this->plugin->getDocuments());
}
public function testAddDocuments()
......@@ -84,9 +86,9 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
$docs = array($doc1, $doc2);
$this->_plugin->addDocuments($docs);
$this->plugin->addDocuments($docs);
$this->assertEquals($docs, $this->_plugin->getDocuments());
$this->assertEquals($docs, $this->plugin->getDocuments());
}
public function testAddDocumentAutoFlush()
......@@ -114,15 +116,15 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
$doc->id = '123';
$doc->name = 'test';
$this->_plugin->addDocument($doc);
$this->_plugin->clear();
$this->plugin->addDocument($doc);
$this->plugin->clear();
$this->assertEquals(array(), $this->_plugin->getDocuments());
$this->assertEquals(array(), $this->plugin->getDocuments());
}
public function testFlushEmptyBuffer()
{
$this->assertEquals(false, $this->_plugin->flush());
$this->assertEquals(false, $this->plugin->flush());
}
public function testFlush()
......@@ -130,16 +132,16 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
$data = array('id' => '123', 'name' => 'test');
$doc = new Document($data);
$mockUpdate = $this->getMock('Solarium\Query\Update', array('addDocuments'));
$mockUpdate = $this->getMock('Solarium\Query\Update\Query\Query', 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 = $this->getMock('Solarium\Core\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 = new BufferedAdd();
$plugin->initPlugin($mockClient, array());
$plugin->addDocument($doc);
$this->assertEquals('dummyResult', $plugin->flush(true,12));
......@@ -150,17 +152,17 @@ class BufferedAddTest extends \PHPUnit_Framework_TestCase
$data = array('id' => '123', 'name' => 'test');
$doc = new Document($data);
$mockUpdate = $this->getMock('Solarium\Query\Update', array('addDocuments', 'addCommit'));
$mockUpdate = $this->getMock('Solarium\Core\Query\Update\Query\Query', 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 = $this->getMock('Solarium\Core\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 = new BufferedAdd();
$plugin->initPlugin($mockClient, array());
$plugin->addDocument($doc);
$this->assertEquals('dummyResult', $plugin->commit(true, false, true, false));
......
......@@ -30,88 +30,89 @@
*/
namespace Solarium\Tests\Plugin\CustomizeRequest;
use Solarium\Plugin\CustomizeRequest\Customization;
class CustomizationTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Plugin\CustomizeRequest\Customization
* @var Customization
*/
protected $_instance;
protected $instance;
public function setUp()
{
$this->_instance = new \Solarium\Plugin\CustomizeRequest\Customization();
$this->instance = new Customization();
}
public function testSetAndGetKey()
{
$value = 'mykey';
$this->_instance->setKey($value);
$this->assertEquals($value, $this->_instance->getKey());
$this->instance->setKey($value);
$this->assertEquals($value, $this->instance->getKey());
}
public function testSetAndGetName()
{
$value = 'myname';
$this->_instance->setName($value);
$this->assertEquals($value, $this->_instance->getName());
$this->instance->setName($value);
$this->assertEquals($value, $this->instance->getName());
}
public function testSetAndGetType()
{
$value = 'mytype';
$this->_instance->setType($value);
$this->assertEquals($value, $this->_instance->getType());
$this->instance->setType($value);
$this->assertEquals($value, $this->instance->getType());
}
public function testSetAndGetValue()
{
$value = 'myvalue';
$this->_instance->setValue($value);
$this->assertEquals($value, $this->_instance->getValue());
$this->instance->setValue($value);
$this->assertEquals($value, $this->instance->getValue());
}
public function testSetAndGetPersistence()
{
$value = true;
$this->_instance->setPersistent($value);
$this->assertEquals($value, $this->_instance->getPersistent());
$this->instance->setPersistent($value);
$this->assertEquals($value, $this->instance->getPersistent());
}
public function testSetAndGetOverwrite()
{
$value = false;
$this->_instance->setOverwrite($value);
$this->assertEquals($value, $this->_instance->getOverwrite());
$this->instance->setOverwrite($value);
$this->assertEquals($value, $this->instance->getOverwrite());
}
public function testIsValid()
{
$this->_instance->setKey('mykey');
$this->_instance->setType('param');
$this->_instance->setName('myname');
$this->_instance->setValue('myvalue');
$this->assertTrue($this->_instance->isValid());
$this->instance->setKey('mykey');
$this->instance->setType('param');
$this->instance->setName('myname');
$this->instance->setValue('myvalue');
$this->assertTrue($this->instance->isValid());
}
public function testIsValidWithInvalidType()
{
$this->_instance->setKey('mykey');
$this->_instance->setType('mytype');
$this->_instance->setName('myname');
$this->_instance->setValue('myvalue');
$this->instance->setKey('mykey');
$this->instance->setType('mytype');
$this->instance->setName('myname');
$this->instance->setValue('myvalue');
$this->assertFalse($this->_instance->isValid());
$this->assertFalse($this->instance->isValid());
}
public function testIsValidWithMissingValue()
{
$this->_instance->setKey('mykey');
$this->_instance->setType('param');
$this->_instance->setName('myname');
$this->instance->setKey('mykey');
$this->instance->setType('param');
$this->instance->setName('myname');
$this->assertFalse($this->_instance->isValid());
$this->assertFalse($this->instance->isValid());
}
}
\ No newline at end of file
......@@ -30,6 +30,7 @@
*/
namespace Solarium\Tests\Plugin\Loadbalancer;
use Solarium\Plugin\Loadbalancer\WeightedRandomChoice;
class WeightedRandomChoiceTest extends \PHPUnit_Framework_TestCase
{
......@@ -38,7 +39,7 @@ class WeightedRandomChoiceTest extends \PHPUnit_Framework_TestCase
{
$choices = array('key1' => 1, 'key2' => 2, 'key3' => 3);
$randomizer = new \Solarium\Plugin\Loadbalancer\WeightedRandomChoice($choices);
$randomizer = new WeightedRandomChoice($choices);
$choice = $randomizer->getRandom();
$this->assertTrue(
......@@ -60,7 +61,7 @@ class WeightedRandomChoiceTest extends \PHPUnit_Framework_TestCase
$choices = array('key1' => 1, 'key2' => 1, 'key3' => 300);
$excludes = array('key3');
$randomizer = new \Solarium\Plugin\Loadbalancer\WeightedRandomChoice($choices);
$randomizer = new WeightedRandomChoice($choices);
$key = $randomizer->getRandom($excludes);
......@@ -72,9 +73,9 @@ class WeightedRandomChoiceTest extends \PHPUnit_Framework_TestCase
$choices = array('key1' => 1, 'key2' => 2, 'key3' => 3);
$excludes = array_keys($choices);
$randomizer = new \Solarium\Plugin\Loadbalancer\WeightedRandomChoice($choices);
$randomizer = new WeightedRandomChoice($choices);
$this->setExpectedException('Solarium\Exception');
$this->setExpectedException('Solarium\Core\Exception');
$randomizer->getRandom($excludes);
}
......
......@@ -30,62 +30,64 @@
*/
namespace Solarium\Tests\Plugin;
use Solarium\Plugin\ParallelExecution;
use Solarium\Core\Client\Client;
class ParallelExecutionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Solarium\Plugin\ParallelExecution
* @var ParallelExecution
*/
protected $_plugin;
protected $plugin;
public function setUp()
{
$this->_plugin = new \Solarium\Plugin\ParallelExecution();
$this->plugin = new ParallelExecution();
}
public function testAddAndGetQueries()
{
$client1 = new \Solarium\Client\Client();
$client2 = new \Solarium\Client\Client(array(
$client1 = new Client();
$client2 = new Client(array(
'adapter' => 'MyAdapter',
'adapteroptions' => array(
'host' => 'myhost',
)
)
);
$this->_plugin->init($client1, array());
$this->plugin->initPlugin($client1, array());
$query1 = $client1->createSelect()->setQuery('test1');
$query2 = $client1->createSelect()->setQuery('test2');
$this->_plugin->addQuery(1, $query1);
$this->_plugin->addQuery(2, $query2, $client2);
$this->plugin->addQuery(1, $query1);
$this->plugin->addQuery(2, $query2, $client2);
$this->assertEquals(
array(
1 => array('query' => $query1, 'client' => $client1),
2 => array('query' => $query2, 'client' => $client2),
),
$this->_plugin->getQueries()
$this->plugin->getQueries()
);
}
public function testClearQueries()
{
$client = new \Solarium\Client\Client();
$this->_plugin->init($client, array());
$client = new Client();
$this->plugin->initPlugin($client, array());
$query1 = $client->createSelect()->setQuery('test1');
$query2 = $client->createSelect()->setQuery('test2');
$this->_plugin->addQuery(1, $query1);
$this->_plugin->addQuery(2, $query2);
$this->_plugin->clearQueries();
$this->plugin->addQuery(1, $query1);
$this->plugin->addQuery(2, $query2);
$this->plugin->clearQueries();
$this->assertEquals(
array(),
$this->_plugin->getQueries()
$this->plugin->getQueries()
);
}
......
......@@ -30,37 +30,41 @@
*/
namespace Solarium\Tests\Plugin;
use Solarium\Plugin\PostBigRequest;
use Solarium\Core\Client\Client;
use Solarium\Query\Select\Query\Query;
use Solarium\Core\Client\Request;
class PostBigRequestTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Plugin\PostBigRequest
* @var PostBigRequest
*/
protected $_plugin;
protected $plugin;
/**
* @var Solarium\Client
* @var Client
*/
protected $_client;
protected $client;
/**
* @var Solarium\Query\Select\Select
* @var Query
*/
protected $query;
public function setUp()
{
$this->_plugin = new \Solarium\Plugin\PostBigRequest();
$this->plugin = new PostBigRequest();
$this->_client = new \Solarium\Client\Client();
$this->_query = $this->_client->createSelect();
$this->client = new Client();
$this->query = $this->client->createSelect();
}
public function testSetAndGetMaxQueryStringLength()
{
$this->_plugin->setMaxQueryStringLength(512);
$this->assertEquals(512, $this->_plugin->getMaxQueryStringLength());
$this->plugin->setMaxQueryStringLength(512);
$this->assertEquals(512, $this->plugin->getMaxQueryStringLength());
}
public function testPostCreateRequest()
......@@ -71,35 +75,35 @@ class PostBigRequestTest extends \PHPUnit_Framework_TestCase
$fq .= ' OR price:'.$i;
}
$fq = substr($fq, 4);
$this->_query->createFilterQuery('fq')->setQuery($fq);
$this->query->createFilterQuery('fq')->setQuery($fq);
$requestOutput = $this->_client->createRequest($this->_query);
$requestOutput = $this->client->createRequest($this->query);
$requestInput = clone $requestOutput;
$this->_plugin->postCreateRequest($this->_query, $requestOutput);
$this->plugin->postCreateRequest($this->query, $requestOutput);
$this->assertEquals(\Solarium\Client\Request::METHOD_GET, $requestInput->getMethod());
$this->assertEquals(\Solarium\Client\Request::METHOD_POST, $requestOutput->getMethod());
$this->assertEquals(Request::METHOD_GET, $requestInput->getMethod());
$this->assertEquals(Request::METHOD_POST, $requestOutput->getMethod());
$this->assertEquals($requestInput->getQueryString(), $requestOutput->getRawData());
$this->assertEquals('', $requestOutput->getQueryString());
}
public function testPostCreateRequestUnalteredSmallRequest()
{
$requestOutput = $this->_client->createRequest($this->_query);
$requestOutput = $this->client->createRequest($this->query);
$requestInput = clone $requestOutput;
$this->_plugin->postCreateRequest($this->_query, $requestOutput);
$this->plugin->postCreateRequest($this->query, $requestOutput);
$this->assertEquals($requestInput, $requestOutput);
}
public function testPostCreateRequestUnalteredPostRequest()
{
$query = $this->_client->createUpdate();
$query = $this->client->createUpdate();
$query->addDeleteById(1);
$requestOutput = $this->_client->createRequest($query);
$requestOutput = $this->client->createRequest($query);
$requestInput = clone $requestOutput;
$this->_plugin->postCreateRequest($query, $requestOutput);
$this->plugin->postCreateRequest($query, $requestOutput);
$this->assertEquals($requestInput, $requestOutput);
}
......
......@@ -30,75 +30,79 @@
*/
namespace Solarium\Tests\Plugin;
use Solarium\QueryType\Select\Result\Document;
use Solarium\Query\Select\Result\Document;
use Solarium\Query\Select\Query\Query;
use Solarium\Query\Select\Result\Result;
use Solarium\Core\Client\Client;
use Solarium\Plugin\PrefetchIterator;
class PrefetchIteratorTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Solarium\Plugin\PrefetchIterator
* @var PrefetchIterator
*/
protected $_plugin;
protected $plugin;
/**
* @var \Solarium\Client\Client
* @var Client
*/
protected $_client;
protected $client;
/**
* @var \Solarium\Query\Select\Select
* @var Query
*/
protected $_query;
protected $query;
public function setUp()
{
$this->_plugin = new \Solarium\Plugin\PrefetchIterator();
$this->plugin = new PrefetchIterator();
$this->_client = new \Solarium\Client\Client();
$this->_query = $this->_client->createSelect();
$this->client = new Client();
$this->query = $this->client->createSelect();
}
public function testSetAndGetPrefetch()
{
$this->_plugin->setPrefetch(120);
$this->assertEquals(120, $this->_plugin->getPrefetch());
$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());
$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'));
$result = $this->getResult();
$mockClient = $this->getMock('Solarium\Core\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));
$this->plugin->initPlugin($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'));
$result = $this->getResult();
$mockClient = $this->getMock('Solarium\Core\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->plugin->initPlugin($mockClient, array());
$this->plugin->setQuery($this->query);
$results1 = array();
foreach($this->_plugin as $doc) {
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) {
foreach($this->plugin as $key => $doc) {
$results2[$key] = $doc;
}
......@@ -106,7 +110,7 @@ class PrefetchIteratorTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($result->getDocuments(), $results2);
}
public function _getResult()
public function getResult()
{
$numFound = 5;
......@@ -123,17 +127,17 @@ class PrefetchIteratorTest extends \PHPUnit_Framework_TestCase
}
class SelectDummy extends \Solarium\QueryType\Select\Result\Result
class SelectDummy extends Result
{
protected $_parsed = true;
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;
$this->numfound = $numfound;
$this->documents = $docs;
$this->components = $components;
$this->queryTime = $queryTime;
$this->status = $status;
}
}
\ No newline at end of file
......@@ -29,44 +29,46 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Analysis\Query;
namespace Solarium\Tests\Query\Analysis\Query;
use Solarium\Query\Analysis\Query\Document;
use Solarium\Core\Client\Client;
class DocumentTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Query\Analysis\Document
* @var Document
*/
protected $_query;
protected $query;
public function setUp()
{
$this->_query = new \Solarium\QueryType\Analysis\Query\Document;
$this->query = new Document;
}
public function testGetType()
{
$this->assertEquals(\Solarium\Client\Client::QUERYTYPE_ANALYSIS_DOCUMENT, $this->_query->getType());
$this->assertEquals(Client::QUERY_ANALYSIS_DOCUMENT, $this->query->getType());
}
public function testAddAndGetDocument()
{
$doc = new \Solarium\QueryType\Update\Query\Document(array('id' => 1));
$this->_query->addDocument($doc);
$doc = new Document(array('id' => 1));
$this->query->addDocument($doc);
$this->assertEquals(
array($doc),
$this->_query->getDocuments()
$this->query->getDocuments()
);
}
public function testAddAndGetDocuments()
{
$doc1 = new \Solarium\QueryType\Update\Query\Document(array('id' => 1));
$doc2 = new \Solarium\QueryType\Update\Query\Document(array('id' => 2));
$this->_query->addDocuments(array($doc1, $doc2));
$doc1 = new Document(array('id' => 1));
$doc2 = new Document(array('id' => 2));
$this->query->addDocuments(array($doc1, $doc2));
$this->assertEquals(
array($doc1, $doc2),
$this->_query->getDocuments()
$this->query->getDocuments()
);
}
......
......@@ -29,45 +29,47 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Analysis\Query;
namespace Solarium\Tests\Query\Analysis\Query;
use Solarium\Query\Analysis\Query\Field;
use Solarium\Core\Client\Client;
class FieldTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Query\Analysis\Field
* @var Field
*/
protected $_query;
protected $query;
public function setUp()
{
$this->_query = new \Solarium\QueryType\Analysis\Query\Field;
$this->query = new Field;
}
public function testGetType()
{
$this->assertEquals(\Solarium\Client\Client::QUERYTYPE_ANALYSIS_FIELD, $this->_query->getType());
$this->assertEquals(Client::QUERY_ANALYSIS_FIELD, $this->query->getType());
}
public function testSetAndGetFieldValue()
{
$data = 'testdata';
$this->_query->setFieldValue($data);
$this->assertEquals($data, $this->_query->getFieldValue());
$this->query->setFieldValue($data);
$this->assertEquals($data, $this->query->getFieldValue());
}
public function testSetAndGetFieldType()
{
$data = 'testdata';
$this->_query->setFieldType($data);
$this->assertEquals($data, $this->_query->getFieldType());
$this->query->setFieldType($data);
$this->assertEquals($data, $this->query->getFieldType());
}
public function testSetAndGetFieldName()
{
$data = 'testdata';
$this->_query->setFieldName($data);
$this->assertEquals($data, $this->_query->getFieldName());
$this->query->setFieldName($data);
$this->assertEquals($data, $this->query->getFieldName());
}
}
\ No newline at end of file
......@@ -29,42 +29,43 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Analysis\Query;
namespace Solarium\Tests\Query\Analysis\Query;
use Solarium\Query\Analysis\Query\Query;
class QueryTest extends \PHPUnit_Framework_TestCase
{
protected $_query;
protected $query;
public function setUp()
{
$this->_query = new TestAnalysisQuery;
$this->query = new TestAnalysisQuery;
}
public function testSetAndGetQuery()
{
$querystring = 'test query values';
$this->_query->setQuery($querystring);
$this->assertEquals($querystring, $this->_query->getQuery());
$this->query->setQuery($querystring);
$this->assertEquals($querystring, $this->query->getQuery());
}
public function testSetAndGetQueryWithBind()
{
$this->_query->setQuery('id:%1%', array(678));
$this->assertEquals('id:678', $this->_query->getQuery());
$this->query->setQuery('id:%1%', array(678));
$this->assertEquals('id:678', $this->query->getQuery());
}
public function testSetAndGetShowMatch()
{
$show = true;
$this->_query->setShowMatch($show);
$this->assertEquals($show, $this->_query->getShowMatch());
$this->query->setShowMatch($show);
$this->assertEquals($show, $this->query->getShowMatch());
}
}
class TestAnalysisQuery extends \Solarium\QueryType\Analysis\Query\Query{
class TestAnalysisQuery extends Query{
public function getType()
{
......
......@@ -29,48 +29,52 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Analysis\RequestBuilder;
namespace Solarium\Tests\Query\Analysis\RequestBuilder;
use Solarium\Query\Analysis\Query\Document;
use Solarium\Query\Analysis\RequestBuilder\Document as DocumentBuilder;
use Solarium\Core\Client\Request;
use Solarium\Query\Update\Query\Document as InputDocument;
class DocumentTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Query\Analysis\Document
* @var Document
*/
protected $_query;
protected $query;
/**
* @var Solarium\Client\RequestBuilder\Analysis\Document
* @var DocumentBuilder
*/
protected $_builder;
protected $builder;
public function setUp()
{
$this->_query = new \Solarium\QueryType\Analysis\Query\Document();
$this->_builder = new \Solarium\QueryType\Analysis\RequestBuilder\Document;
$this->query = new Document();
$this->builder = new DocumentBuilder();
}
public function testBuild()
{
$request = $this->_builder->build($this->_query);
$request = $this->builder->build($this->query);
$this->assertEquals(\Solarium\Client\Request::METHOD_POST, $request->getMethod());
$this->assertEquals($this->_builder->getRawData($this->_query), $request->getRawData());
$this->assertEquals(Request::METHOD_POST, $request->getMethod());
$this->assertEquals($this->builder->getRawData($this->query), $request->getRawData());
}
public function testGetRawData()
{
// this doc tests data escaping
$doc1 = new \Solarium\QueryType\Update\Query\Document(array('id' => 1, 'name' => 'doc1', 'cat' => 'my > cat'));
$doc1 = new InputDocument(array('id' => 1, 'name' => 'doc1', 'cat' => 'my > cat'));
// this doc tests a multivalue field
$doc2 = new \Solarium\QueryType\Update\Query\Document(array('id' => 2, 'name' => 'doc2', 'cat' => array(1,2,3)));
$doc2 = new InputDocument(array('id' => 2, 'name' => 'doc2', 'cat' => array(1,2,3)));
$this->_query->addDocuments(array($doc1, $doc2));
$this->query->addDocuments(array($doc1, $doc2));
$this->assertEquals(
'<docs><doc><field name="id">1</field><field name="name">doc1</field><field name="cat">my &gt; cat</field></doc><doc><field name="id">2</field><field name="name">doc2</field><field name="cat">1</field><field name="cat">2</field><field name="cat">3</field></doc></docs>',
$this->_builder->getRawData($this->_query)
$this->builder->getRawData($this->query)
);
}
......
......@@ -29,25 +29,27 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Analysis\RequestBuilder;
namespace Solarium\Tests\Query\Analysis\RequestBuilder;
use Solarium\Query\Analysis\Query\Field as FieldQuery;
use Solarium\Query\Analysis\RequestBuilder\Field as FieldBuilder;
class FieldTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Query\Analysis\Field
* @var FieldQuery
*/
protected $_query;
protected $query;
/**
* @var Solarium\Client\RequestBuilder\Analysis\Field
* @var FieldBuilder
*/
protected $_builder;
protected $builder;
public function setUp()
{
$this->_query = new \Solarium\QueryType\Analysis\Query\Field();
$this->_builder = new \Solarium\QueryType\Analysis\RequestBuilder\Field;
$this->query = new FieldQuery();
$this->builder = new FieldBuilder();
}
public function testBuild()
......@@ -56,11 +58,11 @@ class FieldTest extends \PHPUnit_Framework_TestCase
$fieldName = 'myfield';
$fieldType = 'text';
$this->_query->setFieldValue($fieldValue)
$this->query->setFieldValue($fieldValue)
->setFieldName($fieldName)
->setFieldType($fieldType);
$request = $this->_builder->build($this->_query);
$request = $this->builder->build($this->query);
$this->assertEquals($fieldValue, $request->getParam('analysis.fieldvalue'));
$this->assertEquals($fieldName, $request->getParam('analysis.fieldname'));
......
......@@ -29,25 +29,27 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Analysis\RequestBuilder;
namespace Solarium\Tests\Query\Analysis\RequestBuilder;
use Solarium\Query\Analysis\Query\Field;
use Solarium\Query\Analysis\RequestBuilder\RequestBuilder;
class RequestBuilderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Query\Analysis\Field
* @var Field
*/
protected $_query;
protected $query;
/**
* @var Solarium\Client\RequestBuilder\Analysis\Analysis
* @var RequestBuilder
*/
protected $_builder;
protected $builder;
public function setUp()
{
$this->_query = new \Solarium\QueryType\Analysis\Query\Field();
$this->_builder = new \Solarium\QueryType\Analysis\RequestBuilder\RequestBuilder();
$this->query = new Field();
$this->builder = new RequestBuilder();
}
public function testBuild()
......@@ -56,10 +58,10 @@ class RequestBuilderTest extends \PHPUnit_Framework_TestCase
$showMatch = true;
$handler = 'myhandler';
$this->_query->setQuery($query)
$this->query->setQuery($query)
->setShowMatch($showMatch)
->setHandler($handler);
$request = $this->_builder->build($this->_query);
$request = $this->builder->build($this->query);
$this->assertEquals(
array(
......
......@@ -29,7 +29,7 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Analysis\ResponseParser;
namespace Solarium\Tests\Query\Analysis\ResponseParser;
class DocumentTest extends \PHPUnit_Framework_TestCase
{
......@@ -47,14 +47,14 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
)
);
$resultStub = $this->getMock('Solarium\Result\Result', array(), array(), '', false);
$resultStub = $this->getMock('Solarium\Core\Query\Result\Result', array(), array(), '', false);
$resultStub->expects($this->once())
->method('getData')
->will($this->returnValue($data));
$parserStub = $this->getMock('Solarium\QueryType\Analysis\ResponseParser\Document',array('_parseTypes'));
$parserStub = $this->getMock('Solarium\Query\Analysis\ResponseParser\Document',array('parseTypes'));
$parserStub->expects($this->exactly(2))
->method('_parseTypes')
->method('parseTypes')
->will($this->returnValue('dummy'));
$result = $parserStub->parse($resultStub);
......
......@@ -29,7 +29,8 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Analysis\ResponseParser;
namespace Solarium\Tests\Query\Analysis\ResponseParser;
use Solarium\Query\Analysis\ResponseParser\Field as FieldParser;
class FieldTest extends \PHPUnit_Framework_TestCase
{
......@@ -74,12 +75,12 @@ class FieldTest extends \PHPUnit_Framework_TestCase
)
);
$resultStub = $this->getMock('Solarium\Result\Result', array(), array(), '', false);
$resultStub = $this->getMock('Solarium\Core\Query\Result\Result', array(), array(), '', false);
$resultStub->expects($this->once())
->method('getData')
->will($this->returnValue($data));
$parser = new \Solarium\QueryType\Analysis\ResponseParser\Field();
$parser = new FieldParser();
$result = $parser->parse($resultStub);
$docs = $result['items'][0]->getItems();
......@@ -101,12 +102,12 @@ class FieldTest extends \PHPUnit_Framework_TestCase
)
);
$resultStub = $this->getMock('Solarium\Result\Result', array(), array(), '', false);
$resultStub = $this->getMock('Solarium\Core\Query\Result\Result', array(), array(), '', false);
$resultStub->expects($this->once())
->method('getData')
->will($this->returnValue($data));
$parser = new \Solarium\QueryType\Analysis\ResponseParser\Field();
$parser = new FieldParser();
$result = $parser->parse($resultStub);
$this->assertEquals(
......
......@@ -29,50 +29,51 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Analysis\Result;
namespace Solarium\Tests\Query\Analysis\Result;
use Solarium\Query\Analysis\Result\Document;
class DocumentTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Result\Analysis\Document
* @var DocumentDummy
*/
protected $_result;
protected $result;
protected $_items;
protected $items;
public function setUp()
{
$this->_items = array('key1' => 'dummy1', 'key2' => 'dummy2', 'key3' => 'dummy3');
$this->_result = new DocumentDummy(1, 12, $this->_items);
$this->items = array('key1' => 'dummy1', 'key2' => 'dummy2', 'key3' => 'dummy3');
$this->result = new DocumentDummy(1, 12, $this->items);
}
public function testGetDocuments()
{
$this->assertEquals($this->_items, $this->_result->getDocuments());
$this->assertEquals($this->items, $this->result->getDocuments());
}
public function testCount()
{
$this->assertEquals(count($this->_items), count($this->_result));
$this->assertEquals(count($this->items), count($this->result));
}
public function testIterator()
{
$docs = array();
foreach($this->_result AS $key => $doc)
foreach($this->result AS $key => $doc)
{
$docs[$key] = $doc;
}
$this->assertEquals($this->_items, $docs);
$this->assertEquals($this->items, $docs);
}
public function testGetStatus()
{
$this->assertEquals(
1,
$this->_result->getStatus()
$this->result->getStatus()
);
}
......@@ -80,15 +81,15 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
{
$this->assertEquals(
12,
$this->_result->getQueryTime()
$this->result->getQueryTime()
);
}
public function testGetDocument()
{
$this->assertEquals(
$this->_items['key2'],
$this->_result->getDocument('key2')
$this->items['key2'],
$this->result->getDocument('key2')
);
}
......@@ -96,21 +97,21 @@ class DocumentTest extends \PHPUnit_Framework_TestCase
{
$this->assertEquals(
null,
$this->_result->getDocument('invalidkey')
$this->result->getDocument('invalidkey')
);
}
}
class DocumentDummy extends \Solarium\QueryType\Analysis\Result\Document
class DocumentDummy extends Document
{
protected $_parsed = true;
protected $parsed = true;
public function __construct($status, $queryTime, $items)
{
$this->_items = $items;
$this->_queryTime = $queryTime;
$this->_status = $status;
$this->items = $items;
$this->queryTime = $queryTime;
$this->status = $status;
}
}
\ No newline at end of file
......@@ -29,50 +29,51 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Analysis\Result;
namespace Solarium\Tests\Query\Analysis\Result;
use Solarium\Query\Analysis\Result\Field;
class FieldTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Solarium\Result\Analysis\Field
* @var FieldDummy
*/
protected $_result;
protected $result;
protected $_items;
protected $items;
public function setUp()
{
$this->_items = array('key1' => 'dummy1', 'key2' => 'dummy2', 'key3' => 'dummy3');
$this->_result = new FieldDummy(1, 12, $this->_items);
$this->items = array('key1' => 'dummy1', 'key2' => 'dummy2', 'key3' => 'dummy3');
$this->result = new FieldDummy(1, 12, $this->items);
}
public function testGetLists()
{
$this->assertEquals($this->_items, $this->_result->getLists());
$this->assertEquals($this->items, $this->result->getLists());
}
public function testCount()
{
$this->assertEquals(count($this->_items), count($this->_result));
$this->assertEquals(count($this->items), count($this->result));
}
public function testIterator()
{
$lists = array();
foreach($this->_result AS $key => $list)
foreach($this->result AS $key => $list)
{
$lists[$key] = $list;
}
$this->assertEquals($this->_items, $lists);
$this->assertEquals($this->items, $lists);
}
public function testGetStatus()
{
$this->assertEquals(
1,
$this->_result->getStatus()
$this->result->getStatus()
);
}
......@@ -80,21 +81,21 @@ class FieldTest extends \PHPUnit_Framework_TestCase
{
$this->assertEquals(
12,
$this->_result->getQueryTime()
$this->result->getQueryTime()
);
}
}
class FieldDummy extends \Solarium\QueryType\Analysis\Result\Field
class FieldDummy extends Field
{
protected $_parsed = true;
protected $parsed = true;
public function __construct($status, $queryTime, $items)
{
$this->_items = $items;
$this->_queryTime = $queryTime;
$this->_status = $status;
$this->items = $items;
$this->queryTime = $queryTime;
$this->status = $status;
}
}
\ No newline at end of file
......@@ -29,7 +29,9 @@
* policies, either expressed or implied, of the copyright holder.
*/
namespace Solarium\Tests\QueryType\Select\Query\Component;
namespace Solarium\Tests\Query\Select\Query\Component;
use Solarium\Query\Select\Query\Component\Component;
use Solarium\Query\Select\Query\Query;
class ComponentTest extends \PHPUnit_Framework_TestCase
{
......@@ -42,7 +44,7 @@ class ComponentTest extends \PHPUnit_Framework_TestCase
}
class TestComponent extends \Solarium\QueryType\Select\Query\Component\Component{
class TestComponent extends Component{
protected $_type = 'testtype';
protected $type = 'testtype';
}
\ No newline at end of file
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