[Session] Utilize MongoDB::selectCollection()

This commit is contained in:
Jeremy Mikola 2012-12-13 15:46:59 -05:00
parent 2447757a4e
commit 20e93bf1a4
2 changed files with 5 additions and 41 deletions

View File

@ -137,7 +137,7 @@ class MongoDbSessionHandler implements \SessionHandlerInterface
private function getCollection() private function getCollection()
{ {
if (null === $this->collection) { if (null === $this->collection) {
$this->collection = $this->mongo->selectDB($this->options['database'])->selectCollection($this->options['collection']); $this->collection = $this->mongo->selectCollection($this->options['database'], $this->options['collection']);
} }
return $this->collection; return $this->collection;

View File

@ -58,22 +58,13 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
public function testWrite() public function testWrite()
{ {
$database = $this->getMockBuilder('MongoDB')
->disableOriginalConstructor()
->getMock();
$collection = $this->getMockBuilder('MongoCollection') $collection = $this->getMockBuilder('MongoCollection')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->mongo->expects($this->once()) $this->mongo->expects($this->once())
->method('selectDB')
->with($this->options['database'])
->will($this->returnValue($database));
$database->expects($this->once())
->method('selectCollection') ->method('selectCollection')
->with($this->options['collection']) ->with($this->options['database'], $this->options['collection'])
->will($this->returnValue($collection)); ->will($this->returnValue($collection));
$that = $this; $that = $this;
@ -96,22 +87,13 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
public function testReplaceSessionData() public function testReplaceSessionData()
{ {
$database = $this->getMockBuilder('MongoDB')
->disableOriginalConstructor()
->getMock();
$collection = $this->getMockBuilder('MongoCollection') $collection = $this->getMockBuilder('MongoCollection')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->mongo->expects($this->once()) $this->mongo->expects($this->once())
->method('selectDB')
->with($this->options['database'])
->will($this->returnValue($database));
$database->expects($this->once())
->method('selectCollection') ->method('selectCollection')
->with($this->options['collection']) ->with($this->options['database'], $this->options['collection'])
->will($this->returnValue($collection)); ->will($this->returnValue($collection));
$data = array(); $data = array();
@ -130,22 +112,13 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
public function testDestroy() public function testDestroy()
{ {
$database = $this->getMockBuilder('MongoDB')
->disableOriginalConstructor()
->getMock();
$collection = $this->getMockBuilder('MongoCollection') $collection = $this->getMockBuilder('MongoCollection')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->mongo->expects($this->once()) $this->mongo->expects($this->once())
->method('selectDB')
->with($this->options['database'])
->will($this->returnValue($database));
$database->expects($this->once())
->method('selectCollection') ->method('selectCollection')
->with($this->options['collection']) ->with($this->options['database'], $this->options['collection'])
->will($this->returnValue($collection)); ->will($this->returnValue($collection));
$collection->expects($this->once()) $collection->expects($this->once())
@ -160,22 +133,13 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
public function testGc() public function testGc()
{ {
$database = $this->getMockBuilder('MongoDB')
->disableOriginalConstructor()
->getMock();
$collection = $this->getMockBuilder('MongoCollection') $collection = $this->getMockBuilder('MongoCollection')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->mongo->expects($this->once()) $this->mongo->expects($this->once())
->method('selectDB')
->with($this->options['database'])
->will($this->returnValue($database));
$database->expects($this->once())
->method('selectCollection') ->method('selectCollection')
->with($this->options['collection']) ->with($this->options['database'], $this->options['collection'])
->will($this->returnValue($collection)); ->will($this->returnValue($collection));
$that = $this; $that = $this;