Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1661 from alcaeus/increment-generator-custom-star…
…t-value Enable a custom starting id
- Loading branch information
Showing
4 changed files
with
110 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
tests/Doctrine/ODM/MongoDB/Tests/Id/IncrementGeneratorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Doctrine\ODM\MongoDB\Tests\Id; | ||
|
||
use Doctrine\ODM\MongoDB\Id\IncrementGenerator; | ||
use Documents\User; | ||
|
||
class IncrementGeneratorTest extends \Doctrine\ODM\MongoDB\Tests\BaseTest | ||
{ | ||
public function testIdGeneratorWithStartingValue() | ||
{ | ||
$generator = new IncrementGenerator(); | ||
$generator->setStartingId(10); | ||
|
||
$collection = $this->dm->getConnection()->selectCollection(DOCTRINE_MONGODB_DATABASE, 'doctrine_increment_ids'); | ||
|
||
$this->assertSame(10, $generator->generate($this->dm, new User())); | ||
$result = $collection->findOne(['_id' => 'users']); | ||
self::assertSame(10, $result['current_id']); | ||
|
||
$this->assertSame(11, $generator->generate($this->dm, new User())); | ||
$result = $collection->findOne(['_id' => 'users']); | ||
self::assertSame(11, $result['current_id']); | ||
} | ||
|
||
public function testUsesOneAsStartingValueIfNotOverridden() | ||
{ | ||
$generator = new IncrementGenerator(); | ||
|
||
$this->assertSame(1, $generator->generate($this->dm, new User())); | ||
|
||
$collection = $this->dm->getConnection()->selectCollection(DOCTRINE_MONGODB_DATABASE, 'doctrine_increment_ids'); | ||
$result = $collection->findOne(['_id' => 'users']); | ||
self::assertSame(1, $result['current_id']); | ||
} | ||
} |