Created
June 8, 2017 09:14
-
-
Save Loupax/af819570fcd8b904f5c67caece89f8a1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
use Symfony\Component\Console\Input\ArgvInput; | |
use Symfony\Component\Filesystem\Filesystem; | |
use Symfony\Component\Process\Exception\ProcessFailedException; | |
use Symfony\Component\Process\Process; | |
define('NO_RECREATE_DB', (bool) getenv('NO_RECREATE_DB') ?: false); | |
define('CLEAR_CACHE', (bool) getenv('CLEAR_CACHE') ?: true); | |
define('RECREATE_DB', (bool) getenv('RECREATE_DB') ?: false); | |
gc_disable(); | |
ini_set('memory_limit', -1); | |
// This file should be in "./tests/" | |
$rootDir = __DIR__.'/..'; | |
// Place where we store phpunit logs & test databases | |
define('BUILD_DIR', $rootDir.'/build'); | |
define('DATABASE_TEST_FILE', $rootDir.'/build/database_test.db'); | |
define('DATABASE_REFERENCE_FILE', $rootDir.'/build/database_reference.db'); | |
$file = $rootDir.'/vendor/autoload.php'; | |
if (!file_exists($file)) { | |
throw new RuntimeException('Install dependencies to run test suite.'); | |
} | |
/** @var Composer\Autoload\ClassLoader $autoload */ | |
$autoload = require $file; | |
(new \Symfony\Component\Dotenv\Dotenv())->load(__DIR__.'/../.env'); | |
$input = new ArgvInput(); | |
/** | |
* Execute a command. | |
* | |
* @param string $cmd | |
*/ | |
function runCommand($cmd) { | |
$process = new Process($cmd); | |
$process->setTimeout(180); | |
$process->run(function ($type, $buffer) { | |
if (Process::ERR === $type) { | |
echo 'ERROR > '.$buffer; | |
} else { | |
echo $buffer; | |
} | |
}); | |
if (!$process->isSuccessful()) { | |
throw new ProcessFailedException($process); | |
} | |
} | |
if (!CLEAR_CACHE) { | |
runCommand('php '.$rootDir.'/bin/console cache:clear --no-warmup'); | |
runCommand('php '.$rootDir.'/bin/console cache:warmup'); | |
} | |
$fs = new Filesystem(); | |
if (RECREATE_DB) { | |
$fs->remove(DATABASE_REFERENCE_FILE); | |
$fs->remove(DATABASE_TEST_FILE); | |
} | |
if ($fs->exists(DATABASE_REFERENCE_FILE)) { | |
// Reset database everytime | |
$fs->copy(DATABASE_REFERENCE_FILE, DATABASE_TEST_FILE, true); | |
return; | |
} | |
if (NO_RECREATE_DB && file_exists($rootDir.'/build/database_reference.db')) { | |
return; | |
} | |
// Remove build dir files | |
if (!is_dir($rootDir.'/build')) { | |
$fs->mkdir($rootDir.'/build'); | |
} | |
if ($fs->exists(DATABASE_TEST_FILE)) { | |
$fs->remove(DATABASE_TEST_FILE); | |
} | |
runCommand('php '.$rootDir.'/bin/console doctrine:database:create'); | |
runCommand('php '.$rootDir.'/bin/console doctrine:schema:create'); | |
runCommand('php '.$rootDir.'/bin/console doctrine:fixtures:load --append'); | |
$fs->copy(DATABASE_TEST_FILE, DATABASE_REFERENCE_FILE); |
This file contains hidden or 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
{ | |
"name": "project/project", | |
"license": "MIT", | |
"type": "project", | |
"autoload": { | |
"psr-4": { | |
"": "src/" | |
}, | |
"classmap": [ | |
"app/AppKernel.php", | |
"app/AppCache.php" | |
] | |
}, | |
"autoload-dev": { | |
"psr-4": { | |
"Tests\\": "tests/" | |
}, | |
"files": [ | |
"vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php" | |
] | |
}, | |
"require-dev": { | |
"symfony/process": "^3.2", | |
"symfony/phpunit-bridge": "^3.2", | |
"doctrine/doctrine-fixtures-bundle": "^2.3", | |
"pierstoval/web-test-case": "^0.1.5", | |
"phpunit/phpunit": "^5.7|^6.0" | |
} | |
} |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.7/phpunit.xsd" | |
backupGlobals="false" | |
backupStaticAttributes="false" | |
convertErrorsToExceptions="true" | |
convertNoticesToExceptions="true" | |
convertWarningsToExceptions="true" | |
processIsolation="false" | |
stopOnFailure="false" | |
colors="true" | |
verbose="true" | |
bootstrap="./tests/bootstrap.php" | |
beStrictAboutTestsThatDoNotTestAnything="true" | |
beStrictAboutOutputDuringTests="true" | |
beStrictAboutTodoAnnotatedTests="true" | |
beStrictAboutResourceUsageDuringSmallTests="true" | |
> | |
<testsuites> | |
<testsuite name="Project test suite"> | |
<directory>./src/*Bundle/Tests</directory> | |
<directory>./src/*/*Bundle/Tests</directory> | |
<exclude>./vendor</exclude> | |
</testsuite> | |
</testsuites> | |
<!--% | |
<logging> | |
<log type="junit" target="./build/log/logfile.xml" /> | |
<log type="coverage-html" target="./build/log/report" lowUpperBound="35" highLowerBound="70" /> | |
<log type="coverage-clover" target="./build/log/clover.xml" /> | |
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false" /> | |
</logging> | |
%--> | |
<php> | |
<server name="KERNEL_DIR" value="./app/" /> | |
<ini name="error_reporting" value="-1" /> | |
<ini name="zend.enable_gc" value="0" /> | |
<env name="SYMFONY_ENV" value="test" /> | |
<env name="SYMFONY_DEBUG" value="0" /> | |
<!-- Uncomment this if you do not need to refresh the whole cache between runs | |
<env name="NO_CLEAR_CACHE" value="1" /> | |
--> | |
<!-- Uncomment this if you don't want to reset the database between runs | |
<env name="NO_RECREATE_DB" value="1" /> | |
--> | |
<!-- Uncomment this if you want to force database recreation between runs | |
<env name="RECREATE_DB" value="1" /> | |
--> | |
</php> | |
<filter> | |
<whitelist processUncoveredFilesFromWhitelist="true"> | |
<directory>./src</directory> | |
<exclude> | |
<directory>./src/*Bundle/Resources</directory> | |
<directory>./src/*/*Bundle/Resources</directory> | |
<directory>./src/*/Bundle/*Bundle/Resources</directory> | |
<directory>./src/*Bundle/DataFixtures</directory> | |
<directory>./src/*/*Bundle/DataFixtures</directory> | |
<directory>./src/*/Bundle/*Bundle/DataFixtures</directory> | |
<directory>./src/*Bundle/Tests</directory> | |
<directory>./src/*/*Bundle/Tests</directory> | |
<directory>./src/*/Bundle/*Bundle/Tests</directory> | |
<directory>./vendor</directory> | |
</exclude> | |
</whitelist> | |
</filter> | |
</phpunit> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment