Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb08ec5

Browse files
Add support for env, server and ini settings in parallel test runs
1 parent974cab3 commitfb08ec5

File tree

10 files changed

+585
-112
lines changed

10 files changed

+585
-112
lines changed

‎.appveyor.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ test_script:
5454
-SET X=0
5555
-SET SYMFONY_PHPUNIT_SKIPPED_TESTS=phpunit.skipped
5656
-copy /Y c:\php\php.ini-min c:\php\php.ini
57-
-php phpunit src\Symfony --exclude-group benchmark,intl-data || SET X=!errorlevel!
57+
-php phpunit src\Symfony --bootstrap vendor\autoload.php --exclude-group benchmark,intl-data || SET X=!errorlevel!
5858
-copy /Y c:\php\php.ini-max c:\php\php.ini
59-
-php phpunit src\Symfony --exclude-group benchmark,intl-data || SET X=!errorlevel!
59+
-php phpunit src\Symfony --bootstrap vendor\autoload.php --exclude-group benchmark,intl-data || SET X=!errorlevel!
6060
-exit %X%

‎.travis.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ before_install:
6666
[ -d ~/.composer ] || mkdir ~/.composer
6767
cp .composer/* ~/.composer/
6868
export PHPUNIT=$(readlink -f ./phpunit)
69-
export PHPUNIT_X="$PHPUNIT --exclude-group tty,benchmark,intl-data"
69+
export PHPUNIT_X="$PHPUNIT --bootstrap vendor/autoload.php --exclude-group tty,benchmark,intl-data"
7070
export COMPOSER_UP='composer update --no-progress --no-suggest --ansi'
7171
export COMPONENTS=$(find src/Symfony -mindepth 2 -type f -name phpunit.xml.dist -printf '%h\n')
7272
find ~/.phpenv -name xdebug.ini -delete
@@ -253,10 +253,10 @@ install:
253253
echo "$COMPONENTS" | xargs -n1 -I{} tar --append -f ~/php-ext/composer-lowest.lock.tar {}/composer.lock
254254
else
255255
echo "$COMPONENTS" | parallel --gnu "tfold {} $PHPUNIT_X {}"
256-
tfold src/Symfony/Component/Console.tty $PHPUNIT src/Symfony/Component/Console --group tty
256+
tfold src/Symfony/Component/Console.tty $PHPUNIT src/Symfony/Component/Console --bootstrap vendor/autoload.php --group tty
257257
if [[ $PHP = ${MIN_PHP%.*} ]]; then
258258
export PHP=$MIN_PHP
259-
tfold src/Symfony/Component/Process.sigchild SYMFONY_DEPRECATIONS_HELPER=weak php-$MIN_PHP/sapi/cli/php ./phpunit --colors=always src/Symfony/Component/Process/
259+
tfold src/Symfony/Component/Process.sigchild SYMFONY_DEPRECATIONS_HELPER=weak php-$MIN_PHP/sapi/cli/php ./phpunit --bootstrap vendor/autoload.php --colors=always src/Symfony/Component/Process/
260260
fi
261261
fi
262262
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bridge\PhpUnit\Tests;
13+
14+
usePHPUnit\Framework\TestCase;
15+
16+
class SimplePhpUnitTestextends TestCase
17+
{
18+
privatestatic$testFiles = [
19+
__DIR__.'/SimplePhpUnitTest/Modul1/phpunit.xml.dist',
20+
__DIR__.'/SimplePhpUnitTest/Modul2/phpunit.xml.dist',
21+
];
22+
23+
private$currentCwd;
24+
25+
publicstaticfunctionsetUpBeforeClass()
26+
{
27+
foreach (self::$testFilesas$testFile) {
28+
$renamedFile =str_replace('.xml.dist','.txml.dist',$testFile);
29+
30+
if (file_exists($renamedFile)) {
31+
rename($renamedFile,$testFile);
32+
}
33+
}
34+
}
35+
36+
publicstaticfunctiontearDownAfterClass()
37+
{
38+
foreach (self::$testFilesas$testFile) {
39+
if (file_exists($testFile)) {
40+
rename($testFile,str_replace('.xml.dist','.txml.dist',$testFile));
41+
}
42+
}
43+
}
44+
45+
protectedfunctionsetUp()
46+
{
47+
$this->currentCwd =getcwd();
48+
chdir(\dirname(__DIR__));
49+
}
50+
51+
protectedfunctiontearDown()
52+
{
53+
chdir($this->currentCwd);
54+
}
55+
56+
publicfunctiontestInstall()
57+
{
58+
$cmd ='bin/simple-phpunit install';
59+
$this->execute($cmd,$output,$exitCode);
60+
$this->assertSame(0,$exitCode);
61+
}
62+
63+
publicfunctiontestSimplePhpunitShortConfigurationFile()
64+
{
65+
$cmd ='bin/simple-phpunit -c Tests/SimplePhpUnitTest/Modul1/phpunit.xml.dist';
66+
$this->execute($cmd,$output);
67+
$this->assertContains('OK (7 tests, 11 assertions)',implode(PHP_EOL,$output));
68+
}
69+
70+
publicfunctiontestSimplePhpunitWithConfigurationWithFilter()
71+
{
72+
$cmd ='bin/simple-phpunit --filter=testEnv --configuration Tests/SimplePhpUnitTest/Modul1/phpunit.xml.dist';
73+
$this->execute($cmd,$output);
74+
$this->assertContains('OK (1 test, 1 assertion)',implode(PHP_EOL,$output));
75+
}
76+
77+
publicfunctiontestParallelTests()
78+
{
79+
$cmd ='bin/simple-phpunit Tests/SimplePhpUnitTest';
80+
$this->execute($cmd,$output);
81+
82+
// Check parallel test suites are runned successfully
83+
$testSuites =explode('Test Suite',implode(PHP_EOL,$output));
84+
85+
unset($testSuites[0]);// Remove header output
86+
$testSuites =array_values($testSuites);
87+
$this->assertCount(2,$testSuites);
88+
89+
$this->assertContains('OK (7 tests, 11 assertions)',$testSuites[0]);
90+
$this->assertContains('OK (7 tests, 11 assertions)',$testSuites[1]);
91+
92+
// Check different phpunit versions are installed
93+
$this->assertFileExists(\dirname(__DIR__).'/.phpunit/phpunit-6.5-remove-symfony_yaml-phpspec_prophecy/phpunit');
94+
$this->assertFileExists(\dirname(__DIR__).'/.phpunit/phpunit-7.4-remove-phpspec_prophecy-symfony_yaml/phpunit');
95+
}
96+
97+
privatefunctionexecute($command, &$output =null, &$return_var =null)
98+
{
99+
$oldPhpUnitRootDirectory =getenv('SYMFONY_PHPUNIT_ROOT_DIRECTORY');
100+
$oldPhpUnitDirectory =getenv('SYMFONY_PHPUNIT_DIR');
101+
102+
// Use putenv vor windows compatible setting of environment variables
103+
putenv('SYMFONY_PHPUNIT_ROOT_DIRECTORY='.\dirname(__DIR__));
104+
putenv('SYMFONY_PHPUNIT_DIR='.\dirname(__DIR__).'/.phpunit');
105+
106+
$result =exec(
107+
sprintf('php %s',$command),
108+
$output,
109+
$return_var
110+
);
111+
112+
// Reset env variables
113+
if (false !==$oldPhpUnitRootDirectory) {
114+
// Set to old value
115+
putenv('SYMFONY_PHPUNIT_ROOT_DIRECTORY='.$oldPhpUnitRootDirectory);
116+
}else {
117+
// Remove when no old value exists
118+
putenv('SYMFONY_PHPUNIT_ROOT_DIRECTORY');
119+
}
120+
121+
if (false !==$oldPhpUnitDirectory) {
122+
// Set to old value
123+
putenv('SYMFONY_PHPUNIT_DIR='.$oldPhpUnitDirectory);
124+
}else {
125+
// Remove when no old value exists
126+
putenv('SYMFONY_PHPUNIT_DIR');
127+
}
128+
129+
return$result;
130+
}
131+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html-->
4+
<phpunitxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
6+
backupGlobals="false"
7+
colors="true"
8+
bootstrap="tests/bootstrap.php"
9+
>
10+
<php>
11+
<ininame="memory_limit"value="-1" />
12+
<ininame="precision"value="7"/>
13+
<servername="SERVER_VAR"value="SERVER_VAR_MODUL_1"/>
14+
<!-- to avoid conflicts with global env force=true is added for this test in CI-->
15+
<envname="ENV_VAR"value="ENV_VAR_MODUL_1"force="true" />
16+
<envname="SYMFONY_DEPRECATIONS_HELPER"value="disabled"force="true" />
17+
<envname="SYMFONY_PHPUNIT_REMOVE"value="symfony/yaml phpspec/prophecy"force="true" />
18+
<envname="SYMFONY_PHPUNIT_VERSION"value="6.5"force="true" />
19+
</php>
20+
21+
<testsuites>
22+
<testsuitename="Modul1 Test Suite">
23+
<directorysuffix=".tphp">tests</directory>
24+
</testsuite>
25+
</testsuites>
26+
27+
<filter>
28+
<whitelist>
29+
<directory>.</directory>
30+
</whitelist>
31+
</filter>
32+
33+
<listeners>
34+
<listenerclass="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
35+
</listeners>
36+
</phpunit>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Symfony\Bridge\PhpUnit\Tests\SimplePhpUnitTest\Modul1;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
class ModulTest extends TestCase
8+
{
9+
public function testEnv()
10+
{
11+
$this->assertSame('ENV_VAR_MODUL_1', getenv('ENV_VAR'));
12+
}
13+
14+
public function testServer()
15+
{
16+
$this->assertSame('SERVER_VAR_MODUL_1', $_SERVER['SERVER_VAR']);
17+
}
18+
19+
public function testIni()
20+
{
21+
$this->assertSame('7', ini_get('precision'));
22+
}
23+
24+
public function testBootstrapEnv()
25+
{
26+
$this->assertSame('BOOTSTRAP_ENV_VAR_MODUL_1', getenv('BOOTSTRAP_ENV_VAR'));
27+
28+
sleep(1); // To Check if the output is streamed
29+
30+
$this->assertTrue(true);
31+
}
32+
33+
public function testBootstrapServer()
34+
{
35+
$this->assertSame('BOOTSTRAP_SERVER_VAR_MODUL_1', $_SERVER['BOOTSTRAP_SERVER_VAR']);
36+
}
37+
38+
public function testBootstrapIni()
39+
{
40+
$this->assertSame('15', ini_get('serialize_precision'));
41+
}
42+
43+
public function testSymfonyEnvs()
44+
{
45+
$this->assertSame('disabled', getenv('SYMFONY_DEPRECATIONS_HELPER'));
46+
$this->assertSame('symfony/yaml phpspec/prophecy', getenv('SYMFONY_PHPUNIT_REMOVE'));
47+
$this->assertSame('6.5', getenv('SYMFONY_PHPUNIT_VERSION'));
48+
exec((defined('PHP_BINARY') ? PHP_BINARY : 'php') . ' ' . $_SERVER['SCRIPT_NAME'] . ' --version', $output);
49+
$this->assertContains('PHPUnit 6.5', $output[0]);
50+
51+
@trigger_error('Deprecation Error which should be ignored');
52+
}
53+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
putenv('BOOTSTRAP_ENV_VAR=BOOTSTRAP_ENV_VAR_MODUL_1');
4+
$_SERVER['BOOTSTRAP_SERVER_VAR'] ='BOOTSTRAP_SERVER_VAR_MODUL_1';
5+
ini_set('serialize_precision',15);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html-->
4+
<phpunitxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
6+
backupGlobals="false"
7+
colors="true"
8+
bootstrap="tests/bootstrap.php"
9+
>
10+
<php>
11+
<ininame="memory_limit"value="-1" />
12+
<ininame="precision"value="9" />
13+
<servername="SERVER_VAR"value="SERVER_VAR_MODUL_2"/>
14+
<!-- to avoid conflicts with global env force=true is added for this test in CI-->
15+
<envname="ENV_VAR"value="ENV_VAR_MODUL_2"force="true" />
16+
<envname="SYMFONY_DEPRECATIONS_HELPER"value="weak"force="true" />
17+
<envname="SYMFONY_PHPUNIT_REMOVE"value="phpspec/prophecy symfony/yaml"force="true" />
18+
<envname="SYMFONY_PHPUNIT_VERSION"value="7.4"force="true" />
19+
</php>
20+
21+
<testsuites>
22+
<testsuitename="Modul2 Test Suite">
23+
<directorysuffix=".tphp">tests</directory>
24+
</testsuite>
25+
</testsuites>
26+
27+
<filter>
28+
<whitelist>
29+
<directory>.</directory>
30+
</whitelist>
31+
</filter>
32+
33+
<listeners>
34+
<listenerclass="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
35+
</listeners>
36+
</phpunit>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Symfony\Bridge\PhpUnit\Tests\SimplePhpUnitTest\Modul2;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
class ModulTest extends TestCase
8+
{
9+
public function testEnv()
10+
{
11+
$this->assertSame('ENV_VAR_MODUL_2', getenv('ENV_VAR'));
12+
}
13+
14+
public function testServer()
15+
{
16+
$this->assertSame('SERVER_VAR_MODUL_2', $_SERVER['SERVER_VAR']);
17+
}
18+
19+
public function testIni()
20+
{
21+
$this->assertSame('9', ini_get('precision'));
22+
}
23+
24+
public function testBootstrapEnv()
25+
{
26+
$this->assertSame('BOOTSTRAP_ENV_VAR_MODUL_2', getenv('BOOTSTRAP_ENV_VAR'));
27+
28+
sleep(1); // To Check if the output is streamed
29+
30+
$this->assertTrue(true);
31+
}
32+
33+
public function testBootstrapServer()
34+
{
35+
$this->assertSame('BOOTSTRAP_SERVER_VAR_MODUL_2', $_SERVER['BOOTSTRAP_SERVER_VAR']);
36+
}
37+
38+
public function testBootstrapIni()
39+
{
40+
$this->assertSame('11', ini_get('serialize_precision'));
41+
}
42+
43+
public function testSymfonyDeprecationHelper()
44+
{
45+
$this->assertSame('weak', getenv('SYMFONY_DEPRECATIONS_HELPER'));
46+
$this->assertSame('phpspec/prophecy symfony/yaml', getenv('SYMFONY_PHPUNIT_REMOVE'));
47+
$this->assertSame('7.4', getenv('SYMFONY_PHPUNIT_VERSION'));
48+
exec((defined('PHP_BINARY') ? PHP_BINARY : 'php') . ' ' . $_SERVER['SCRIPT_NAME'] . ' --version', $output);
49+
$this->assertContains('PHPUnit 7.4', $output[0]);
50+
51+
@trigger_error('Deprecation Error which should be ignored');
52+
}
53+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
putenv('BOOTSTRAP_ENV_VAR=BOOTSTRAP_ENV_VAR_MODUL_2');
4+
$_SERVER['BOOTSTRAP_SERVER_VAR'] ='BOOTSTRAP_SERVER_VAR_MODUL_2';
5+
ini_set('serialize_precision',11);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp