Skip to content

Commit

Permalink
Merge pull request #256 from jackalope/fix-namespaces-cached-client
Browse files Browse the repository at this point in the history
Handle the ArrayObject in CachedClient as well
  • Loading branch information
dbu committed Apr 5, 2015
2 parents 4c5ae80 + b1bf1f9 commit e44167e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/Jackalope/Transport/DoctrineDBAL/CachedClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,19 @@ protected function workspaceExists($workspaceName)
}

/**
* {@inheritDoc}
* Return the namespaces of the current session as a referenceable ArrayObject.
*
* @return \ArrayObject
*/
public function getNamespaces()
protected function getNamespacesObject()
{
if (empty($this->namespaces)) {
if ($this->namespaces->count() === 0) {
$cacheKey = 'namespaces';
$result = $this->caches['meta']->fetch($cacheKey);
if ($result) {
$this->namespaces = $result;
} else {
$this->namespaces = parent::getNamespaces();
$this->namespaces = parent::getNamespacesObject();

$this->caches['meta']->save($cacheKey, $this->namespaces);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Jackalope/Transport/DoctrineDBAL/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public function getNamespaces()
*
* @return \ArrayObject
*/
private function getNamespacesObject()
protected function getNamespacesObject()
{
if ($this->namespaces->count() === 0) {
$query = 'SELECT * FROM phpcr_namespaces';
Expand Down
66 changes: 66 additions & 0 deletions tests/Jackalope/Transport/DoctrineDBAL/CachedClientTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Jackalope\Transport\DoctrineDBAL;

use Doctrine\DBAL\Platforms\SqlitePlatform;
use Jackalope\Repository;
use Jackalope\Session;
use Jackalope\Test\TestCase;
use PHPCR\PropertyType;
use PHPCR\Util\NodeHelper;
use PHPCR\Util\PathHelper;

class CachedClientTest extends TestCase
{
/**
* @var Client
*/
private $transport;

/**
* @var Repository
*/
private $repository;

/**
* @var Session
*/
private $session;

public function setUp()
{
static $initialized = false;
parent::setUp();

$conn = $this->getConnection();
$options = array('disable_fks' => $conn->getDatabasePlatform() instanceof SqlitePlatform);
$schema = new RepositorySchema($options, $conn);
$tables = $schema->getTables();

foreach ($tables as $table) {
$conn->exec('DELETE FROM ' . $table->getName());
}

$this->transport = new \Jackalope\Transport\DoctrineDBAL\CachedClient(new \Jackalope\Factory(), $conn);
$this->transport->createWorkspace('default');

$this->repository = new \Jackalope\Repository(null, $this->transport);

try {
$this->transport->createWorkspace($GLOBALS['phpcr.workspace']);
} catch (\PHPCR\RepositoryException $e) {
if ($e->getMessage() != "Workspace '".$GLOBALS['phpcr.workspace']."' already exists") {
// if the message is not that the workspace already exists, something went really wrong
throw $e;
}
}
$this->session = $this->repository->login(new \PHPCR\SimpleCredentials("user", "passwd"), $GLOBALS['phpcr.workspace']);
}

public function testArrayObjectIsConvertedToArray()
{
$namespaces = $this->transport->getNamespaces();

$this->assertInternalType("array", $namespaces);
}
}

0 comments on commit e44167e

Please sign in to comment.