Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added simple unit test and getMongoClientObject method

  • Loading branch information...
commit 3f61c297a255c1b208db42313b78545d0b095a1d 1 parent d8c6c85
Mustafa Navruz authored
1  .gitignore
View
@@ -1 +1,2 @@
/vendor
+composer.lock
13 .travis.yml
View
@@ -0,0 +1,13 @@
+language: php
+
+php:
+ - 5.3
+ - 5.4
+
+services: mongodb
+
+before_script:
+ - pecl install mongo
+ - echo "extension=mongo.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
+
+script: phpunit
4 composer.json
View
@@ -8,6 +8,10 @@
"require": {
"php": ">=5.3.0"
},
+ "require-dev": {
+ "phpunit/phpunit": "3.7.*",
+ "illuminate/support": "*"
+ },
"authors": [
{
"name": "Mustafa Navruz",
18 phpunit.xml
View
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit backupGlobals="false"
+ backupStaticAttributes="false"
+ bootstrap="vendor/autoload.php"
+ colors="true"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ processIsolation="false"
+ stopOnFailure="false"
+ syntaxCheck="false"
+>
+ <testsuites>
+ <testsuite name="LMongo Test Suite">
+ <directory>./tests/</directory>
+ </testsuite>
+ </testsuites>
+</phpunit>
23 src/LMongo/Database.php
View
@@ -25,7 +25,14 @@ class Database
protected $database;
/**
- * The MongoDB connection handler.
+ * The MongoDB database handler.
+ *
+ * @var resource
+ */
+ protected $db;
+
+ /**
+ * The MongoClient connection handler.
*
* @var resource
*/
@@ -55,8 +62,8 @@ public function connect()
{
if ( ! is_null($this->connection)) return;
- $conn = new \MongoClient($this->host . ':' . $this->port);
- $this->connection = $conn->{$this->database};
+ $this->connection = new \MongoClient($this->host . ':' . $this->port);
+ $this->db = $this->connection->{$this->database};
}
/**
@@ -66,6 +73,16 @@ public function connect()
*/
public function getMongoDBObject()
{
+ return $this->db;
+ }
+
+ /**
+ * return MongoClient object
+ *
+ * @return \MongoClient
+ */
+ public function getMongoClientObject()
+ {
return $this->connection;
}
51 tests/LMongoDatabaseTest.php
View
@@ -0,0 +1,51 @@
+<?php
+
+use LMongo\Database;
+
+class LMongoDatabaseTest extends PHPUnit_Framework_TestCase {
+
+ private $conn;
+
+ private $db;
+
+ private $connection;
+
+ function setUp()
+ {
+ parent::setUp();
+
+ $conn = new Database('localhost', 27017, 'lmongotestdb');
+ $conn->connect();
+ $this->connection = $conn->getMongoClientObject();
+ $this->db = $conn->getMongoDBObject();
+ }
+
+ function testInstanceOfMongoDB()
+ {
+ $this->assertInstanceOf('MongoDB', $this->db);
+ }
+
+ function testInstanceOfMongoClient()
+ {
+ $this->assertInstanceOf('MongoClient', $this->connection);
+ }
+
+ function testInstanceOfMongoCollection()
+ {
+ $this->assertInstanceOf('MongoCollection', $this->db->testcollection);
+ }
+
+ function testInstanceOfMongoCursor()
+ {
+ $this->assertInstanceOf('MongoCursor', $this->db->testcollection->find());
+ }
+
+ function tearDown()
+ {
+ parent::tearDown();
+
+ if ($this->db) {
+ $this->db->drop();
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.