Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Commit

Permalink
Refactor LoggableCollection test
Browse files Browse the repository at this point in the history
  • Loading branch information
jmikola committed Aug 12, 2013
1 parent 839493d commit c76cdbc
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions tests/Doctrine/MongoDB/Tests/LoggableCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}

0 comments on commit c76cdbc

Please sign in to comment.