From 49603df1b8a9791100ee0d6e65869a93ca39fa78 Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Wed, 14 Feb 2024 10:33:50 +0100 Subject: [PATCH] Revert "Doctrine Object : Move Suite Parent Id to object" --- src/Entity/Suite.php | 51 +++++------------------- src/Service/ReportMochaImporter.php | 8 ++-- src/Service/ReportPlaywrightImporter.php | 4 +- src/Service/ReportSuiteBuilder.php | 13 +++--- 4 files changed, 23 insertions(+), 53 deletions(-) diff --git a/src/Entity/Suite.php b/src/Entity/Suite.php index eb03ad40..4d1f70be 100644 --- a/src/Entity/Suite.php +++ b/src/Entity/Suite.php @@ -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; @@ -74,14 +74,12 @@ class Suite #[ORM\OneToMany(mappedBy: 'suite', targetEntity: Test::class, orphanRemoval: true)] private Collection $tests; - /** @var Collection */ - #[ORM\OneToMany(mappedBy: 'parent', targetEntity: Suite::class)] - private Collection $suites; + /** @var array */ + private array $suites = []; public function __construct() { $this->tests = new ArrayCollection(); - $this->suites = new ArrayCollection(); } public function getId(): ?int @@ -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; } @@ -358,9 +356,9 @@ public function removeTest(Test $test): static } /** - * @return Collection + * @return array */ - public function getSuites(): Collection + public function getSuites(): array { return $this->suites; } @@ -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; } diff --git a/src/Service/ReportMochaImporter.php b/src/Service/ReportMochaImporter.php index 670c1fdc..1ba9be4d 100644 --- a/src/Service/ReportMochaImporter.php +++ b/src/Service/ReportMochaImporter.php @@ -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 @@ -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()) @@ -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(); } } diff --git a/src/Service/ReportPlaywrightImporter.php b/src/Service/ReportPlaywrightImporter.php index 6cf28dfe..ee168e2d 100644 --- a/src/Service/ReportPlaywrightImporter.php +++ b/src/Service/ReportPlaywrightImporter.php @@ -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 @@ -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()) diff --git a/src/Service/ReportSuiteBuilder.php b/src/Service/ReportSuiteBuilder.php index 06008fe7..f9102fab 100644 --- a/src/Service/ReportSuiteBuilder.php +++ b/src/Service/ReportSuiteBuilder.php @@ -5,7 +5,6 @@ use App\Entity\Execution; use App\Entity\Suite; use App\Entity\Test; -use Doctrine\Common\Collections\Collection; class ReportSuiteBuilder { @@ -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; } @@ -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'), @@ -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; } @@ -290,9 +289,9 @@ private function buildTree(?int $parentId, bool $isRoot): array } /** - * @param Collection $suites + * @param array $suites */ - private function countStatus(int $basis, Collection $suites, string $status): int + private function countStatus(int $basis, array $suites, string $status): int { $num = $basis; @@ -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));