Skip to content

Commit

Permalink
API Nightly : Support for database
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Jun 4, 2024
1 parent a773d9c commit bc8f2f4
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Command/ImportMochaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ protected function configure(): void
->addArgument('filename', InputArgument::REQUIRED)
->addOption('platform', 'p', InputOption::VALUE_REQUIRED, '', ReportMochaImporter::FILTER_PLATFORMS[0], ReportMochaImporter::FILTER_PLATFORMS)
->addOption('campaign', 'c', InputOption::VALUE_REQUIRED, '', ReportMochaImporter::FILTER_CAMPAIGNS[0], ReportMochaImporter::FILTER_CAMPAIGNS)
->addOption('database', 'd', InputOption::VALUE_REQUIRED, '', ReportMochaImporter::FILTER_DATABASES[0], ReportMochaImporter::FILTER_DATABASES)
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}-(.*)?\.json/', $input->getArgument('filename'), $matchesVersion);
preg_match(ReportMochaImporter::REGEX_FILE, $input->getArgument('filename'), $matchesVersion);
if (!isset($matchesVersion[1]) || strlen($matchesVersion[1]) < 1) {
$output->writeln(sprintf(
'<error>Version found not correct (%s) from filename %s</error>',
Expand Down Expand Up @@ -69,6 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->reportImporter->import(
$input->getArgument('filename'),
$input->getOption('platform'),
$input->getOption('database'),
$input->getOption('campaign'),
$matchesVersion[1],
$startDate,
Expand Down
4 changes: 3 additions & 1 deletion src/Command/ImportPlaywrightCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ protected function configure(): void
->addArgument('filename', InputArgument::REQUIRED)
->addOption('platform', 'p', InputOption::VALUE_REQUIRED, '', ReportPlaywrightImporter::FILTER_PLATFORMS[0], ReportPlaywrightImporter::FILTER_PLATFORMS)
->addOption('campaign', 'c', InputOption::VALUE_REQUIRED, '', ReportPlaywrightImporter::FILTER_CAMPAIGNS[0], ReportPlaywrightImporter::FILTER_CAMPAIGNS)
->addOption('database', 'd', InputOption::VALUE_REQUIRED, '', ReportPlaywrightImporter::FILTER_DATABASES[0], ReportPlaywrightImporter::FILTER_DATABASES)
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}-(.*)?\.json/', $input->getArgument('filename'), $matchesVersion);
preg_match(ReportPlaywrightImporter::REGEX_FILE, $input->getArgument('filename'), $matchesVersion);
if (!isset($matchesVersion[1]) || strlen($matchesVersion[1]) < 1) {
$output->writeln(sprintf(
'<error>Version found not correct (%s) from filename %s</error>',
Expand Down Expand Up @@ -69,6 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->reportImporter->import(
$input->getArgument('filename'),
$input->getOption('platform'),
$input->getOption('database'),
$input->getOption('campaign'),
$matchesVersion[1],
$startDate,
Expand Down
10 changes: 9 additions & 1 deletion src/Controller/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Controller;

use App\Repository\ExecutionRepository;
use App\Service\AbstractReportImporter;
use App\Service\ReportMochaImporter;
use App\Service\ReportPlaywrightImporter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand Down Expand Up @@ -31,6 +32,8 @@ class ImportController extends AbstractController

private ?string $platform;

private ?string $database;

private ?string $campaign;

private ?\DateTime $startDate;
Expand Down Expand Up @@ -60,6 +63,7 @@ public function importReportMocha(Request $request): JsonResponse
$execution = $this->reportMochaImporter->import(
$this->filename,
$this->platform,
$this->database,
$this->campaign,
$this->version,
$this->startDate,
Expand All @@ -83,6 +87,7 @@ public function importReportPlaywright(Request $request): JsonResponse
$execution = $this->reportPlaywrightImporter->import(
$this->filename,
$this->platform,
$this->database,
$this->campaign,
$this->version,
$this->startDate,
Expand Down Expand Up @@ -114,7 +119,7 @@ private function checkAuth(Request $request, array $allowedCampaigns, bool $forc
], Response::HTTP_UNAUTHORIZED);
}

preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}-(.*)?\.json/', $this->filename, $matchesVersion);
preg_match(AbstractReportImporter::REGEX_FILE, $this->filename, $matchesVersion);
if (!isset($matchesVersion[1])) {
return new JsonResponse([
'message' => 'Could not retrieve version from filename',
Expand Down Expand Up @@ -154,6 +159,9 @@ private function checkAuth(Request $request, array $allowedCampaigns, bool $forc
);
$this->platform = in_array($this->platform, ReportMochaImporter::FILTER_PLATFORMS) ? $this->platform : ReportMochaImporter::FILTER_PLATFORMS[0];

$this->database = $request->query->has('database') ? $request->query->get('database') : null;
$this->database = in_array($this->database, ReportMochaImporter::FILTER_DATABASES) ? $this->database : ReportMochaImporter::FILTER_DATABASES[0];

$this->campaign = $request->query->has('campaign') ? $request->query->get('campaign') : null;
if (!in_array($this->campaign, $allowedCampaigns)) {
if ($forceCampaign) {
Expand Down
1 change: 1 addition & 0 deletions src/Controller/ReportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function reports(Request $request): JsonResponse
'campaign' => $execution->getCampaign(),
'browser' => $execution->getPlatform(), // retro-compatibility
'platform' => $execution->getPlatform(),
'database' => $execution->getDatabase(),
'start_date' => $execution->getStartDate()->format('Y-m-d H:i:s'),
'end_date' => $execution->getEndDate()->format('Y-m-d H:i:s'),
'duration' => $execution->getDuration(),
Expand Down
15 changes: 15 additions & 0 deletions src/Entity/Execution.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class Execution
#[ORM\Column(length: 50, nullable: false)]
private string $platform = 'chromium';

#[ORM\Column(name: '`database`', length: 50, nullable: false)]
private string $database = 'mysql';

#[ORM\Column(nullable: true)]
private ?int $suites = null;

Expand Down Expand Up @@ -82,11 +85,23 @@ public function __construct()
$this->suitesCollection = new ArrayCollection();
}

public function getDatabase(): ?string
{
return $this->database;
}

public function getId(): ?int
{
return $this->id;
}

public function setDatabase(string $database): static
{
$this->database = $database;

return $this;
}

public function setId(int $id): static
{
$this->id = $id;
Expand Down
5 changes: 5 additions & 0 deletions src/Service/AbstractReportImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ abstract class AbstractReportImporter
abstract public function import(
string $filename,
string $platform,
string $database,
string $campaign,
string $version,
\DateTime $startDate,
Expand All @@ -19,6 +20,10 @@ abstract public function import(

public const FILTER_PLATFORMS = ['chromium', 'firefox', 'webkit', 'cli'];

public const FILTER_DATABASES = ['mysql', 'mariadb'];

public const REGEX_FILE = '/[0-9]{4}-[0-9]{2}-[0-9]{2}-([^-]*)[-]?(.*)]?\.json/';

protected ExecutionRepository $executionRepository;

protected TestRepository $testRepository;
Expand Down
2 changes: 2 additions & 0 deletions src/Service/ReportMochaImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __construct(
public function import(
string $filename,
string $platform,
string $database,
string $campaign,
string $version,
\DateTime $startDate,
Expand All @@ -37,6 +38,7 @@ public function import(
->setRef(date('YmdHis'))
->setFilename($filename)
->setPlatform($platform)
->setDatabase($database)
->setCampaign($campaign)
->setStartDate($startDate)
->setEndDate(\DateTime::createFromFormat(\DateTime::RFC3339_EXTENDED, $jsonContent->stats->end))
Expand Down
2 changes: 2 additions & 0 deletions src/Service/ReportPlaywrightImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct(
public function import(
string $filename,
string $platform,
string $database,
string $campaign,
string $version,
\DateTime $startDate,
Expand All @@ -43,6 +44,7 @@ public function import(
->setRef(date('YmdHis'))
->setFilename($filename)
->setPlatform($platform)
->setDatabase($database)
->setCampaign($campaign)
->setStartDate($startDate)
->setEndDate($endDate)
Expand Down
2 changes: 2 additions & 0 deletions tests/Command/ImportMochaCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function testImportAutoupgrade(): void
$commandTester->execute([
'--platform' => 'cli',
'--campaign' => 'autoupgrade',
'--database' => 'mysql',
'filename' => 'autoupgrade_2024-01-25-develop.json',
]);

Expand All @@ -37,6 +38,7 @@ public function testImportCore(): void
$commandTester->execute([
'--platform' => 'chromium',
'--campaign' => 'functional',
'--database' => 'mysql',
'filename' => '2024-01-25-develop.json',
]);

Expand Down
1 change: 1 addition & 0 deletions tests/Command/ImportPlaywrightCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function testImportBlockwislist(): void
$commandTester->execute([
'--platform' => 'chromium',
'--campaign' => 'blockwishlist',
'--database' => 'mysql',
'filename' => 'blockwishlist_2024-01-25-develop.json',
]);

Expand Down
4 changes: 4 additions & 0 deletions tests/Controller/ReportControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public function testReportsFilters(array $query, int $count): void
$this->assertArrayHasKey('platform', $item);
$this->assertContains($item['platform'], ReportMochaImporter::FILTER_PLATFORMS);
$this->assertEquals($item['browser'], $item['platform']);
$this->assertArrayHasKey('database', $item);
$this->assertContains($item['database'], ReportMochaImporter::FILTER_DATABASES);
if (isset($query['filter_platform'])) {
$this->assertEquals($item['platform'], $query['filter_platform']);
}
Expand Down Expand Up @@ -177,6 +179,8 @@ public function testReportID(int $reportId, array $campaigns): void
$this->assertArrayHasKey('platform', $content);
$this->assertContains($content['platform'], ReportMochaImporter::FILTER_PLATFORMS);
$this->assertEquals($content['browser'], $content['platform']);
$this->assertArrayHasKey('database', $content);
$this->assertContains($content['database'], ReportMochaImporter::FILTER_DATABASES);
$this->assertArrayHasKey('start_date', $content);
$this->assertArrayHasKey('end_date', $content);
$this->assertArrayHasKey('duration', $content);
Expand Down

0 comments on commit bc8f2f4

Please sign in to comment.