• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IGNF / validator-api / 37029673965

02 Oct 2026 03:49PM UTC coverage: 89.794% (+38.5%) from 51.256%
37029673965

push

github

floriancerizay
fix(tests): Fix validation database support for PostgreSQL

871 of 970 relevant lines covered (89.79%)

9.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/src/Repository/ValidationRepository.php
1
<?php
2

3
namespace App\Repository;
4

5
use App\Entity\Validation;
6
use DateTime;
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8
use Doctrine\Persistence\ManagerRegistry;
9
use SortDirection;
10

11
/**
12
 * @method Validation|null find($id, $lockMode = null, $lockVersion = null)
13
 * @method Validation|null findOneBy(array $criteria, array $orderBy = null)
14
 * @method Validation|null findOneByUid(string $uid)
15
 * @method Validation[]    findAll()
16
 * @method Validation[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
17
 */
18
class ValidationRepository extends ServiceEntityRepository
19
{
20
    public function __construct(ManagerRegistry $registry)
21
    {
22
        parent::__construct($registry, Validation::class);
64 ✔
23
    }
24

25
    /**
26
     * Update next "pending" validation to "processing" and returns it.
27
     *
28
     * @return Validation|null
29
     */
30
    public function popNextPending()
31
    {
32
        $em = $this->getEntityManager();
4 ✔
33
        $conn = $em->getConnection();
4 ✔
34
        $conn->setNestTransactionsWithSavepoints(true);
4 ✔
35

36
        $conn->beginTransaction();
4 ✔
37
        try {
38
            $conn->executeQuery('LOCK TABLE validation IN ACCESS EXCLUSIVE MODE;');
4 ✔
39

40
            /** @var Validation|null $result */
41
            $result = $this->createQueryBuilder('v')
4 ✔
42
                ->where('v.status = :status')
4 ✔
43
                ->setParameter('status', Validation::STATUS_PENDING)
4 ✔
44
                ->orderBy('v.dateCreation', SortDirection::Ascending)
4 ✔
45
                ->setMaxResults(1)
4 ✔
46
                ->getQuery()
4 ✔
47
                ->getOneOrNullResult();
4 ✔
48

49
            if (!is_null($result)) {
4 ✔
50
                $result->setStatus(Validation::STATUS_PROCESSING);
3 ✔
51
                $result->setDateStart(new DateTime('now'));
3 ✔
52
                $em->flush();
3 ✔
53
                $em->refresh($result);
3 ✔
54
            }
55

56
            $conn->commit();
4 ✔
57
        } catch (\Throwable $th) {
×
58
            // release the table lock
59
            $conn->rollBack();
×
60
            throw $th;
×
61
        }
62

63
        return $result;
4 ✔
64
    }
65

66
    /**
67
     * Finds all archivable validations older than expiryDate
68
     * (validations being processed by a worker are ignored).
69
     *
70
     * @return array<Validation>
71
     */
72
    public function findAllToBeArchived(DateTime $expiryDate)
73
    {
74
        return $this->createQueryBuilder('v')
3 ✔
75
            ->where('v.dateCreation < :expiryDate')
3 ✔
76
            ->andWhere('v.status NOT IN (:ignoredStatus)')
3 ✔
77
            ->setParameter('expiryDate', $expiryDate)
3 ✔
78
            ->setParameter('ignoredStatus', [Validation::STATUS_ARCHIVED, Validation::STATUS_PROCESSING])
3 ✔
79
            ->getQuery()
3 ✔
80
            ->getResult()
3 ✔
81
        ;
3 ✔
82
    }
83

84
    /**
85
     * Finds validations still "processing" after maxDateStart (worker killed, OOM...).
86
     *
87
     * @return array<Validation>
88
     */
89
    public function findAllInterrupted(DateTime $maxDateStart)
90
    {
91
        return $this->createQueryBuilder('v')
3 ✔
92
            ->where('v.status = :status')
3 ✔
93
            ->andWhere('v.dateStart < :maxDateStart')
3 ✔
94
            ->setParameter('status', Validation::STATUS_PROCESSING)
3 ✔
95
            ->setParameter('maxDateStart', $maxDateStart)
3 ✔
96
            ->getQuery()
3 ✔
97
            ->getResult()
3 ✔
98
        ;
3 ✔
99
    }
100

101
    /**
102
     * Drop schema corresponding to input validation.
103
     *
104
     * @return bool
105
     */
106
    public function dropSchema(Validation $validation)
107
    {
108
        $sql = sprintf('DROP SCHEMA IF EXISTS "validation%s" CASCADE', $validation->getUid());
4 ✔
109
        $reponse = $this->getEntityManager()->getConnection()->executeQuery($sql);
4 ✔
110

111
        return 0 != $reponse->rowCount();
4 ✔
112
    }
113
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc