From 936d5912c5f750dbbbaac1a8cfa14c606fdb47fe Mon Sep 17 00:00:00 2001 From: Tim Millwood Date: Wed, 11 Nov 2015 20:20:00 +0000 Subject: [PATCH] Adding path support for url --- lib/Doctrine/CouchDB/CouchDBClient.php | 4 +++- .../Tests/CouchDB/CouchDBClientTest.php | 21 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/CouchDB/CouchDBClient.php b/lib/Doctrine/CouchDB/CouchDBClient.php index 5cf9ed6..63b73e1 100644 --- a/lib/Doctrine/CouchDB/CouchDBClient.php +++ b/lib/Doctrine/CouchDB/CouchDBClient.php @@ -88,7 +88,9 @@ static public function create(array $options) break; case 'path': - $options['dbname'] = ltrim($value, '/'); + $path = explode('/', $value); + $options['dbname'] = array_pop($path); + $options['path'] = trim(implode('/', $path), '/'); break; case 'pass': diff --git a/tests/Doctrine/Tests/CouchDB/CouchDBClientTest.php b/tests/Doctrine/Tests/CouchDB/CouchDBClientTest.php index a76e651..83403d4 100644 --- a/tests/Doctrine/Tests/CouchDB/CouchDBClientTest.php +++ b/tests/Doctrine/Tests/CouchDB/CouchDBClientTest.php @@ -44,6 +44,27 @@ public function testCreateClientFromUrl() ); } + public function testCreateClientFromUrlWithPath() + { + $client = CouchDBClient::create(array('url' => 'https://foo:bar@localhost:5555/baz/qux/norf')); + + $this->assertEquals('norf', $client->getDatabase()); + $this->assertEquals( + array( + 'host' => 'localhost', + 'port' => 5555, + 'ip' => '127.0.0.1', + 'username' => 'foo', + 'password' => 'bar', + 'ssl' => true, + 'timeout' => 0.01, + 'keep-alive' => true, + 'path' => 'baz/qux', + ), + $client->getHttpClient()->getOptions() + ); + } + public function testCreateClientWithLogging() { $client = CouchDBClient::create(array('dbname' => 'test', 'logging' => true));