Skip to content

Commit 7bcac01

Browse files
authored
Merge pull request #141 from PrestaShop/develop
Merge `develop` into `master`
2 parents f01465a + cd81195 commit 7bcac01

File tree

4 files changed

+23
-53
lines changed

4 files changed

+23
-53
lines changed

src/Entity/Suite.php

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ class Suite
6464
#[ORM\Column(name: 'hasTests', nullable: true)]
6565
private ?bool $hasTests = null;
6666

67-
#[ORM\ManyToOne(inversedBy: 'suites')]
68-
private ?Suite $parent = null;
67+
#[ORM\Column(nullable: true)]
68+
private ?int $parent_id = null;
6969

7070
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
7171
private ?\DateTime $insertion_date = null;
@@ -74,14 +74,12 @@ class Suite
7474
#[ORM\OneToMany(mappedBy: 'suite', targetEntity: Test::class, orphanRemoval: true)]
7575
private Collection $tests;
7676

77-
/** @var Collection<int, Suite> */
78-
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: Suite::class)]
79-
private Collection $suites;
77+
/** @var array<int, Suite> */
78+
private array $suites = [];
8079

8180
public function __construct()
8281
{
8382
$this->tests = new ArrayCollection();
84-
$this->suites = new ArrayCollection();
8583
}
8684

8785
public function getId(): ?int
@@ -288,14 +286,14 @@ public function setHasTests(?bool $hasTests): static
288286
return $this;
289287
}
290288

291-
public function getParent(): ?Suite
289+
public function getParentId(): ?int
292290
{
293-
return $this->parent;
291+
return $this->parent_id;
294292
}
295293

296-
public function setParent(?Suite $parent): static
294+
public function setParentId(?int $parent_id): static
297295
{
298-
$this->parent = $parent;
296+
$this->parent_id = $parent_id;
299297

300298
return $this;
301299
}
@@ -358,9 +356,9 @@ public function removeTest(Test $test): static
358356
}
359357

360358
/**
361-
* @return Collection<int, Suite>
359+
* @return array<int, Suite>
362360
*/
363-
public function getSuites(): Collection
361+
public function getSuites(): array
364362
{
365363
return $this->suites;
366364
}
@@ -370,34 +368,7 @@ public function getSuites(): Collection
370368
*/
371369
public function setSuites(array $suites): static
372370
{
373-
foreach ($this->suites as $suite) {
374-
$this->removeSuite($suite);
375-
}
376-
foreach ($suites as $suite) {
377-
$this->addSuite($suite);
378-
}
379-
380-
return $this;
381-
}
382-
383-
public function addSuite(Suite $suite): static
384-
{
385-
if (!$this->suites->contains($suite)) {
386-
$this->suites->add($suite);
387-
$suite->setParent($this);
388-
}
389-
390-
return $this;
391-
}
392-
393-
public function removeSuite(Suite $suite): static
394-
{
395-
if ($this->suites->removeElement($suite)) {
396-
// set the owning side to null (unless already changed)
397-
if ($suite->getParent() === $this) {
398-
$suite->setParent(null);
399-
}
400-
}
371+
$this->suites = $suites;
401372

402373
return $this;
403374
}

src/Service/ReportMochaImporter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function import(
7878
return $execution;
7979
}
8080

