SequenceGeneratorTest.php 963 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Doctrine\Tests\ORM\Id;
  3. use Doctrine\ORM\Id\SequenceGenerator;
  4. require_once __DIR__ . '/../../TestInit.php';
  5. /**
  6. * Description of SequenceGeneratorTest
  7. *
  8. * @author robo
  9. */
  10. class SequenceGeneratorTest extends \Doctrine\Tests\OrmTestCase
  11. {
  12. private $_em;
  13. private $_seqGen;
  14. protected function setUp()
  15. {
  16. $this->_em = $this->_getTestEntityManager();
  17. $this->_seqGen = new SequenceGenerator('seq', 10);
  18. }
  19. public function testGeneration()
  20. {
  21. for ($i=0; $i < 42; ++$i) {
  22. if ($i % 10 == 0) {
  23. $this->_em->getConnection()->setFetchOneResult((int)($i / 10) * 10);
  24. }
  25. $id = $this->_seqGen->generate($this->_em, null);
  26. $this->assertEquals($i, $id);
  27. $this->assertEquals((int)($i / 10) * 10 + 10, $this->_seqGen->getCurrentMaxValue());
  28. $this->assertEquals($i + 1, $this->_seqGen->getNextValue());
  29. }
  30. }
  31. }