From b1bf1f99471c3aabdd7dcc8822006c2116668659 Mon Sep 17 00:00:00 2001 From: alexander Date: Wed, 1 Apr 2015 11:27:17 +0200 Subject: [PATCH] Handle the ArrayObject in CachedClient as well --- .../Transport/DoctrineDBAL/CachedClient.php | 10 +-- .../Transport/DoctrineDBAL/Client.php | 2 +- .../DoctrineDBAL/CachedClientTest.php | 66 +++++++++++++++++++ 3 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 tests/Jackalope/Transport/DoctrineDBAL/CachedClientTest.php diff --git a/src/Jackalope/Transport/DoctrineDBAL/CachedClient.php b/src/Jackalope/Transport/DoctrineDBAL/CachedClient.php index f990ed1f..a1488712 100644 --- a/src/Jackalope/Transport/DoctrineDBAL/CachedClient.php +++ b/src/Jackalope/Transport/DoctrineDBAL/CachedClient.php @@ -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); } diff --git a/src/Jackalope/Transport/DoctrineDBAL/Client.php b/src/Jackalope/Transport/DoctrineDBAL/Client.php index 0e39fb90..7e4ca73b 100644 --- a/src/Jackalope/Transport/DoctrineDBAL/Client.php +++ b/src/Jackalope/Transport/DoctrineDBAL/Client.php @@ -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'; diff --git a/tests/Jackalope/Transport/DoctrineDBAL/CachedClientTest.php b/tests/Jackalope/Transport/DoctrineDBAL/CachedClientTest.php new file mode 100644 index 00000000..9dce125d --- /dev/null +++ b/tests/Jackalope/Transport/DoctrineDBAL/CachedClientTest.php @@ -0,0 +1,66 @@ +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); + } +}