Skip to content

Commit 7ae3472

Browse files
authored
Introduce a full demo app test (#140)
2 parents 2fde970 + e54f471 commit 7ae3472

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

.github/tester.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Input\InputInterface;
4+
use Symfony\Component\Console\Output\OutputInterface;
5+
use Symfony\Component\Console\SingleCommandApplication;
6+
use Symfony\Component\Console\Style\SymfonyStyle;
7+
use Symfony\Component\Filesystem\Filesystem;
8+
use Symfony\Component\Process\Process;
9+
10+
require_once __DIR__.'/../vendor/autoload.php';
11+
12+
(new SingleCommandApplication())->setCode(function (InputInterface $input, OutputInterface $output) {
13+
$io = new SymfonyStyle($input, $output);
14+
$helper = $this->getHelper('process');
15+
16+
$io->section('Setting up the project...');
17+
18+
$projectDir = sys_get_temp_dir().'/eloquent';
19+
$refDir = $projectDir.'-ref';
20+
$filesystem = new Filesystem();
21+
if ($filesystem->exists($projectDir)) $filesystem->remove($projectDir);
22+
if ($filesystem->exists($refDir)) $filesystem->remove($refDir);
23+
24+
$helper->mustRun($output, new Process(['git', 'clone', 'https://github.com/wouterj-nl/symfony-eloquent.git', $refDir]));
25+
$filesystem->mkdir($projectDir);
26+
$helper->mustRun($output, new Process(['git', 'init'], $projectDir));
27+
28+
$commits = array_map(
29+
fn ($l) => explode(' ', $l, 2),
30+
array_reverse(
31+
preg_split(
32+
'/\R/',
33+
trim(
34+
(new Process(['git', 'log', '--oneline'], $refDir))->mustRun()->getOutput()
35+
)
36+
)
37+
)
38+
);
39+
40+
$io->writeln('');
41+
42+
$io->section('Running the test');
43+
44+
$i = 1;
45+
foreach ($commits as [$commit, $msg]) {
46+
[$op, $val] = explode(': ', $msg, 2);
47+
switch ($op) {
48+
case 'PATCH':
49+
$io->text($i++.'. Patching files ('.$commit.'): '.$val);
50+
$diff = (new Process(['git', 'show', '--pretty=format:%b', $commit], $refDir))->mustRun()->getOutput();
51+
$helper->mustRun($output, (new Process(['git', 'apply'], $projectDir))->setInput($diff));
52+
53+
break;
54+
case 'CMD':
55+
$io->text($i++.'. Running command: <comment>'.$val.'</>');
56+
$helper->mustRun($output, (Process::fromShellCommandline($val, $projectDir, ['SHELL_VERBOSITY' => '0'])));
57+
58+
break;
59+
default:
60+
throw new \LogicException('Unknown operation: '.$op);
61+
}
62+
}
63+
})->run();

.github/workflows/app.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: App test
2+
3+
on:
4+
push:
5+
branches: [2.x]
6+
schedule:
7+
- cron: '4 3 1 * *'
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
name: 'Demo application test'
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- name: Setup PHP
19+
uses: 'shivammathur/setup-php@v2'
20+
with:
21+
php-version: '8.2'
22+
extensions: xml, pdo_sqlite
23+
24+
- name: Install dependencies
25+
uses: 'ramsey/composer-install@v2'
26+
27+
- name: Run script
28+
run: php .github/tester.php -vvv

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"symfony/twig-bundle": "^5.4 || ^6.0",
3333
"symfony/twig-bridge": "^5.4 || ^6.0",
3434
"symfony/var-dumper": "^5.4 || ^6.0",
35+
"symfony/process": "^5.4 || ^6.0",
3536
"twig/twig": "^1.26 || ^2.0 || ^3.0",
3637
"vimeo/psalm": "^3.18.2 || ^4.0",
3738
"psalm/plugin-symfony": "^1.5.0 || ^2.0 || ^3.0"

0 commit comments

Comments
 (0)