diff --git a/Classes/Command/SequenceCommandController.php b/Classes/Command/SequenceCommandController.php index ce884f8..cf9dc7e 100644 --- a/Classes/Command/SequenceCommandController.php +++ b/Classes/Command/SequenceCommandController.php @@ -5,7 +5,10 @@ declare(strict_types=1); namespace DigiComp\Sequence\Command; use DigiComp\Sequence\Domain\Model\Insert; +use DigiComp\Sequence\Service\Exception as DigiCompSequenceServiceException; use DigiComp\Sequence\Service\SequenceGenerator; +use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException; +use Doctrine\DBAL\Exception as DoctrineDBALException; use Doctrine\ORM\EntityManagerInterface; use Neos\Flow\Annotations as Flow; use Neos\Flow\Cli\CommandController; @@ -34,6 +37,7 @@ class SequenceCommandController extends CommandController * * @param int $to * @param string $type + * @throws DigiCompSequenceServiceException */ public function advanceCommand(int $to, string $type): void { @@ -42,6 +46,9 @@ class SequenceCommandController extends CommandController /** * @param string[] $typesToClean + * @throws DigiCompSequenceServiceException + * @throws DoctrineDBALDriverException + * @throws DoctrineDBALException */ public function cleanSequenceInsertsCommand(array $typesToClean = []) { diff --git a/Classes/Service/SequenceGenerator.php b/Classes/Service/SequenceGenerator.php index d9a3399..7c7b744 100644 --- a/Classes/Service/SequenceGenerator.php +++ b/Classes/Service/SequenceGenerator.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace DigiComp\Sequence\Service; use DigiComp\Sequence\Domain\Model\Insert; +use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException; use Doctrine\DBAL\Exception as DoctrineDBALException; use Doctrine\ORM\EntityManagerInterface; use Neos\Flow\Annotations as Flow; @@ -37,6 +38,7 @@ class SequenceGenerator * @param string|object $type * @return int * @throws Exception + * @throws DoctrineDBALDriverException * @throws DoctrineDBALException */ public function getNextNumberFor($type): int @@ -71,10 +73,10 @@ class SequenceGenerator return false; } catch (DoctrineDBALException $e) { if (!$e->getPrevious() instanceof \PDOException) { - $this->logger->critical('Exception occured: ' . $e->getMessage()); + $this->logger->critical('Exception occurred: ' . $e->getMessage()); } } catch (\Exception $e) { - $this->logger->critical('Exception occured: ' . $e->getMessage()); + $this->logger->critical('Exception occurred: ' . $e->getMessage()); } return false; @@ -98,6 +100,7 @@ class SequenceGenerator * @param string|object $type * @return int * @throws Exception + * @throws DoctrineDBALDriverException * @throws DoctrineDBALException */ public function getLastNumberFor($type): int @@ -107,7 +110,7 @@ class SequenceGenerator . $this->entityManager->getClassMetadata(Insert::class)->getTableName() . ' WHERE type = :type', ['type' => $this->inferTypeFromSource($type)] - )->fetchAll(\PDO::FETCH_COLUMN)[0]; + )->fetchOne(); } /** diff --git a/Tests/Functional/SequenceTest.php b/Tests/Functional/SequenceTest.php index 7913837..b400c34 100644 --- a/Tests/Functional/SequenceTest.php +++ b/Tests/Functional/SequenceTest.php @@ -2,18 +2,24 @@ namespace DigiComp\Sequence\Tests\Functional; +use DigiComp\Sequence\Service\Exception as DigiCompSequenceServiceException; use DigiComp\Sequence\Service\SequenceGenerator; +use Doctrine\DBAL\Driver\Exception as DoctrineDBALDriverException; +use Doctrine\DBAL\Exception as DoctrineDBALException; use Neos\Flow\Tests\FunctionalTestCase; class SequenceTest extends FunctionalTestCase { /** - * @var bool + * @inheritDoc */ protected static $testablePersistenceEnabled = true; /** * @test + * @throws DigiCompSequenceServiceException + * @throws DoctrineDBALDriverException + * @throws DoctrineDBALException */ public function sequenceTest() { @@ -47,6 +53,9 @@ class SequenceTest extends FunctionalTestCase /** * @test + * @throws DigiCompSequenceServiceException + * @throws DoctrineDBALDriverException + * @throws DoctrineDBALException */ public function advanceTest() { diff --git a/composer.json b/composer.json index b77183f..cace62e 100644 --- a/composer.json +++ b/composer.json @@ -3,6 +3,7 @@ "description": "Sequence is a very simple database agnostic but database based sequence generator", "type": "neos-package", "require": { + "ext-pdo": "*", "neos/flow": "^5.3.0 || ^6.3.5", "php": "~7.4.0" },