Commit 4930bf62 authored by Jeremy Mikola's avatar Jeremy Mikola

Validate Database $databaseName and test getters

parent 337075f2
......@@ -34,9 +34,14 @@ class Database
* @param string $databaseName Database name
* @param WriteConcern $writeConcern Default write concern to apply
* @param ReadPreference $readPreference Default read preference to apply
* @throws InvalidArgumentException if $databaseName is invalid
*/
public function __construct(Manager $manager, $databaseName, WriteConcern $writeConcern = null, ReadPreference $readPreference = null)
{
if (strlen($databaseName) < 1) {
throw new InvalidArgumentException('$databaseName is invalid: ' . $databaseName);
}
$this->manager = $manager;
$this->databaseName = (string) $databaseName;
$this->writeConcern = $writeConcern;
......
......@@ -2,11 +2,41 @@
namespace MongoDB\Tests\Database;
use MongoDB\Database;
/**
* Functional tests for the Database class.
*/
class DatabaseFunctionalTest extends FunctionalTestCase
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDatabaseValues
*/
public function testConstructorDatabaseNameArgument($databaseName)
{
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
new Database($this->manager, $databaseName);
}
public function provideInvalidDatabaseValues()
{
return array(
array(null),
array(''),
);
}
public function testToString()
{
$this->assertEquals($this->getDatabaseName(), (string) $this->database);
}
public function getGetDatabaseName()
{
$this->assertEquals($this->getDatabaseName(), $this->database->getDatabaseName());
}
public function testDrop()
{
$writeResult = $this->manager->executeInsert($this->getNamespace(), array('x' => 1));
......
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