Skip to content

Commit f01465a

Browse files
authored
Merge pull request #133 from PrestaShop/develop
Merge `develop` into `master`
2 parents 9799a27 + 95dc98b commit f01465a

File tree

8 files changed

+363
-299
lines changed

8 files changed

+363
-299
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ Set up a vhost that points to the `/public` folder (example in the `vhost.conf`
3535

3636
## Inserting new data
3737

38-
Use the hook provided in the `Hook` controller. You need to call this URL: `BASE_URL/hook/reports/import` with the following GET
39-
parameters:
38+
Use the hook provided in the `Hook` controller.
39+
You need to call one of these URLs with the method `GET`:
40+
- `BASE_URL/hook/reports/import` (for a Mocha Import)
41+
- `BASE_URL/import/report/playwright` (for a Playwright Import)
42+
43+
You can add these parameters in the query:
4044
- `token`: the token set in the environment variable `QANB_TOKEN` (e.g.: `IpBzOmwXQUrW5Hn`)
4145
- `filename` : the complete filename to look for in the Google Cloud Storage (e.g.: `2019-07-22-develop.json`). The
4246
name must follow this pattern: `/[0-9]{4}-[0-9]{2}-[0-9]{2}-(.*)?\.json/`
@@ -47,6 +51,7 @@ Optional:
4751
- `campaign`: to specify the campaign. Possible values are 'functional' (default), 'sanity', 'e2e', and 'regression'.
4852

4953
EG : `api.mysite.com/hook/reports/import?token=IpBzOmwXQUrW5Hn&filename=2019-07-22-develop.json`
54+
EG : `api.mysite.com/import/report/playwright?token=IpBzOmwXQUrW5Hn&filename=2019-07-22-develop.json`
5055

5156
The files in the Google Cloud Storage might be huge, so be sure your server is properly configured to handle large files.
5257

composer.lock

Lines changed: 257 additions & 260 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Controller/ReportController.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,18 @@ public function __construct(
3737
public function reports(Request $request): JsonResponse
3838
{
3939
$executionFilters = [];
40+
$requestParams = $request->query->all();
4041

41-
if ($request->query->has('filter_platform')) {
42-
$executionFilters['platform'] = $request->query->get('filter_platform');
43-
} elseif ($request->query->has('filter_browser')) {
44-
$executionFilters['platform'] = $request->query->get('filter_browser');
42+
if (isset($requestParams['filter_platform'])) {
43+
$executionFilters['platform'] = $requestParams['filter_platform'];
44+
} elseif (isset($requestParams['filter_browser'])) {
45+
$executionFilters['platform'] = $requestParams['filter_browser'];
4546
}
46-
if ($request->query->has('filter_campaign')) {
47-
$executionFilters['campaign'] = $request->query->get('filter_campaign');
47+
if (isset($requestParams['filter_campaign'])) {
48+
$executionFilters['campaign'] = $requestParams['filter_campaign'];
4849
}
49-
if ($request->query->has('filter_version')) {
50-
$executionFilters['version'] = $request->query->get('filter_version');
50+
if (isset($requestParams['filter_version'])) {
51+
$executionFilters['version'] = $requestParams['filter_version'];
5152
}
5253
$executions = $this->executionRepository->findBy($executionFilters, [
5354
'start_date' => 'DESC',

src/Entity/Suite.php

Lines changed: 40 additions & 11 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\Column(nullable: true)]
68-
private ?int $parent_id = null;
67+
#[ORM\ManyToOne(inversedBy: 'suites')]
68+
private ?Suite $parent = null;
6969

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

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

8081
public function __construct()
8182
{
8283
$this->tests = new ArrayCollection();
84+
$this->suites = new ArrayCollection();
8385
}
8486

8587
public function getId(): ?int
@@ -286,14 +288,14 @@ public function setHasTests(?bool $hasTests): static
286288
return $this;
287289
}
288290

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

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

298300
return $this;
299301
}
@@ -356,9 +358,9 @@ public function removeTest(Test $test): static
356358
}
357359

358360
/**
359-
* @return array<int, Suite>
361+
* @return Collection<int, Suite>
360362
*/
361-
public function getSuites(): array
363+
public function getSuites(): Collection
362364
{
363365
return $this->suites;
364366
}
@@ -368,7 +370,34 @@ public function getSuites(): array
368370
*/
369371
public function setSuites(array $suites): static
370372
{
371-
$this->suites = $suites;
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+
}
372401

373402
return $this;
374403
}

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, int $parentSuiteId = null): void
81+
private function insertExecutionSuite(Execution $execution, \stdClass $suite, ?Suite $parentSuite = null): void
8282
{
8383
$executionSuite = new Suite();
8484
$executionSuite
@@ -96,7 +96,7 @@ private function insertExecutionSuite(Execution $execution, \stdClass $suite, in
9696
->setTotalPending(count($suite->pending))
9797
->setTotalPasses(count($suite->passes))
9898
->setTotalFailures(count($suite->failures))
99-
->setParentId($parentSuiteId)
99+
->setParent($parentSuite)
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, in
130130

131131
// Insert children suites
132132
foreach ($suite->suites as $suiteChildren) {
133-
$this->insertExecutionSuite($execution, $suiteChildren, $executionSuite->getId());
133+
$this->insertExecutionSuite($execution, $suiteChildren, $executionSuite);
134134
}
135-
if (!$parentSuiteId) {
135+
if (!$parentSuite) {
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, int $parentSuiteId = null): Suite
87+
protected function insertExecutionSuite(Execution $execution, \stdClass $suite): 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-
->setParentId($parentSuiteId)
97+
->setParent(null)
9898
->setCampaign($this->extractDataFromFile('/' . $suite->file, 'campaign'))
9999
->setFile($this->extractDataFromFile('/' . $suite->file, 'file'))
100100
->setInsertionDate(new \DateTime())

src/Service/ReportSuiteBuilder.php

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

910
class ReportSuiteBuilder
1011
{
@@ -45,7 +46,7 @@ public function filterEmptyArrays(bool $filterEmptyArrays): self
4546
return $this;
4647
}
4748

48-
public function filterSearch(string $search = null): self
49+
public function filterSearch(?string $search = null): self
4950
{
5051
$this->filterSearch = $search;
5152

@@ -62,7 +63,7 @@ public function filterStates(array $states = self::FILTER_STATES): self
6263
return $this;
6364
}
6465

65-
public function filterSuite(int $suiteId = null): self
66+
public function filterSuite(?int $suiteId = null): self
6667
{
6768
$this->filterSuiteId = $suiteId;
6869

@@ -77,7 +78,7 @@ public function build(Execution $execution): self
7778
$hasOnlyOneMainSuite = false;
7879
$mainSuiteId = null;
7980
foreach ($this->suites as $suite) {
80-
if ($suite->getParentId()) {
81+
if ($suite->getParent()) {
8182
continue;
8283
}
8384

@@ -157,7 +158,7 @@ private function formatSuite(Suite $suite): array
157158
'totalFailures' => $suite->getTotalFailures(),
158159
'hasSuites' => $suite->getHasSuites() ? 1 : 0,
159160
'hasTests' => $suite->getHasTests() ? 1 : 0,
160-
'parent_id' => $suite->getParentId(),
161+
'parent_id' => $suite->getParent()?->getId(),
161162
'insertion_date' => $suite->getInsertionDate()
162163
->setTimezone(new \DateTimeZone('-01:00'))
163164
->format('Y-m-d H:i:s'),
@@ -237,7 +238,7 @@ private function buildTree(?int $parentId, bool $isRoot): array
237238
&& $suite->getId() !== $this->filterSuiteId) {
238239
continue;
239240
}
240-
if ($suite->getParentId() !== $parentId) {
241+
if ($suite->getParent()?->getId() !== $parentId) {
241242
continue;
242243
}
243244

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

291292
/**
292-
* @param array<int, Suite> $suites
293+
* @param Collection<int, Suite> $suites
293294
*/
294-
private function countStatus(int $basis, array $suites, string $status): int
295+
private function countStatus(int $basis, Collection $suites, string $status): int
295296
{
296297
$num = $basis;
297298

@@ -316,7 +317,7 @@ private function countStatus(int $basis, array $suites, string $status): int
316317
private function filterTree(array $suites): array
317318
{
318319
foreach ($suites as $key => &$suite) {
319-
$suiteChildren = $suite->getSuites();
320+
$suiteChildren = $suite->getSuites()->toArray();
320321
$numSuiteTests = $suite->getTests()->count();
321322
if (!empty($suiteChildren)) {
322323
$suite->setSuites($this->filterTree($suiteChildren));

tests/Controller/ReportControllerTest.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,23 @@ public function testCorsReports(): void
3939
$this->assertEquals($response->headers->get('access-control-allow-origin'), '*');
4040
}
4141

42-
public function testReports(): void
42+
/**
43+
* @dataProvider dataProviderReportFilters
44+
*
45+
* @param array<string, string> $query
46+
*/
47+
public function testReportsFilters(array $query, int $count): void
4348
{
4449
$client = static::createClient();
45-
$client->request('GET', '/reports');
50+
$client->request('GET', '/reports' . ($query ? '?' . http_build_query($query) : ''));
4651
$response = $client->getResponse();
4752

4853
$this->assertTrue($response->isSuccessful());
4954
$this->assertTrue($response->headers->has('content-type'));
5055
$this->assertEquals('application/json', $response->headers->get('content-type'));
5156

5257
$content = json_decode($response->getContent(), true);
53-
$this->assertGreaterThan(0, count($content));
58+
$this->assertEquals($count, count($content));
5459
$datePrevious = null;
5560
foreach ($content as $item) {
5661
if ($datePrevious) {
@@ -61,16 +66,28 @@ public function testReports(): void
6166
$this->assertIsInt($item['id']);
6267
$this->assertArrayHasKey('date', $item);
6368
$this->assertArrayHasKey('version', $item);
69+
if (isset($query['filter_version'])) {
70+
$this->assertEquals($item['version'], $query['filter_version']);
71+
}
6472
$this->assertArrayHasKey('campaign', $item);
6573
$this->assertContains($item['campaign'], array_merge(
6674
ReportMochaImporter::FILTER_CAMPAIGNS,
6775
ReportPlaywrightImporter::FILTER_CAMPAIGNS
6876
));
77+
if (isset($query['filter_campaign[0]'])) {
78+
$this->assertEquals($item['campaign'], $query['filter_campaign[0]']);
79+
}
6980
$this->assertArrayHasKey('browser', $item);
7081
$this->assertContains($item['browser'], ReportMochaImporter::FILTER_PLATFORMS);
7182
$this->assertArrayHasKey('platform', $item);
7283
$this->assertContains($item['platform'], ReportMochaImporter::FILTER_PLATFORMS);
7384
$this->assertEquals($item['browser'], $item['platform']);
85+
if (isset($query['filter_platform'])) {
86+
$this->assertEquals($item['platform'], $query['filter_platform']);
87+
}
88+
if (isset($query['filter_browser'])) {
89+
$this->assertEquals($item['platform'], $query['filter_browser']);
90+
}
7491
$this->assertArrayHasKey('start_date', $item);
7592
$this->assertArrayHasKey('end_date', $item);
7693
$this->assertArrayHasKey('duration', $item);
@@ -91,6 +108,20 @@ public function testReports(): void
91108
}
92109
}
93110

111+
/**
112+
* @return array<array<array<string, string>|int>>
113+
*/
114+
public static function dataProviderReportFilters(): array
115+
{
116+
return [
117+
[[], 6],
118+
[['filter_campaign[0]' => 'functional'], 2],
119+
[['filter_platform' => 'chromium'], 3],
120+
[['filter_browser' => 'chromium'], 3],
121+
[['filter_version' => 'develop'], 6],
122+
];
123+
}
124+
94125
public function testReportNotFound(): void
95126
{
96127
$client = static::createClient();
@@ -368,7 +399,7 @@ private function partialCompareTest(array $expected, array $actual): void
368399
/**
369400
* @param array<string, string> $item
370401
*/
371-
private function partialTestSuite(int $executionId, int $id, array $item, int $idParent = null, bool $hasChildrenData = null): void
402+
private function partialTestSuite(int $executionId, int $id, array $item, ?int $idParent = null, ?bool $hasChildrenData = null): void
372403
{
373404
$this->assertIsInt($id);
374405

0 commit comments

Comments
 (0)