2016-06-24 20:35:59 +02:00
|
|
|
<?php
|
2020-03-10 14:48:58 +01:00
|
|
|
|
2021-09-22 11:34:34 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-06-24 20:35:59 +02:00
|
|
|
namespace DigiComp\Sequence\Tests\Functional;
|
|
|
|
|
2021-09-22 11:34:34 +02:00
|
|
|
use DigiComp\Sequence\Service\Exception\InvalidSourceException;
|
2016-06-24 20:35:59 +02:00
|
|
|
use DigiComp\Sequence\Service\SequenceGenerator;
|
2021-09-21 10:39:03 +02:00
|
|
|
use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException;
|
|
|
|
use Doctrine\DBAL\Exception as DoctrineDBALException;
|
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
|
|
|
/**
|
2021-09-21 10:39:03 +02:00
|
|
|
* @inheritDoc
|
2017-03-13 16:59:04 +01:00
|
|
|
*/
|
2016-06-24 20:35:59 +02:00
|
|
|
protected static $testablePersistenceEnabled = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2021-09-21 10:39:03 +02:00
|
|
|
* @throws DoctrineDBALDriverException
|
|
|
|
* @throws DoctrineDBALException
|
2021-09-22 11:34:34 +02:00
|
|
|
* @throws InvalidSourceException
|
2016-06-24 20:35:59 +02:00
|
|
|
*/
|
2021-09-23 08:55:03 +02:00
|
|
|
public function sequenceTest(): void
|
2016-06-24 20:35:59 +02:00
|
|
|
{
|
|
|
|
$sequenceGenerator = $this->objectManager->get(SequenceGenerator::class);
|
|
|
|
|
2021-09-22 11:34:34 +02:00
|
|
|
$this->assertEquals(0, $sequenceGenerator->getLastNumberFor($sequenceGenerator));
|
2016-06-24 20:35:59 +02:00
|
|
|
$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();
|
2021-09-22 11:34:34 +02:00
|
|
|
if ($pId > 0) {
|
2017-03-13 16:59:04 +01:00
|
|
|
$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
|
2021-09-21 10:39:03 +02:00
|
|
|
* @throws DoctrineDBALDriverException
|
|
|
|
* @throws DoctrineDBALException
|
2021-09-22 11:34:34 +02:00
|
|
|
* @throws InvalidSourceException
|
2016-06-24 20:35:59 +02:00
|
|
|
*/
|
2021-09-23 08:55:03 +02:00
|
|
|
public function setLastNumberForTest(): void
|
2016-06-24 20:35:59 +02:00
|
|
|
{
|
|
|
|
$sequenceGenerator = $this->objectManager->get(SequenceGenerator::class);
|
|
|
|
|
2021-09-22 11:34:34 +02:00
|
|
|
$sequenceGenerator->setLastNumberFor($sequenceGenerator, 100);
|
|
|
|
|
2016-06-24 20:35:59 +02:00
|
|
|
$this->assertEquals(100, $sequenceGenerator->getLastNumberFor($sequenceGenerator));
|
2021-09-22 11:34:34 +02:00
|
|
|
$this->assertEquals(0, $sequenceGenerator->getLastNumberFor('otherSequence'));
|
2016-06-24 20:35:59 +02:00
|
|
|
}
|
|
|
|
}
|