Permalink
Browse files

Split CollectionTest and LoggableCollectionTest

  • Loading branch information...
1 parent ec10f4d commit e9e1473233ad52d369db578619311ccf4fd71f31 @jmikola jmikola committed Jan 17, 2013
@@ -4,35 +4,11 @@
use Doctrine\MongoDB\Collection;
use Doctrine\MongoDB\Connection;
-use Doctrine\MongoDB\LoggableCollection;
use Doctrine\MongoDB\Database;
use Doctrine\Common\EventManager;
-use MongoCollection;
-use PHPUnit_Framework_TestCase;
-class CollectionTest extends PHPUnit_Framework_TestCase
+class CollectionTest extends \PHPUnit_Framework_TestCase
{
- public function testLog()
- {
- $mockConnection = $this->getMockConnection();
- $mongoCollection = $this->getMockMongoCollection();
- $mongoCollection->expects($this->any())
- ->method('getName')
- ->will($this->returnValue('collection'));
-
- $mockDatabase = $this->getMockDatabase();
- $mockDatabase->expects($this->once())
- ->method('getName')
- ->will($this->returnValue('db'));
-
- $called = false;
- $coll = $this->getTestCollection($mockConnection, $mongoCollection, $mockDatabase, function($msg) use (&$called) {
- $called = $msg;
- });
- $coll->log(array('test' => 'test'));
- $this->assertEquals(array('collection' => 'collection', 'db' => 'db', 'test' => 'test'), $called);
- }
-
public function testBatchInsert()
{
$mockConnection = $this->getMockConnection();
@@ -501,37 +477,35 @@ public function testToString()
private function getMockMongoCursor()
{
- return $this->getMock('MongoCursor', array(), array(), '', false, false);
+ return $this->getMockBuilder('MongoCursor')
+ ->disableOriginalConstructor()
+ ->getMock();
}
private function getMockMongoCollection()
{
- return $this->getMock('MongoCollection', array(), array(), '', false, false);
- }
-
- private function getMockMongoDB()
- {
- return $this->getMock('MongoDB', array(), array(), '', false, false);
+ return $this->getMockBuilder('MongoCollection')
+ ->disableOriginalConstructor()
+ ->getMock();
}
private function getMockDatabase()
{
- return $this->getMock('Doctrine\MongoDB\Database', array(), array(), '', false, false);
+ return $this->getMockBuilder('Doctrine\MongoDB\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
}
private function getMockConnection()
{
- return $this->getMock('Doctrine\MongoDB\Connection', array(), array(), '', false, false);
+ return $this->getMockBuilder('Doctrine\MongoDB\Connection')
+ ->disableOriginalConstructor()
+ ->getMock();
}
- private function getTestCollection(Connection $connection, MongoCollection $mongoCollection, Database $db, $loggerCallable = null)
+ private function getTestCollection(Connection $connection, \MongoCollection $mongoCollection, Database $db)
{
- if (null === $loggerCallable) {
- $collection = new TestCollectionStub($connection, $mongoCollection->getName(), $db, new EventManager(), '$');
- $collection->setMongoCollection($mongoCollection);
- return $collection;
- }
- $collection = new TestLoggableCollectionStub($connection, $mongoCollection->getName(), $db, new EventManager(), '$', $loggerCallable);
+ $collection = new TestCollectionStub($connection, $mongoCollection->getName(), $db, new EventManager(), '$');
$collection->setMongoCollection($mongoCollection);
return $collection;
}
@@ -545,19 +519,6 @@ private function assertArrayHasKeyValue($expected, $array, $message = '')
}
}
-class TestLoggableCollectionStub extends LoggableCollection
-{
- public function setMongoCollection($mongoCollection)
- {
- $this->mongoCollection = $mongoCollection;
- }
-
- public function getMongoCollection()
- {
- return $this->mongoCollection;
- }
-}
-
class TestCollectionStub extends Collection
{
public function setMongoCollection($mongoCollection)
@@ -0,0 +1,43 @@
+<?php
+
+namespace Doctrine\MongoDB\Tests;
+
+use Doctrine\MongoDB\LoggableCollection;
+use Doctrine\Common\EventManager;
+
+class LoggableCollectionTest extends \PHPUnit_Framework_TestCase
+{
+ public function testLog()
+ {
+ $called = false;
+
+ $loggerCallable = function($msg) use (&$called) {
+ $called = $msg;
+ };
+
+ $database = $this->getMockDatabase();
+
+ $database->expects($this->once())
+ ->method('getName')
+ ->will($this->returnValue('test'));
+
+ $coll = new LoggableCollection($this->getMockConnection(), 'foo', $database, new EventManager(), '$', $loggerCallable);
+ $coll->log(array('test' => 'test'));
+
+ $this->assertEquals(array('collection' => 'foo', 'db' => 'test', 'test' => 'test'), $called);
+ }
+
+ private function getMockDatabase()
+ {
+ return $this->getMockBuilder('Doctrine\MongoDB\Database')
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
+
+ private function getMockConnection()
+ {
+ return $this->getMockBuilder('Doctrine\MongoDB\Connection')
+ ->disableOriginalConstructor()
+ ->getMock();
+ }
+}

0 comments on commit e9e1473

Please sign in to comment.