-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import les données Litteralis de Lons-le-Saunier
- Loading branch information
1 parent
c0534af
commit 58c096b
Showing
10 changed files
with
257 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: Litteralis Lons-le-Saunier Import | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '15 16 * * 1' # Voir https://crontab.guru/ : tous les lundis à 16h08 GMT | ||
|
||
jobs: | ||
import: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- name: Setup PHP with PECL extension | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: '8.2' | ||
|
||
- name: Get Composer Cache Directory | ||
id: composer-cache | ||
run: | | ||
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
- uses: actions/cache@v3 | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-composer- | ||
- name: Install Scalingo CLI | ||
run: curl -O https://cli-dl.scalingo.com/install && bash install | ||
|
||
- name: Install SSH key | ||
# Credit: https://stackoverflow.com/a/69234389 | ||
run: | | ||
mkdir -p ~/.ssh | ||
install -m 600 -D /dev/null ~/.ssh/id_rsa | ||
echo "${{ secrets.GH_SCALINGO_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | ||
- name: Add Scalingo as a known host | ||
run: | | ||
ssh-keyscan -H ssh.osc-fr1.scalingo.com >> ~/.ssh/known_hosts | ||
- name: Init environment variables | ||
run: | | ||
echo "DATABASE_URL=${{ secrets.APP_LONS_LE_SAUNIER_IMPORT_DATABASE_URL }}" >> .env.local | ||
echo "BDTOPO_DATABASE_URL=${{ secrets.BDTOPO_DATABASE_URL }}" >> .env.local | ||
echo "APP_LONS_LE_SAUNIER_LITTERALIS_CREDENTIALS=${{ secrets.APP_LONS_LE_SAUNIER_LITTERALIS_CREDENTIALS }}" >> .env.local | ||
echo "APP_LONS_LE_SAUNIER_ORG_ID=${{ vars.APP_LONS_LE_SAUNIER_ORG_ID }}" >> .env.local | ||
- name: Run import | ||
run: make ci_litteralis_lons_le_saunier_import BIN_PHP="php" BIN_CONSOLE="php bin/console" BIN_COMPOSER="composer" | ||
|
||
- name: Get log file path | ||
id: logfile | ||
if: ${{ !cancelled() }} | ||
run: | ||
echo "path=$(find log/litteralis -type f -name '*.log' | head -n 1)" >> $GITHUB_OUTPUT | ||
|
||
- uses: actions/upload-artifact@v3 | ||
if: ${{ !cancelled() }} | ||
with: | ||
name: litteralis_logfile | ||
path: ${{ steps.logfile.outputs.path }} | ||
retention-days: 21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Infrastructure/Litteralis/LonsLeSaunier/LonsLeSaunierExecutor.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Infrastructure\Litteralis\LonsLeSaunier; | ||
|
||
use App\Infrastructure\IntegrationReport\Reporter; | ||
use App\Infrastructure\Litteralis\LitteralisExecutor; | ||
|
||
final class LonsLeSaunierExecutor | ||
{ | ||
private const INTEGRATION_NAME = 'Litteralis Lons-le-Saunier'; | ||
|
||
public function __construct( | ||
private LitteralisExecutor $executor, | ||
private string $lonsLeSaunierOrgId, | ||
string $lonsLeSaunierCredentials, | ||
) { | ||
$this->executor->configure($lonsLeSaunierCredentials); | ||
} | ||
|
||
public function execute(\DateTimeInterface $laterThan, Reporter $reporter): string | ||
{ | ||
return $this->executor->execute(self::INTEGRATION_NAME, $this->lonsLeSaunierOrgId, $laterThan, $reporter); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/Infrastructure/Symfony/Command/LonsLeSaunierImportCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Infrastructure\Symfony\Command; | ||
|
||
use App\Application\DateUtilsInterface; | ||
use App\Infrastructure\IntegrationReport\Reporter; | ||
use App\Infrastructure\Litteralis\LonsLeSaunier\LonsLeSaunierExecutor; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[AsCommand( | ||
name: 'app:lons_le_saunier:import', | ||
description: 'Import Litteralis data of Lons-le-Saunier', | ||
hidden: false, | ||
)] | ||
class LonsLeSaunierImportCommand extends Command | ||
{ | ||
public function __construct( | ||
private LoggerInterface $logger, | ||
private LonsLeSaunierExecutor $executor, | ||
private DateUtilsInterface $dateUtils, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$reporter = new Reporter($this->logger); | ||
$now = $this->dateUtils->getNow(); | ||
|
||
try { | ||
$report = $this->executor->execute($now, $reporter); | ||
|
||
$output->write($report); | ||
} catch (\RuntimeException $exc) { | ||
$output->writeln($exc->getMessage()); | ||
|
||
return Command::FAILURE; | ||
} | ||
|
||
return Command::SUCCESS; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/Integration/Infrastructure/Symfony/Command/LonsLeSaunierImportCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Integration\Infrastructure\Symfony\Command; | ||
|
||
use App\Infrastructure\Symfony\Command\LonsLeSaunierImportCommand; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
final class LonsLeSaunierImportCommandTest extends KernelTestCase | ||
{ | ||
public function testExecute(): void | ||
{ | ||
self::bootKernel(); | ||
$container = static::getContainer(); | ||
|
||
$command = $container->get(LonsLeSaunierImportCommand::class); | ||
$commandTester = new CommandTester($command); | ||
|
||
$commandTester->execute([]); | ||
$commandTester->assertCommandIsSuccessful($commandTester->getDisplay()); | ||
|
||
$output = $commandTester->getDisplay(); | ||
// These results depend on LitteralisMockHttpClient | ||
$this->assertStringContainsString("Nombre total d'emprises dans Litteralis pour cette organisation : 2", $output); | ||
$this->assertStringContainsString("Emprises d'intérêt récupérées dans Litteralis : 2", $output); | ||
$this->assertStringContainsString("Emprises effectivement candidates à l'import : 2 (dans 1 arrêtés)", $output); | ||
$this->assertStringContainsString('Emprises importées avec succès : 2 (dans 1 arrêtés)', $output); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
tests/Unit/Infrastructure/Symfony/Command/LonsLeSaunierImportCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Tests\Unit\Infrastructure\Symfony\Command; | ||
|
||
use App\Application\DateUtilsInterface; | ||
use App\Infrastructure\Litteralis\LonsLeSaunier\LonsLeSaunierExecutor; | ||
use App\Infrastructure\Symfony\Command\LonsLeSaunierImportCommand; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class LonsLeSaunierImportCommandTest extends TestCase | ||
{ | ||
private $logger; | ||
private $executor; | ||
private $dateUtils; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->logger = $this->createMock(LoggerInterface::class); | ||
$this->executor = $this->createMock(LonsLeSaunierExecutor::class); | ||
$this->dateUtils = $this->createMock(DateUtilsInterface::class); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
$this->executor | ||
->expects(self::once()) | ||
->method('execute'); | ||
|
||
$command = new LonsLeSaunierImportCommand($this->logger, $this->executor, $this->dateUtils); | ||
$this->assertSame('app:lons_le_saunier:import', $command->getName()); | ||
|
||
$commandTester = new CommandTester($command); | ||
$commandTester->execute([]); | ||
$commandTester->assertCommandIsSuccessful(); | ||
} | ||
|
||
public function testExecuteError() | ||
{ | ||
$this->executor | ||
->expects(self::once()) | ||
->method('execute') | ||
->willThrowException(new \RuntimeException('Failed')); | ||
|
||
$command = new LonsLeSaunierImportCommand($this->logger, $this->executor, $this->dateUtils); | ||
$commandTester = new CommandTester($command); | ||
$commandTester->execute([]); | ||
|
||
$this->assertSame(Command::FAILURE, $commandTester->getStatusCode()); | ||
} | ||
} |