diff --git a/src/Command/ImportMochaCommand.php b/src/Command/ImportMochaCommand.php index 6066754..7a0ed9a 100644 --- a/src/Command/ImportMochaCommand.php +++ b/src/Command/ImportMochaCommand.php @@ -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( 'Version found not correct (%s) from filename %s', @@ -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, diff --git a/src/Command/ImportPlaywrightCommand.php b/src/Command/ImportPlaywrightCommand.php index a8a2e11..1cc9747 100644 --- a/src/Command/ImportPlaywrightCommand.php +++ b/src/Command/ImportPlaywrightCommand.php @@ -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( 'Version found not correct (%s) from filename %s', @@ -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, diff --git a/src/Controller/ImportController.php b/src/Controller/ImportController.php index 2eb482c..0bb8b62 100644 --- a/src/Controller/ImportController.php +++ b/src/Controller/ImportController.php @@ -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; @@ -31,6 +32,8 @@ class ImportController extends AbstractController private ?string $platform; + private ?string $database; + private ?string $campaign; private ?\DateTime $startDate; @@ -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, @@ -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, @@ -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', @@ -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) { @@ -172,13 +180,20 @@ private function checkAuth(Request $request, array $allowedCampaigns, bool $forc $this->startDate = \DateTime::createFromFormat(\DateTime::RFC3339_EXTENDED, $this->jsonContent->stats->start ?? $this->jsonContent->stats->startTime); // Check if there is no similar entry - if (!$force && $this->executionRepository->findOneByNightly($this->version, $this->platform, $this->campaign, $this->startDate->format('Y-m-d'))) { + if (!$force && $this->executionRepository->findOneByNightly( + $this->version, + $this->platform, + $this->campaign, + $this->database, + $this->startDate->format('Y-m-d') + )) { return new JsonResponse([ 'message' => sprintf( - 'A similar entry was found (criteria: version %s, platform %s, campaign %s, date %s).', + 'A similar entry was found (criteria: version %s, platform %s, campaign %s, database %s, date %s).', $this->version, $this->platform, $this->campaign, + $this->database, $this->startDate->format('Y-m-d') ), ], Response::HTTP_FORBIDDEN); diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 2423a1d..dfa903f 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -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(), @@ -134,6 +135,7 @@ public function report(int $idReport, Request $request): JsonResponse 'campaign' => $execution->getCampaign(), 'browser' => $execution->getPlatform(), // retro-compatibility 'platform' => $execution->getPlatform(), + 'database' => $execution->getDatabase(), 'start_date' => $execution->getStartDate()->setTimezone(new \DateTimeZone('-01:00'))->format('Y-m-d H:i:s'), 'end_date' => $execution->getEndDate()->setTimezone(new \DateTimeZone('-01:00'))->format('Y-m-d H:i:s'), 'duration' => $execution->getDuration(), diff --git a/src/Entity/Execution.php b/src/Entity/Execution.php index c745555..f87230e 100644 --- a/src/Entity/Execution.php +++ b/src/Entity/Execution.php @@ -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; @@ -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; diff --git a/src/Repository/ExecutionRepository.php b/src/Repository/ExecutionRepository.php index 3dd5abf..a05c620 100644 --- a/src/Repository/ExecutionRepository.php +++ b/src/Repository/ExecutionRepository.php @@ -25,16 +25,19 @@ public function findOneByNightly( string $version, string $platform, string $campaign, + string $database, string $date ): ?Execution { $qb = $this->createQueryBuilder('e') ->andWhere('e.version = :version') ->andWhere('e.platform = :platform') ->andWhere('e.campaign = :campaign') + ->andWhere('e.database = :database') ->andWhere('DATE(e.start_date) = :date') ->setParameter('version', $version) ->setParameter('platform', $platform) ->setParameter('campaign', $campaign) + ->setParameter('database', $database) ->setParameter('date', $date) ->orderBy('e.start_date', 'DESC'); @@ -47,16 +50,19 @@ public function findOneByNightlyBefore( string $version, string $platform, string $campaign, + string $database, \DateTimeInterface $dateUntil ): ?Execution { $qb = $this->createQueryBuilder('e') ->andWhere('e.version = :version') ->andWhere('e.platform = :platform') ->andWhere('e.campaign = :campaign') + ->andWhere('e.database = :database') ->andWhere('e.start_date < :dateUntil') ->setParameter('version', $version) ->setParameter('platform', $platform) ->setParameter('campaign', $campaign) + ->setParameter('database', $database) ->setParameter('dateUntil', $dateUntil) ->orderBy('e.start_date', 'DESC'); diff --git a/src/Service/AbstractReportImporter.php b/src/Service/AbstractReportImporter.php index 8ea9b9d..c4fb95d 100644 --- a/src/Service/AbstractReportImporter.php +++ b/src/Service/AbstractReportImporter.php @@ -11,6 +11,7 @@ abstract class AbstractReportImporter abstract public function import( string $filename, string $platform, + string $database, string $campaign, string $version, \DateTime $startDate, @@ -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; @@ -39,6 +44,7 @@ protected function compareReportData(Execution $execution): Execution $execution->getVersion(), $execution->getPlatform(), $execution->getCampaign(), + $execution->getDatabase(), $execution->getStartDate() ); if (!$executionPrevious) { diff --git a/src/Service/ReportMochaImporter.php b/src/Service/ReportMochaImporter.php index 1ba9be4..82fa010 100644 --- a/src/Service/ReportMochaImporter.php +++ b/src/Service/ReportMochaImporter.php @@ -27,6 +27,7 @@ public function __construct( public function import( string $filename, string $platform, + string $database, string $campaign, string $version, \DateTime $startDate, @@ -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)) diff --git a/src/Service/ReportPlaywrightImporter.php b/src/Service/ReportPlaywrightImporter.php index 9aab007..1dd8590 100644 --- a/src/Service/ReportPlaywrightImporter.php +++ b/src/Service/ReportPlaywrightImporter.php @@ -30,6 +30,7 @@ public function __construct( public function import( string $filename, string $platform, + string $database, string $campaign, string $version, \DateTime $startDate, @@ -43,6 +44,7 @@ public function import( ->setRef(date('YmdHis')) ->setFilename($filename) ->setPlatform($platform) + ->setDatabase($database) ->setCampaign($campaign) ->setStartDate($startDate) ->setEndDate($endDate) diff --git a/tests/Command/ImportMochaCommandTest.php b/tests/Command/ImportMochaCommandTest.php index 416e848..04a7967 100644 --- a/tests/Command/ImportMochaCommandTest.php +++ b/tests/Command/ImportMochaCommandTest.php @@ -18,6 +18,7 @@ public function testImportAutoupgrade(): void $commandTester->execute([ '--platform' => 'cli', '--campaign' => 'autoupgrade', + '--database' => 'mysql', 'filename' => 'autoupgrade_2024-01-25-develop.json', ]); @@ -37,6 +38,7 @@ public function testImportCore(): void $commandTester->execute([ '--platform' => 'chromium', '--campaign' => 'functional', + '--database' => 'mysql', 'filename' => '2024-01-25-develop.json', ]); diff --git a/tests/Command/ImportPlaywrightCommandTest.php b/tests/Command/ImportPlaywrightCommandTest.php index 0aa03dc..bda560c 100644 --- a/tests/Command/ImportPlaywrightCommandTest.php +++ b/tests/Command/ImportPlaywrightCommandTest.php @@ -18,6 +18,7 @@ public function testImportBlockwislist(): void $commandTester->execute([ '--platform' => 'chromium', '--campaign' => 'blockwishlist', + '--database' => 'mysql', 'filename' => 'blockwishlist_2024-01-25-develop.json', ]); diff --git a/tests/Controller/ImportControllerTest.php b/tests/Controller/ImportControllerTest.php index 49e9e66..e365609 100644 --- a/tests/Controller/ImportControllerTest.php +++ b/tests/Controller/ImportControllerTest.php @@ -170,7 +170,7 @@ public function testReportMochaAlreadyExisting(): void $content = $response->getContent(); $content = json_decode($content, true); $this->assertArrayHasKey('message', $content); - $this->assertEquals('A similar entry was found (criteria: version develop, platform chromium, campaign functional, date ' . self::DATE_RESOURCE . ').', $content['message']); + $this->assertEquals('A similar entry was found (criteria: version develop, platform chromium, campaign functional, database mysql, date ' . self::DATE_RESOURCE . ').', $content['message']); } public function testReportPlaywrightWithNoParameters(): void @@ -332,6 +332,6 @@ public function testReportPlaywrightAlreadyExisting(): void $content = $response->getContent(); $content = json_decode($content, true); $this->assertArrayHasKey('message', $content); - $this->assertEquals('A similar entry was found (criteria: version develop, platform chromium, campaign blockwishlist, date ' . self::DATE_RESOURCE . ').', $content['message']); + $this->assertEquals('A similar entry was found (criteria: version develop, platform chromium, campaign blockwishlist, database mysql, date ' . self::DATE_RESOURCE . ').', $content['message']); } } diff --git a/tests/Controller/ReportControllerTest.php b/tests/Controller/ReportControllerTest.php index 70f1537..69b9f9f 100644 --- a/tests/Controller/ReportControllerTest.php +++ b/tests/Controller/ReportControllerTest.php @@ -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']); } @@ -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);