Permalink
Browse files

Use constant collection name in CollectionTest

  • Loading branch information...
1 parent 88de5ad commit b7c9871b20d912b887469ce16c86a675f5e712b4 @jmikola jmikola committed Mar 7, 2013
Showing with 17 additions and 27 deletions.
  1. +17 −27 tests/Doctrine/MongoDB/Tests/CollectionTest.php
View
44 tests/Doctrine/MongoDB/Tests/CollectionTest.php
@@ -9,6 +9,8 @@
class CollectionTest extends \PHPUnit_Framework_TestCase
{
+ const collectionName = 'collection';
+
public function testBatchInsert()
{
$docs = array(array('x' => 1, 'y' => 2));
@@ -87,26 +89,20 @@ public function testFindAndRemove()
$query = array('completed' => true);
$command = array(
- 'findandmodify' => 'collection',
+ 'findandmodify' => self::collectionName,
'query' => $query,
'remove' => true,
);
$document = array('_id' => 1, 'completed' => true);
- $mongoCollection = $this->getMockMongoCollection();
$database = $this->getMockDatabase();
-
- $mongoCollection->expects($this->any())
- ->method('getName')
- ->will($this->returnValue('collection'));
-
$database->expects($this->once())
->method('command')
->with($command)
->will($this->returnValue(array('value' => $document)));
- $coll = $this->getTestCollection($this->getMockConnection(), $mongoCollection, $database);
+ $coll = $this->getTestCollection($this->getMockConnection(), $this->getMockMongoCollection(), $database);
$this->assertEquals($document, $coll->findAndRemove($query));
}
@@ -118,27 +114,21 @@ public function testFindAndModify()
$options = array('new' => true);
$command = array(
- 'findandmodify' => 'collection',
+ 'findandmodify' => self::collectionName,
'query' => $query,
'update' => $newObj,
'new' => true,
);
$document = array('_id' => 1, 'inprogress' => true);
- $mongoCollection = $this->getMockMongoCollection();
$database = $this->getMockDatabase();
-
- $mongoCollection->expects($this->any())
- ->method('getName')
- ->will($this->returnValue('collection'));
-
$database->expects($this->once())
->method('command')
->with($command)
->will($this->returnValue(array('value' => $document)));
- $coll = $this->getTestCollection($this->getMockConnection(), $mongoCollection, $database);
+ $coll = $this->getTestCollection($this->getMockConnection(), $this->getMockMongoCollection(), $database);
$this->assertEquals($document, $coll->findAndUpdate($query, $newObj, $options));
}
@@ -303,15 +293,9 @@ public function provideIsFieldIndex()
public function testGetName()
{
- $mongoCollection = $this->getMockMongoCollection();
-
- $mongoCollection->expects($this->once())
- ->method('getName')
- ->will($this->returnValue('collection'));
-
- $coll = $this->getTestCollection($this->getMockConnection(), $mongoCollection, $this->getMockDatabase());
+ $coll = $this->getTestCollection($this->getMockConnection(), $this->getMockMongoCollection(), $this->getMockDatabase());
- $this->assertEquals('collection', $coll->getName());
+ $this->assertEquals(self::collectionName, $coll->getName());
}
public function testGroupWithNonEmptyOptionsArray()
@@ -533,11 +517,11 @@ public function testToString()
$mongoCollection->expects($this->once())
->method('__toString')
- ->will($this->returnValue('collection'));
+ ->will($this->returnValue(self::collectionName));
$coll = $this->getTestCollection($this->getMockConnection(), $mongoCollection, $this->getMockDatabase());
- $this->assertEquals('collection', $coll->__toString());
+ $this->assertEquals(self::collectionName, $coll->__toString());
}
private function getMockMongoCursor()
@@ -549,9 +533,15 @@ private function getMockMongoCursor()
private function getMockMongoCollection()
{
- return $this->getMockBuilder('MongoCollection')
+ $mongoCollection = $this->getMockBuilder('MongoCollection')
->disableOriginalConstructor()
->getMock();
+
+ $mongoCollection->expects($this->any())
+ ->method('getName')
+ ->will($this->returnValue(self::collectionName));
+
+ return $mongoCollection;
}
private function getMockDatabase()

0 comments on commit b7c9871

Please sign in to comment.