|
| 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(); |
0 commit comments