Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

unit tests for sql query

  • Loading branch information...
commit 75deb85db2ac45935e7af431d01f97588afa0885 1 parent b40eebd
David Buchmann dbu authored
14 src/Jackalope/Query/SqlQuery.php
View
@@ -31,7 +31,7 @@ class SqlQuery implements \PHPCR\Query\QueryInterface
/**
* @var \Jackalope\ObjectManager
*/
- protected $objectmanager;
+ protected $objectManager;
/**
* If this is a stored query, the path to the node that stores this query.
* @var string
@@ -44,16 +44,16 @@ class SqlQuery implements \PHPCR\Query\QueryInterface
* @param object $factory an object factory implementing "get" as described
* in \Jackalope\Factory
* @param string $statement The SQL statement for this query
- * @param ObjectManager $objectmanager Object manager to execute query
+ * @param ObjectManager $objectManager Object manager to execute query
* against
* @param string $path If this query is loaded from workspace with
* QueryManager::getQuery(), path has to be provided here
*/
- public function __construct($factory, $statement, ObjectManager $objectmanager, $path = null)
+ public function __construct($factory, $statement, ObjectManager $objectManager, $path = null)
{
$this->factory = $factory;
$this->statement = $statement;
- $this->objectmanager = $objectmanager;
+ $this->objectManager = $objectManager;
$this->path = $path;
}
@@ -72,13 +72,13 @@ public function bindValue($varName, $value)
*/
public function execute()
{
- $transport = $this->objectmanager->getTransport();
+ $transport = $this->objectManager->getTransport();
$rawData = $transport->query($this);
$queryResult = $this->factory->get(
'Query\QueryResult',
array(
$rawData,
- $this->objectmanager,
+ $this->objectManager,
)
);
return $queryResult;
@@ -135,6 +135,8 @@ public function getOffset()
* Access the query statement from the transport layer
*
* @return string the sql2 query statement
+ *
+ * @private
*/
public function getStatementSql2()
{
91 tests/Jackalope/Query/SqlQueryTest.php
View
@@ -6,9 +6,96 @@
class SqlQueryTest extends TestCase
{
- public function testDummy()
+ protected $statement = 'statement';
+ protected function getQuery($factory = null, $statement = null, $objectManager = null, $path = null)
{
- $this->markTestSkipped('No tests for this class yet');
+ if (! $factory) {
+ $factory = new \Jackalope\Factory;
+ }
+ if (! $statement) {
+ $statement = $this->statement;
+ }
+ if (! $objectManager) {
+ $objectManager = $this->getObjectManagerMock();
+ }
+
+ return new SqlQuery($factory, $statement, $objectManager, $path);
+ }
+
+ public function testBindValue()
+ {
+ $this->markTestSkipped('TODO: implement');
}
+ public function testExecute()
+ {
+ $dummyData = 'x';
+ $factory = $this->getMock('\Jackalope\Factory');
+ $transport = $this->getMock('\Jackalope\TransportInterface');
+ $om = $this->getMock('\Jackalope\ObjectManager', array('getNodeTypes'), array($factory, $transport, $this->getSessionMock()));
+
+ $query = $this->getQuery($factory, null, $om);
+
+ $transport->expects($this->once())
+ ->method('query')
+ ->with($query)
+ ->will($this->returnValue($dummyData));
+ $factory->expects($this->once())
+ ->method('get')
+ ->with('Query\QueryResult', array($dummyData, $om))
+ ->will($this->returnValue('result'));
+
+ $result = $query->execute();
+ $this->assertEquals('result', $result);
+ }
+ public function testGetBindVariableNames()
+ {
+ $this->markTestSkipped('TODO: implement');
+ }
+ public function testLimit()
+ {
+ $query = $this->getQuery();
+ $query->setLimit(37);
+ $this->assertEquals(37, $query->getLimit());
+ }
+ public function testOffset()
+ {
+ $query = $this->getQuery();
+ $query->setOffset(15);
+ $this->assertEquals(15, $query->getOffset());
+ }
+ public function testGetStatementSql2()
+ {
+ $query = $this->getQuery();
+ $this->assertEquals($this->statement, $query->getStatementSql2());
+ }
+ public function testGetStatement()
+ {
+ $query = $this->getQuery();
+ $this->assertEquals($this->statement, $query->getStatement());
+ }
+ public function testGetLanguage()
+ {
+ $query = $this->getQuery();
+ $this->assertEquals(\PHPCR\Query\QueryInterface::JCR_SQL2, $query->getLanguage());
+ }
+
+ public function testGetStoredQueryPath()
+ {
+ $query = $this->getQuery(null, null, null, '/path/query');
+ $this->assertSame('/path/query', $query->getStoredQueryPath());
+ }
+
+ /**
+ * @expectedException \PHPCR\ItemNotFoundException
+ */
+ public function testGetStoredQueryPathNotStored()
+ {
+ $query = $this->getQuery();
+ $query->getStoredQueryPath();
+ }
+ public function testStoreAsNode()
+ {
+ $this->markTestSkipped('TODO: implement feature');
+ }
}
8 tests/Jackalope/TestCase.php
View
@@ -81,13 +81,19 @@ protected function getRepositoryMock()
return $mock;
}
+ protected function getObjectManagerMock()
+ {
+ $factory = new \Jackalope\Factory;
+ return $this->getMock('\Jackalope\ObjectManager', array('getNodeTypes'), array($factory, $this->getTransportStub('/jcr:root'), $this->getSessionMock()));
+ }
+
protected function getNodeTypeManager()
{
$factory = new \Jackalope\Factory;
$dom = new \DOMDocument();
$dom->load(dirname(__FILE__) . '/../fixtures/nodetypes.xml');
$converter = new \Jackalope\NodeType\NodeTypeXmlConverter;
- $om = $this->getMock('\Jackalope\ObjectManager', array('getNodeTypes'), array($factory, $this->getTransportStub('/jcr:root'), $this->getSessionMock()));
+ $om = $this->getObjectManagerMock();
$om->expects($this->any())
->method('getNodeTypes')
->will($this->returnValue($converter->getNodeTypesFromXml($dom)));
Please sign in to comment.
Something went wrong with that request. Please try again.