81-
private function insertExecutionSuite(Execution $execution, \stdClass $suite, ?Suite $parentSuite = null): void
81+
private function insertExecutionSuite(Execution $execution, \stdClass $suite, ?int $parentSuiteId = null): void
8282
{
8383
$executionSuite = new Suite();
8484
$executionSuite
@@ -96,7 +96,7 @@ private function insertExecutionSuite(Execution $execution, \stdClass $suite, ?S
9696
->setTotalPending(count($suite->pending))
9797
->setTotalPasses(count($suite->passes))
9898
->setTotalFailures(count($suite->failures))
99-
->setParent($parentSuite)
99+
->setParentId($parentSuiteId)
100100
->setCampaign($this->extractDataFromFile($suite->file, 'campaign'))
101101
->setFile($this->extractDataFromFile($suite->file, 'file'))
102102
->setInsertionDate(new \DateTime())
@@ -130,9 +130,9 @@ private function insertExecutionSuite(Execution $execution, \stdClass $suite, ?S
130130

131131
// Insert children suites
132132
foreach ($suite->suites as $suiteChildren) {
133-
$this->insertExecutionSuite($execution, $suiteChildren, $executionSuite);
133+
$this->insertExecutionSuite($execution, $suiteChildren, $executionSuite->getId());
134134
}
135-
if (!$parentSuite) {
135+
if (!$parentSuiteId) {
136136
$this->entityManager->clear();
137137
}
138138
}

src/Service/ReportPlaywrightImporter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function import(
8484
return $execution;
8585
}
8686

87-
protected function insertExecutionSuite(Execution $execution, \stdClass $suite): Suite
87+
protected function insertExecutionSuite(Execution $execution, \stdClass $suite, ?int $parentSuiteId = null): Suite
8888
{
8989
$executionSuite = new Suite();
9090
$executionSuite
@@ -94,7 +94,7 @@ protected function insertExecutionSuite(Execution $execution, \stdClass $suite):
9494
->setTitle($suite->title)
9595
->setHasSuites(false)
9696
->setHasTests(!empty($suite->specs))
97-
->setParent(null)
97+
->setParentId($parentSuiteId)
9898
->setCampaign($this->extractDataFromFile('/' . $suite->file, 'campaign'))
9999
->setFile($this->extractDataFromFile('/' . $suite->file, 'file'))
100100
->setInsertionDate(new \DateTime())

src/Service/ReportSuiteBuilder.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use App\Entity\Execution;
66
use App\Entity\Suite;
77
use App\Entity\Test;
8-
use Doctrine\Common\Collections\Collection;
98

109
class ReportSuiteBuilder
1110
{
@@ -78,7 +77,7 @@ public function build(Execution $execution): self
7877
$hasOnlyOneMainSuite = false;
7978
$mainSuiteId = null;
8079
foreach ($this->suites as $suite) {
81-
if ($suite->getParent()) {
80+
if ($suite->getParentId()) {
8281
continue;
8382
}
8483

@@ -158,7 +157,7 @@ private function formatSuite(Suite $suite): array
158157
'totalFailures' => $suite->getTotalFailures(),
159158
'hasSuites' => $suite->getHasSuites() ? 1 : 0,
160159
'hasTests' => $suite->getHasTests() ? 1 : 0,
161-
'parent_id' => $suite->getParent()?->getId(),
160+
'parent_id' => $suite->getParentId(),
162161
'insertion_date' => $suite->getInsertionDate()
163162
->setTimezone(new \DateTimeZone('-01:00'))
164163
->format('Y-m-d H:i:s'),
@@ -238,7 +237,7 @@ private function buildTree(?int $parentId, bool $isRoot): array
238237
&& $suite->getId() !== $this->filterSuiteId) {
239238
continue;
240239
}
241-
if ($suite->getParent()?->getId() !== $parentId) {
240+
if ($suite->getParentId() !== $parentId) {
242241
continue;
243242
}
244243

@@ -290,9 +289,9 @@ private function buildTree(?int $parentId, bool $isRoot): array
290289
}
291290

292291
/**
293-
* @param Collection<int, Suite> $suites
292+
* @param array<int, Suite> $suites
294293
*/
295-
private function countStatus(int $basis, Collection $suites, string $status): int
294+
private function countStatus(int $basis, array $suites, string $status): int
296295
{
297296
$num = $basis;
298297

@@ -317,7 +316,7 @@ private function countStatus(int $basis, Collection $suites, string $status): in
317316
private function filterTree(array $suites): array
318317
{
319318
foreach ($suites as $key => &$suite) {
320-
$suiteChildren = $suite->getSuites()->toArray();
319+
$suiteChildren = $suite->getSuites();
321320
$numSuiteTests = $suite->getTests()->count();
322321
if (!empty($suiteChildren)) {
323322
$suite->setSuites($this->filterTree($suiteChildren));

0 commit comments

Comments
 (0)