Skip to content

Commit

Permalink
Issue sebastianbergmann#2724 - fix @runClassInSeparateProcess not wor…
Browse files Browse the repository at this point in the history
…king for tests

without a data provider
  • Loading branch information
KintradimCrux committed Nov 30, 2017
1 parent 4ab66ee commit dbaf284
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Framework/TestSuite.php
Expand Up @@ -608,6 +608,14 @@ public static function createTest(ReflectionClass $theClass, $name)
}
}

if ($runClassInSeparateProcess) {
$test->setRunClassInSeparateProcess(true);

if ($preserveGlobalState !== null) {
$test->setPreserveGlobalState($preserveGlobalState);
}
}

if ($backupSettings['backupGlobals'] !== null) {
$test->setBackupGlobals($backupSettings['backupGlobals']);
}
Expand Down
20 changes: 20 additions & 0 deletions tests/Regression/GitHub/2724.phpt
@@ -0,0 +1,20 @@
--TEST--
GH-2724: Missing initialization of setRunClassInSeparateProcess() for tests without data providers
--FILE--
<?php

$_SERVER['argv'][1] = '--no-configuration';
$_SERVER['argv'][2] = '--bootstrap';
$_SERVER['argv'][3] = __DIR__ . '/2724/bootstrap.php';
$_SERVER['argv'][4] = __DIR__ . '/2724/RunClassInSeparateProcessWithoutDataProviderTest.php';

require __DIR__ . '/../../bootstrap.php';
PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

.. 2 / 2 (100%)

Time: %s, Memory: %s

OK (2 tests, 2 assertions)
@@ -0,0 +1,25 @@
<?php
use PHPUnit\Framework\TestCase;

if (false === getenv('_MAINPID')) {
putenv('_MAINPID='.posix_getpid());
}

/**
* @runClassInSeparateProcess
*/
class Issue2724_RunClassInSeparateProcessWithoutDataProviderTest extends TestCase
{
public function test_without_dataProvider(){
$this->assertNotEquals((int) getenv('_MAINPID'), posix_getpid());
}
public function nullDataProvider(){
return array(array(null, null, null));
}
/**
* @dataProvider nullDataProvider
*/
public function test_with_dataProvider(){
$this->assertNotEquals((int) getenv('_MAINPID'), posix_getpid());
}
}
3 changes: 3 additions & 0 deletions tests/Regression/GitHub/2724/bootstrap.php
@@ -0,0 +1,3 @@
<?php

require __DIR__ . '/../../../bootstrap.php';

0 comments on commit dbaf284

Please sign in to comment.