Skip to content

Commit

Permalink
Merge pull request #141 from PrestaShop/develop
Browse files Browse the repository at this point in the history
Merge `develop` into `master`
  • Loading branch information
Progi1984 authored Feb 14, 2024
2 parents f01465a + cd81195 commit 7bcac01
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 53 deletions.
51 changes: 11 additions & 40 deletions src/Entity/Suite.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class Suite
#[ORM\Column(name: 'hasTests', nullable: true)]
private ?bool $hasTests = null;

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

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

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

public function __construct()
{
$this->tests = new ArrayCollection();
$this->suites = new ArrayCollection();
}

public function getId(): ?int
Expand Down Expand Up @@ -288,14 +286,14 @@ public function setHasTests(?bool $hasTests): static
return $this;
}

public function getParent(): ?Suite
public function getParentId(): ?int
{
return $this->parent;
return $this->parent_id;
}

public function setParent(?Suite $parent): static
public function setParentId(?int $parent_id): static
{
$this->parent = $parent;
$this->parent_id = $parent_id;

return $this;
}
Expand Down Expand Up @@ -358,9 +356,9 @@ public function removeTest(Test $test): static
}

/**
* @return Collection<int, Suite>
* @return array<int, Suite>
*/
public function getSuites(): Collection
public function getSuites(): array
{
return $this->suites;
}
Expand All @@ -370,34 +368,7 @@ public function getSuites(): Collection
*/
public function setSuites(array $suites): static
{
foreach ($this->suites as $suite) {
$this->removeSuite($suite);
}
foreach ($suites as $suite) {
$this->addSuite($suite);
}

return $this;
}

public function addSuite(Suite $suite): static
{
if (!$this->suites->contains($suite)) {
$this->suites->add($suite);
$suite->setParent($this);
}

return $this;
}

public function removeSuite(Suite $suite): static
{
if ($this->suites->removeElement($suite)) {
// set the owning side to null (unless already changed)
if ($suite->getParent() === $this) {
$suite->setParent(null);
}
}
$this->suites = $suites;

return $this;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Service/ReportMochaImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function import(
return $execution;
}

private function insertExecutionSuite(Execution $execution, \stdClass $suite, ?Suite $parentSuite = null): void
private function insertExecutionSuite(Execution $execution, \stdClass $suite, ?int $parentSuiteId = null): void
{
$executionSuite = new Suite();
$executionSuite
Expand All @@ -96,7 +96,7 @@ private function insertExecutionSuite(Execution $execution, \stdClass $suite, ?S
->setTotalPending(count($suite->pending))
->setTotalPasses(count($suite->passes))
->setTotalFailures(count($suite->failures))
->setParent($parentSuite)
->setParentId($parentSuiteId)
->setCampaign($this->extractDataFromFile($suite->file, 'campaign'))
->setFile($this->extractDataFromFile($suite->file, 'file'))
->setInsertionDate(new \DateTime())
Expand Down Expand Up @@ -130,9 +130,9 @@ private function insertExecutionSuite(Execution $execution, \stdClass $suite, ?S

// Insert children suites
foreach ($suite->suites as $suiteChildren) {
$this->insertExecutionSuite($execution, $suiteChildren, $executionSuite);
$this->insertExecutionSuite($execution, $suiteChildren, $executionSuite->getId());
}
if (!$parentSuite) {
if (!$parentSuiteId) {
$this->entityManager->clear();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Service/ReportPlaywrightImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function import(
return $execution;
}

protected function insertExecutionSuite(Execution $execution, \stdClass $suite): Suite
protected function insertExecutionSuite(Execution $execution, \stdClass $suite, ?int $parentSuiteId = null): Suite
{
$executionSuite = new Suite();
$executionSuite
Expand All @@ -94,7 +94,7 @@ protected function insertExecutionSuite(Execution $execution, \stdClass $suite):
->setTitle($suite->title)
->setHasSuites(false)
->setHasTests(!empty($suite->specs))
->setParent(null)
->setParentId($parentSuiteId)
->setCampaign($this->extractDataFromFile('/' . $suite->file, 'campaign'))
->setFile($this->extractDataFromFile('/' . $suite->file, 'file'))
->setInsertionDate(new \DateTime())
Expand Down
13 changes: 6 additions & 7 deletions src/Service/ReportSuiteBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Entity\Execution;
use App\Entity\Suite;
use App\Entity\Test;
use Doctrine\Common\Collections\Collection;

class ReportSuiteBuilder
{
Expand Down Expand Up @@ -78,7 +77,7 @@ public function build(Execution $execution): self
$hasOnlyOneMainSuite = false;
$mainSuiteId = null;
foreach ($this->suites as $suite) {
if ($suite->getParent()) {
if ($suite->getParentId()) {
continue;
}

Expand Down Expand Up @@ -158,7 +157,7 @@ private function formatSuite(Suite $suite): array
'totalFailures' => $suite->getTotalFailures(),
'hasSuites' => $suite->getHasSuites() ? 1 : 0,
'hasTests' => $suite->getHasTests() ? 1 : 0,
'parent_id' => $suite->getParent()?->getId(),
'parent_id' => $suite->getParentId(),
'insertion_date' => $suite->getInsertionDate()
->setTimezone(new \DateTimeZone('-01:00'))
->format('Y-m-d H:i:s'),
Expand Down Expand Up @@ -238,7 +237,7 @@ private function buildTree(?int $parentId, bool $isRoot): array
&& $suite->getId() !== $this->filterSuiteId) {
continue;
}
if ($suite->getParent()?->getId() !== $parentId) {
if ($suite->getParentId() !== $parentId) {
continue;
}

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

/**
* @param Collection<int, Suite> $suites
* @param array<int, Suite> $suites
*/
private function countStatus(int $basis, Collection $suites, string $status): int
private function countStatus(int $basis, array $suites, string $status): int
{
$num = $basis;

Expand All @@ -317,7 +316,7 @@ private function countStatus(int $basis, Collection $suites, string $status): in
private function filterTree(array $suites): array
{
foreach ($suites as $key => &$suite) {
$suiteChildren = $suite->getSuites()->toArray();
$suiteChildren = $suite->getSuites();
$numSuiteTests = $suite->getTests()->count();
if (!empty($suiteChildren)) {
$suite->setSuites($this->filterTree($suiteChildren));
Expand Down

0 comments on commit 7bcac01

Please sign in to comment.