Skip to content

Commit

Permalink
Introduce a full demo app test (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Jul 30, 2023
2 parents 2fde970 + e54f471 commit 7ae3472
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/tester.php
@@ -0,0 +1,63 @@
<?php

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\SingleCommandApplication;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;

require_once __DIR__.'/../vendor/autoload.php';

(new SingleCommandApplication())->setCode(function (InputInterface $input, OutputInterface $output) {
$io = new SymfonyStyle($input, $output);
$helper = $this->getHelper('process');

$io->section('Setting up the project...');

$projectDir = sys_get_temp_dir().'/eloquent';
$refDir = $projectDir.'-ref';
$filesystem = new Filesystem();
if ($filesystem->exists($projectDir)) $filesystem->remove($projectDir);
if ($filesystem->exists($refDir)) $filesystem->remove($refDir);

$helper->mustRun($output, new Process(['git', 'clone', 'https://github.com/wouterj-nl/symfony-eloquent.git', $refDir]));
$filesystem->mkdir($projectDir);
$helper->mustRun($output, new Process(['git', 'init'], $projectDir));

$commits = array_map(
fn ($l) => explode(' ', $l, 2),
array_reverse(
preg_split(
'/\R/',
trim(
(new Process(['git', 'log', '--oneline'], $refDir))->mustRun()->getOutput()
)
)
)
);

$io->writeln('');

$io->section('Running the test');

$i = 1;
foreach ($commits as [$commit, $msg]) {
[$op, $val] = explode(': ', $msg, 2);
switch ($op) {
case 'PATCH':
$io->text($i++.'. Patching files ('.$commit.'): '.$val);
$diff = (new Process(['git', 'show', '--pretty=format:%b', $commit], $refDir))->mustRun()->getOutput();
$helper->mustRun($output, (new Process(['git', 'apply'], $projectDir))->setInput($diff));

break;
case 'CMD':
$io->text($i++.'. Running command: <comment>'.$val.'</>');
$helper->mustRun($output, (Process::fromShellCommandline($val, $projectDir, ['SHELL_VERBOSITY' => '0'])));

break;
default:
throw new \LogicException('Unknown operation: '.$op);
}
}
})->run();
28 changes: 28 additions & 0 deletions .github/workflows/app.yml
@@ -0,0 +1,28 @@
name: App test

on:
push:
branches: [2.x]
schedule:
- cron: '4 3 1 * *'

jobs:
build:
runs-on: ubuntu-latest

name: 'Demo application test'

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: 'shivammathur/setup-php@v2'
with:
php-version: '8.2'
extensions: xml, pdo_sqlite

- name: Install dependencies
uses: 'ramsey/composer-install@v2'

- name: Run script
run: php .github/tester.php -vvv
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -32,6 +32,7 @@
"symfony/twig-bundle": "^5.4 || ^6.0",
"symfony/twig-bridge": "^5.4 || ^6.0",
"symfony/var-dumper": "^5.4 || ^6.0",
"symfony/process": "^5.4 || ^6.0",
"twig/twig": "^1.26 || ^2.0 || ^3.0",
"vimeo/psalm": "^3.18.2 || ^4.0",
"psalm/plugin-symfony": "^1.5.0 || ^2.0 || ^3.0"
Expand Down

0 comments on commit 7ae3472

Please sign in to comment.