2016-06-24 20:35:59 +02:00
|
|
|
<?php
|
2020-03-10 14:48:58 +01:00
|
|
|
|
2016-06-24 20:35:59 +02:00
|
|
|
namespace DigiComp\Sequence\Tests\Functional;
|
|
|
|
|
|
|
|
use DigiComp\Sequence\Service\SequenceGenerator;
|
2017-03-13 16:59:04 +01:00
|
|
|
use Neos\Flow\Tests\FunctionalTestCase;
|
2016-06-24 20:35:59 +02:00
|
|
|
|
|
|
|
class SequenceTest extends FunctionalTestCase
|
|
|
|
{
|
2017-03-13 16:59:04 +01:00
|
|
|
/**
|
|
|
|
* @var bool
|
|
|
|
*/
|
2016-06-24 20:35:59 +02:00
|
|
|
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 = [];
|
2016-06-24 20:35:59 +02:00
|
|
|
for ($i = 0; $i < 10; $i++) {
|
2021-09-16 15:30:22 +02:00
|
|
|
$pId = \pcntl_fork();
|
2017-03-13 16:59:04 +01:00
|
|
|
if ($pId) {
|
|
|
|
$pIds[] = $pId;
|
2020-03-10 14:48:58 +01:00
|
|
|
} else {
|
2016-06-24 20:35:59 +02:00
|
|
|
for ($j = 0; $j < 10; $j++) {
|
|
|
|
$sequenceGenerator->getNextNumberFor($sequenceGenerator);
|
|
|
|
}
|
2019-12-04 12:48:02 +01:00
|
|
|
// making a hard exit to avoid phpunit having the tables cleaned up again
|
2016-06-24 20:35:59 +02:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
2017-03-13 16:59:04 +01:00
|
|
|
|
|
|
|
foreach ($pIds as $pId) {
|
2016-06-24 20:35:59 +02:00
|
|
|
$status = 0;
|
2021-09-16 15:30:22 +02:00
|
|
|
\pcntl_waitpid($pId, $status);
|
2016-06-24 20:35:59 +02:00
|
|
|
}
|
2017-03-13 16:59:04 +01:00
|
|
|
|
2016-06-24 20:35:59 +02: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'));
|
|
|
|
}
|
|
|
|
}
|