Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 99c8988

Browse files
committed
feature #19915 [Bridge/PhpUnit] Add bin/simple-phpunit wrapper (=phpunit - yaml - prophecy) (nicolas-grekas)
This PR was merged into the 3.2-dev branch. Discussion ---------- [Bridge/PhpUnit] Add bin/simple-phpunit wrapper (=phpunit - yaml - prophecy) | Q | A | ------------- | --- | Branch? | master | New feature? | yes | Tests pass? | not yet | License | MIT | Doc PR | symfony/symfony-docs#6962 So that e.g. [Sami](https://github.com/FriendsOfPHP/Sami/blob/master/phpunit) & [SensioFranmeworkExtraBundle](https://github.com/sensiolabs/SensioFrameworkExtraBundle/blob/master/phpunit) can stop copy/pasting our phpunit wrapper and get it from phpunit-bridge instead. 2 commits to keep the "rename" semantic in the git history. Diff best viewed by looking directly at each commit. Commits ------- 0c1c70c [Bridge/PhpUnit] Add bin/simple-phpunit wrapper (=phpunit - yaml - prophecy)
2 parents 1f9f87b + 0c1c70c commit 99c8988

File tree

3 files changed

+24
-50
lines changed

3 files changed

+24
-50
lines changed

src/Symfony/Bridge/PhpUnit/TextUI/Command.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,4 @@ protected function createRunner()
2323
{
2424
return new TestRunner($this->arguments['loader']);
2525
}
26-
27-
/**
28-
* {@inheritdoc}
29-
*/
30-
protected function handleBootstrap($filename)
31-
{
32-
parent::handleBootstrap($filename);
33-
34-
// By default, we want PHPUnit's autoloader before Symfony's one
35-
if (!getenv('SYMFONY_PHPUNIT_OVERLOAD')) {
36-
$filename = realpath(stream_resolve_include_path($filename));
37-
$symfonyLoader = realpath(dirname(PHPUNIT_COMPOSER_INSTALL).'/../../../vendor/autoload.php');
38-
39-
if ($filename === $symfonyLoader) {
40-
$symfonyLoader = require $symfonyLoader;
41-
$symfonyLoader->unregister();
42-
$symfonyLoader->register(false);
43-
}
44-
}
45-
}
4626
}

phpunit renamed to src/Symfony/Bridge/PhpUnit/bin/simple-phpunit

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,27 @@
1111
*/
1212

1313
// Please update when phpunit needs to be reinstalled with fresh deps:
14-
// Cache-Id-Version: 2016-06-29 13:45 UTC
15-
16-
use Symfony\Component\Process\ProcessUtils;
14+
// Cache-Id-Version: 2016-09-12 09:00 UTC
1715

1816
error_reporting(-1);
19-
require __DIR__.'/src/Symfony/Component/Process/ProcessUtils.php';
2017

2118
// PHPUnit 4.8 does not support PHP 7, while 5.1 requires PHP 5.6+
2219
$PHPUNIT_VERSION = PHP_VERSION_ID >= 50600 ? '5.1' : '4.8';
23-
$PHPUNIT_DIR = __DIR__.'/.phpunit';
20+
$oldPwd = getcwd();
21+
$PHPUNIT_DIR = getenv('SYMFONY_PHPUNIT_DIR') ?: (__DIR__.'/.phpunit');
2422
$PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php';
25-
$PHP = ProcessUtils::escapeArgument($PHP);
23+
$PHP = escapeshellarg($PHP);
2624
if ('phpdbg' === PHP_SAPI) {
2725
$PHP .= ' -qrr';
2826
}
2927

