DigiComp.Sequence/Tests/Functional/SequenceTest.php

60 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace DigiComp\Sequence\Tests\Functional;
use DigiComp\Sequence\Service\SequenceGenerator;
2017-03-13 16:59:04 +01:00
use Neos\Flow\Tests\FunctionalTestCase;
class SequenceTest extends FunctionalTestCase
{
2017-03-13 16:59:04 +01:00
/**
* @var bool
*/
protected static $testablePersistenceEnabled = true;
/**
* @test
*/
public function sequenceTest()
{
$sequenceGenerator = $this->objectManager->get(SequenceGenerator::class);
$number = $sequenceGenerator->getLastNumberFor($sequenceGenerator);
$this->assertEquals(0, $number);
$this->assertEquals(1, $sequenceGenerator->getNextNumberFor($sequenceGenerator));
2017-03-13 16:59:04 +01:00
$pIds = [];
for ($i = 0; $i < 10; $i++) {
2017-03-13 16:59:04 +01:00
$pId = pcntl_fork();
if ($pId) {
$pIds[] = $pId;
}
else {
for ($j = 0; $j < 10; $j++) {
$sequenceGenerator->getNextNumberFor($sequenceGenerator);
}
// making a hard exit to avoid phpunit having the tables cleaned up again
exit;
}
}
2017-03-13 16:59:04 +01:00
foreach ($pIds as $pId) {
$status = 0;
2017-03-13 16:59:04 +01:00
pcntl_waitpid($pId, $status);
}
2017-03-13 16:59:04 +01:00
$this->assertEquals(101, $sequenceGenerator->getLastNumberFor($sequenceGenerator));
}
/**
* @test
*/
public function advanceTest()
{
$sequenceGenerator = $this->objectManager->get(SequenceGenerator::class);
$sequenceGenerator->advanceTo(100, $sequenceGenerator);
$this->assertEquals(100, $sequenceGenerator->getLastNumberFor($sequenceGenerator));
$this->assertEquals(0, $sequenceGenerator->getLastNumberFor('strangeOtherSequence'));
}
}