From c76cdbc9b78db2552145b95be6de1b6247841f3c Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 12 Aug 2013 19:09:12 -0400 Subject: [PATCH] Refactor LoggableCollection test --- .../MongoDB/Tests/LoggableCollectionTest.php | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/tests/Doctrine/MongoDB/Tests/LoggableCollectionTest.php b/tests/Doctrine/MongoDB/Tests/LoggableCollectionTest.php index 3f0cde84..5045e6ef 100644 --- a/tests/Doctrine/MongoDB/Tests/LoggableCollectionTest.php +++ b/tests/Doctrine/MongoDB/Tests/LoggableCollectionTest.php @@ -3,10 +3,12 @@ namespace Doctrine\MongoDB\Tests; use Doctrine\MongoDB\LoggableCollection; -use Doctrine\Common\EventManager; class LoggableCollectionTest extends \PHPUnit_Framework_TestCase { + const collectionName = 'collection'; + const databaseName = 'database'; + public function testLog() { $called = false; @@ -15,29 +17,30 @@ public function testLog() $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')); + $collection = $this->getTestLoggableDatabase($loggerCallable); + $collection->log(array('test' => 'test')); - $this->assertEquals(array('collection' => 'foo', 'db' => 'test', 'test' => 'test'), $called); + $this->assertEquals(array('collection' => self::collectionName, 'db' => self::databaseName, 'test' => 'test'), $called); } - private function getMockDatabase() + private function getTestLoggableDatabase($loggerCallable) { - return $this->getMockBuilder('Doctrine\MongoDB\Database') + $c = $this->getMockBuilder('Doctrine\MongoDB\Connection') ->disableOriginalConstructor() ->getMock(); - } - private function getMockConnection() - { - return $this->getMockBuilder('Doctrine\MongoDB\Connection') + $db = $this->getMockBuilder('Doctrine\MongoDB\Database') ->disableOriginalConstructor() ->getMock(); + + $db->expects($this->any()) + ->method('getName') + ->will($this->returnValue(self::databaseName)); + + $em = $this->getMockBuilder('Doctrine\Common\EventManager') + ->disableOriginalConstructor() + ->getMock(); + + return new LoggableCollection($c, self::collectionName, $db, $em, '$', $loggerCallable); } }