30-
$COMPOSER = file_exists($COMPOSER = __DIR__.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar`))
31-
? $PHP.' '.ProcessUtils::escapeArgument($COMPOSER)
28+
$COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rtrim('\\' === DIRECTORY_SEPARATOR ? preg_replace('/[\r\n].*/', '', `where.exe composer.phar`) : `which composer.phar`))
29+
? $PHP.' '.escapeshellarg($COMPOSER)
3230
: 'composer';
3331

3432
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__) !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION.md5")) {
35-
// Build a standalone phpunit without symfony/yaml
33+
// Build a standalone phpunit without symfony/yaml nor prophecy
3634

37-
$oldPwd = getcwd();
3835
@mkdir($PHPUNIT_DIR);
3936
chdir($PHPUNIT_DIR);
4037
if (file_exists("phpunit-$PHPUNIT_VERSION")) {
@@ -65,13 +62,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
6562
<?php
6663
6764
define('PHPUNIT_COMPOSER_INSTALL', __DIR__.'/vendor/autoload.php');
68-
69-
$loader = require PHPUNIT_COMPOSER_INSTALL;
70-
71-
if (getenv('SYMFONY_PHPUNIT_OVERLOAD') && file_exists(__DIR__.'/../../src/Symfony/Bridge/PhpUnit')) {
72-
$loader->addPsr4('Symfony\\Bridge\\PhpUnit\\', array('src/Symfony/Bridge/PhpUnit'), true);
73-
}
74-
unset($loader);
65+
require PHPUNIT_COMPOSER_INSTALL;
7566
Symfony\Bridge\PhpUnit\TextUI\Command::main();
7667

7768
EOPHP
@@ -82,14 +73,17 @@ EOPHP
8273

8374
}
8475

85-
$cmd = array_map('Symfony\Component\Process\ProcessUtils::escapeArgument', $argv);
76+
$cmd = array_map('escapeshellarg', $argv);
8677
$exit = 0;
8778

88-
if (isset($argv[1]) && 'symfony' === $argv[1]) {
79+
if (isset($argv[1]) && 'symfony' === $argv[1] && !file_exists('symfony') && file_exists('src/Symfony')) {
80+
$argv[1] = 'src/Symfony';
81+
}
82+
if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) {
8983
array_shift($cmd);
9084
}
9185

92-
$cmd[0] = sprintf('%s %s --colors=always', $PHP, ProcessUtils::escapeArgument("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"));
86+
$cmd[0] = sprintf('%s %s --colors=always', $PHP, escapeshellarg("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"));
9387
$cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s';
9488

9589
if ('\\' === DIRECTORY_SEPARATOR) {
@@ -98,14 +92,12 @@ if ('\\' === DIRECTORY_SEPARATOR) {
9892
$cmd .= '%2$s';
9993
}
10094

101-
if (isset($argv[1]) && 'symfony' === $argv[1]) {
95+
if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) {
10296
// Find Symfony components in plain php for Windows portability
10397

104-
$oldPwd = getcwd();
105-
chdir(__DIR__);
106-
$finder = new RecursiveDirectoryIterator('src/Symfony', FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
98+
$finder = new RecursiveDirectoryIterator($argv[1], FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
10799
$finder = new RecursiveIteratorIterator($finder);
108-
$finder->setMaxDepth(3);
100+
$finder->setMaxDepth(getenv('SYMFONY_PHPUNIT_MAX_DEPTH') ?: 3);
109101

110102
$skippedTests = isset($_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS']) ? $_SERVER['SYMFONY_PHPUNIT_SKIPPED_TESTS'] : false;
111103
$runningProcs = array();
@@ -120,7 +112,7 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
120112
putenv("SYMFONY_PHPUNIT_SKIPPED_TESTS=$component/$skippedTests");
121113
}
122114

123-
$c = ProcessUtils::escapeArgument($component);
115+
$c = escapeshellarg($component);
124116

125117
if ($proc = proc_open(sprintf($cmd, $c, " > $c/phpunit.stdout 2> $c/phpunit.stderr"), array(), $pipes)) {
126118
$runningProcs[$component] = $proc;
@@ -130,7 +122,6 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
130122
}
131123
}
132124
}
133-
chdir($oldPwd);
134125

135126
// Fixes for colors support on appveyor
136127
// See https://github.com/appveyor/ci/issues/373
@@ -185,11 +176,11 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
185176
}
186177
}
187178
}
188-
} elseif (!isset($argv[1]) || 'install' !== $argv[1]) {
179+
} elseif (!isset($argv[1]) || 'install' !== $argv[1] || file_exists('install')) {
189180
// Run regular phpunit in a subprocess
190181

191182
$errFile = tempnam(sys_get_temp_dir(), 'phpunit.stderr.');
192-
if ($proc = proc_open(sprintf($cmd, '', ' 2> '.ProcessUtils::escapeArgument($errFile)), array(1 => array('pipe', 'w')), $pipes)) {
183+
if ($proc = proc_open(sprintf($cmd, '', ' 2> '.escapeshellarg($errFile)), array(1 => array('pipe', 'w')), $pipes)) {
193184
stream_copy_to_stream($pipes[1], STDOUT);
194185
fclose($pipes[1]);
195186
$exit = proc_close($proc);
@@ -199,7 +190,7 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
199190
}
200191

201192
if (!file_exists($component = array_pop($argv))) {
202-
$component = basename(getcwd());
193+
$component = basename($oldcwd);
203194
}
204195

205196
if ($exit) {

src/Symfony/Bridge/PhpUnit/composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"/Tests/"
3131
]
3232
},
33+
"bin": [
34+
"bin/simple-phpunit"
35+
],
3336
"minimum-stability": "dev",
3437
"extra": {
3538
"branch-alias": {

0 commit comments

Comments
 (0)