Skip to content

Commit

Permalink
Added CI PHPUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Jan 5, 2024
1 parent 1e2a5dd commit 9f4b15c
Show file tree
Hide file tree
Showing 7 changed files with 425 additions and 315 deletions.
8 changes: 1 addition & 7 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@ SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
PANTHER_ERROR_SCREENSHOT_DIR=./var/error-screenshots

DATABASE_URL="mysql://root:root@127.0.0.1:3306/qanightlyresults?serverVersion=10.3.38-MariaDB&charset=utf8mb4"
DATABASE_URL="mysql://root:password@127.0.0.1:3306/qanightlyresults?serverVersion=8.0.23&charset=utf8mb4"


QANB_DB_HOST=localhost
QANB_DB_NAME=qanightlyresults
QANB_DB_USERNAME=root
QANB_DB_PASSWORD=root
QANB_GCPURL=https://storage.googleapis.com/prestashop-core-nightly/
QANB_VERSION=3
QANB_TOKEN='AZERTY'
101 changes: 52 additions & 49 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,52 +58,55 @@ jobs:

- name: Run phpstan
run: ./vendor/bin/phpstan analyse
# phpunit:
# permissions:
# contents: read # for actions/checkout to fetch code
# name: PHPUnit
# runs-on: ubuntu-latest
# strategy:
# matrix:
# php: [ '8.1', '8.2' ]
# fail-fast: false
# steps:
# - name: Setup PHP
# uses: shivammathur/setup-php@v2
# with:
# php-version: ${{ matrix.php }}
# extensions: mbstring, intl, gd, xml, dom, json, fileinfo, curl, zip, iconv, simplexml
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# - uses: actions/checkout@v3

# - name: PrestaShop Configuration
# run: cp .github/workflows/phpunit/parameters.yml app/config/parameters.yml

# - name: Get Composer Cache Directory
# id: composer-cache
# run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

# - name: Cache Composer Directory
# uses: actions/cache@v3
# with:
# path: ${{ steps.composer-cache.outputs.dir }}
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
# restore-keys: ${{ runner.os }}-composer-

# - name: Composer Install
# run: composer install --ansi --prefer-dist --no-interaction --no-progress

# - name: Update phpunit version
# if: ${{ startsWith(matrix.php, '8.') }}
# run: composer update -w --ignore-platform-reqs --no-interaction phpunit/phpunit

# - name: Run phpunit
# run: ./vendor/phpunit/phpunit/phpunit -c tests/Unit/phpunit.xml
# env:
# SYMFONY_DEPRECATIONS_HELPER: disabled

# - name: Test git versionned files unchanged
# if: ${{ !startsWith(matrix.php, '8.') }} # composer.lock changes when updating phpunit version
# run: git diff --exit-code
phpunit:
permissions:
contents: read # for actions/checkout to fetch code
name: PHPUnit
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup MySQL
uses: mirromutth/[email protected]
with:
mysql version: '8.0'
mysql database: 'qanightlyresults'
mysql root password: 'password'

- uses: actions/checkout@v3

- name: Config
run: cp .env.dist .env

- name: Composer Install
run: composer install --ansi --prefer-dist --no-interaction --no-progress

- name: Change MySQL authentication method
run: sleep 15 && mysql -h127.0.0.1 -uroot -ppassword -e "ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password'; FLUSH PRIVILEGES;"

- name: Setup database
run: php bin/console doctrine:schema:update --dump-sql --force --env=test

- name: Inject data for AutoUpgrade
run: |
DATE=$(date -d "1 day ago" +"%Y-%m-%d")
php bin/console nightly:import autoupgrade_$DATE-develop\
-p cli \
-c autoupgrade \
--env test
- name: Inject data for Core
run: |
DATE=$(date -d "1 day ago" +"%Y-%m-%d")
php bin/console nightly:import $DATE-develop\
-p chromium \
-c functional \
--env test
- name: Run phpunit
run: ./vendor/bin/phpunit
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions src/Command/ImportCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace App\Command;

use App\Service\ReportImporter;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(name: 'nightly:import')]
class ImportCommand extends Command
{
private ReportImporter $reportImporter;

private string $nightlyGCPUrl;

public function __construct(ReportImporter $reportImporter, string $nightlyGCPUrl)
{
parent::__construct();

$this->reportImporter = $reportImporter;
$this->nightlyGCPUrl = $nightlyGCPUrl;
}

protected function configure(): void
{
$this
->addArgument('filename', InputArgument::REQUIRED)
->addOption('platform', 'p', InputOption::VALUE_REQUIRED, '', ReportImporter::FILTER_PLATFORMS[0], ReportImporter::FILTER_PLATFORMS)
->addOption('campaign', 'c', InputOption::VALUE_REQUIRED, '', ReportImporter::FILTER_CAMPAIGNS[0], ReportImporter::FILTER_CAMPAIGNS)
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}-(.*)?\.json/', $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>',
$matchesVersion[1],
$output->getArgument('filename')

Check failure on line 44 in src/Command/ImportCommand.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Call to an undefined method Symfony\Component\Console\Output\OutputInterface::getArgument().
));

return Command::FAILURE;
}

$fileContent = @file_get_contents($this->nightlyGCPUrl . 'reports/' . $input->getArgument('filename'));
if (!$fileContent) {
$output->writeln('<error>Unable to retrieve content from GCP URL</error>');

return Command::FAILURE;
}

$jsonContent = json_decode($fileContent);
if (!$jsonContent) {
$output->writeln('<error>Unable to decode JSON data</error>');

return Command::FAILURE;
}

$dateformat = $input->getOption('campaign') === 'autoupgrade'
? ReportImporter::FORMAT_DATE_MOCHA5
: ReportImporter::FORMAT_DATE_MOCHA6;
$startDate = \DateTime::createFromFormat(
$dateformat,
$jsonContent->stats->start
);

$this->reportImporter->import(
$input->getArgument('filename'),
$input->getOption('platform'),
$input->getOption('campaign'),
$matchesVersion[1],
$startDate,
$jsonContent,
$dateformat
);

return Command::SUCCESS;
}
}
Loading

0 comments on commit 9f4b15c

Please sign in to comment.