Skip to content

Instantly share code, notes, and snippets.

@alexander-schranz
Last active July 10, 2023 20:52
Show Gist options
  • Save alexander-schranz/6bde6b783482049c8d47fbd0c10b1e63 to your computer and use it in GitHub Desktop.
Save alexander-schranz/6bde6b783482049c8d47fbd0c10b1e63 to your computer and use it in GitHub Desktop.
ParaTest
<?php
declare(strict_types=1);
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\Process\ExecutableFinder;
require \dirname(__DIR__) . '/vendor/autoload.php';
(new Dotenv())->bootEnv(\dirname(__DIR__) . '/.env');
if (\class_exists(\Locale::class)) {
\Locale::setDefault('en');
}
\ini_set('date.timezone', 'UTC');
$testToken = \getenv('TEST_TOKEN');
if (false !== $testToken) {
$dir = \dirname(__DIR__) . '/var/cache/admin/test/TEST_TOKEN/' . \date('Ymd');
$fileName = $dir . '/' . $testToken . '.lock';
// do bootstraping only once or again if `bin/console cache:clear --env test` was called
if (!\file_exists($fileName)) {
if (!\is_dir($dir)) {
\mkdir($dir, 0777, true);
}
\touch($fileName);
// run composer bootstrap-test-env with the callers PHP Binary
$binary = 'composer';
if (\getenv('COMPOSER_BINARY')) {
$binary = \getenv('COMPOSER_BINARY');
} else {
$executableFinder = new ExecutableFinder();
$binary = $executableFinder->find('composer') ?: 'composer';
}
if ('composer' !== $binary) {
$binary = \PHP_BINARY . ' ' . $binary;
}
// forward TEST_TOKEN to the infrastructure / database
\exec('TEST_TOKEN=' . $testToken . ' ' . $binary . ' bootstrap-test-infrastructure');
}
}
#!/usr/bin/env php
<?php
if (!\ini_get('date.timezone')) {
\ini_set('date.timezone', 'UTC');
}
$command = implode(' ', $argv);
$allowParatest = true;
if (\str_contains($command, '--filter')) {
// errors else with: Option --filter is not implemented for none functional mode
$allowParatest = false;
} elseif (\str_contains($command, 'tests/Unit')) {
// only running unit tests is faster in a single process
$allowParatest = false;
} elseif (\getenv('PARATEST_DISABLED')) {
$allowParatest = false;
}
if ($allowParatest && \is_file(\dirname(__DIR__) . '/vendor/brianium/paratest/bin/paratest')) {
require_once 'vendor/autoload.php';
\ParaTest\Console\Commands\ParaTestCommand::applicationFactory(\getcwd())->run();
} elseif (\is_file(\dirname(__DIR__) . '/vendor/phpunit/phpunit/phpunit')) {
\define('PHPUNIT_COMPOSER_INSTALL', \dirname(__DIR__) . '/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
PHPUnit\TextUI\Command::main();
} else {
if (!\is_file(\dirname(__DIR__) . '/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php')) {
echo "Unable to find the `simple-phpunit.php` script in `vendor/symfony/phpunit-bridge/bin/`.\n";
exit(1);
}
require \dirname(__DIR__) . '/vendor/symfony/phpunit-bridge/bin/simple-phpunit.php';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment