Skip to content

Commit

Permalink
WIP exploratory testing of @run[Class]InSeperateProcess annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
epdenouden committed Dec 5, 2018
1 parent 543f76a commit 34114e8
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -686,16 +686,19 @@ public function run(TestResult $result = null): TestResult
return $result;
}

print "## check: TestCase->runInSeperateProcess()\n";
if ($this->runInSeparateProcess()) {
$runEntireClass = $this->runClassInSeparateProcess && !$this->runTestInSeparateProcess;

$class = new ReflectionClass($this);

if ($runEntireClass) {
print "## @runClassInSeperateProcess\n";
$template = new Text_Template(
__DIR__ . '/../Util/PHP/Template/TestCaseClass.tpl'
);
} else {
print "## @runInSeperateProcess\n";
$template = new Text_Template(
__DIR__ . '/../Util/PHP/Template/TestCaseMethod.tpl'
);
Expand Down
38 changes: 38 additions & 0 deletions tests/end-to-end/regression/GitHub/3258/Issue3258Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/**
* @preserveGlobalState
* @runClassInSeperateProcess
*/
class Issue3258Test extends \PHPUnit\Framework\TestCase
{
protected $internalCounter = 0;

/**
*/
public function testVerifyUntouchedStartStateThenUpdateState()
{
$this->assertSame(0, $this->internalCounter);
$this->assertArrayNotHasKey('Issue3258_test_global', $GLOBALS);

$this->internalCounter++;
$GLOBALS['Issue3258_test_global'] = true;
}

/**
* @depends testVerifyUntouchedStartStateThenUpdateState
*/
public function testStateHasBeenKeptBetweenTests()
{
$this->assertSame(1, $this->internalCounter);
$this->assertSame(true, $GLOBALS['Issue3258_test_global']);
}
}

0 comments on commit 34114e8

Please sign in to comment.