Commit af9bc65d authored by Jeremy Mikola's avatar Jeremy Mikola

Merge pull request #97

parents 7039bd7a c56c7e2b
......@@ -73,6 +73,23 @@ class Client
];
}
/**
* Select a database.
*
* Note: collections whose names contain special characters (e.g. "-") may
* be selected with complex syntax (e.g. $client->{"that-database"}) or
* {@link selectDatabase()}.
*
* @see http://php.net/oop5.overloading#object.get
* @see http://php.net/types.string#language.types.string.parsing.complex
* @param string $databaseName Name of the database to select
* @return Database
*/
public function __get($databaseName)
{
return $this->selectDatabase($databaseName);
}
/**
* Return the connection string (i.e. URI).
*
......
......@@ -102,6 +102,23 @@ class Database
];
}
/**
* Select a collection within this database.
*
* Note: collections whose names contain special characters (e.g. ".") may
* be selected with complex syntax (e.g. $database->{"system.profile"}) or
* {@link selectCollection()}.
*
* @see http://php.net/oop5.overloading#object.get
* @see http://php.net/types.string#language.types.string.parsing.complex
* @param string $collectionName Name of the collection to select
* @return Collection
*/
public function __get($collectionName)
{
return $this->selectCollection($collectionName);
}
/**
* Return the database name.
*
......
......@@ -97,6 +97,19 @@ class ClientTest extends TestCase
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
}
public function testGetSelectsDatabaseAndInheritsOptions()
{
$uriOptions = ['w' => WriteConcern::MAJORITY];
$client = new Client($this->getUri(), $uriOptions);
$database = $client->{$this->getDatabaseName()};
$debug = $database->__debugInfo();
$this->assertSame($this->getDatabaseName(), $debug['databaseName']);
$this->assertInstanceOf('MongoDB\Driver\WriteConcern', $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
}
public function testSelectDatabaseInheritsOptions()
{
$this->markTestSkipped('Depends on https://jira.mongodb.org/browse/PHPC-523');
......
......@@ -131,6 +131,20 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this->assertCollectionCount($this->getNamespace(), 0);
}
public function testGetSelectsCollectionAndInheritsOptions()
{
$databaseOptions = ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)];
$database = new Database($this->manager, $this->getDatabaseName(), $databaseOptions);
$collection = $database->{$this->getCollectionName()};
$debug = $collection->__debugInfo();
$this->assertSame($this->getCollectionName(), $debug['collectionName']);
$this->assertSame($this->getDatabaseName(), $debug['databaseName']);
$this->assertInstanceOf('MongoDB\Driver\WriteConcern', $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
}
public function testSelectCollectionInheritsOptions()
{
$databaseOptions = [
......
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