From 9bba2c902a72f6bead4a21b80a525b31837cbbe0 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 8 Nov 2018 06:02:52 -0500 Subject: [PATCH 1/4] Only run isBeforeClassMethod(), isBeforeMethod(), isAfterMethod(), and isAfterClassMethod() on likely candidates --- src/Util/Test.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Util/Test.php b/src/Util/Test.php index c0c1ec78f63..fe23e05b739 100644 --- a/src/Util/Test.php +++ b/src/Util/Test.php @@ -10,6 +10,7 @@ namespace PHPUnit\Util; use PharIo\Version\VersionConstraintParser; +use PHPUnit\Framework\Assert; use PHPUnit\Framework\CodeCoverageException; use PHPUnit\Framework\Exception; use PHPUnit\Framework\InvalidCoversTargetException; @@ -706,6 +707,14 @@ public static function getHookMethods(string $className): array $class = new ReflectionClass($className); foreach ($class->getMethods() as $method) { + if ($method->getDeclaringClass()->getName() === Assert::class) { + continue; + } + + if ($method->getDeclaringClass()->getName() === TestCase::class) { + continue; + } + if (self::isBeforeClassMethod($method)) { \array_unshift( self::$hookMethods[$className]['beforeClass'], From bc9f7ac94447c5d4cf52394a49dfadd891443564 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 8 Nov 2018 06:08:19 -0500 Subject: [PATCH 2/4] Refactor --- src/Framework/TestCase.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index 40ff2783ade..2edb160e919 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -686,11 +686,9 @@ public function run(TestResult $result = null): TestResult return $result; } - $runEntireClass = $this->runClassInSeparateProcess && !$this->runTestInSeparateProcess; + if ($this->runInSeparateProcess()) { + $runEntireClass = $this->runClassInSeparateProcess && !$this->runTestInSeparateProcess; - if (($this->runTestInSeparateProcess === true || $this->runClassInSeparateProcess === true) && - $this->inIsolation !== true && - !$this instanceof PhptTestCase) { $class = new ReflectionClass($this); if ($runEntireClass) { @@ -2114,4 +2112,10 @@ private function checkExceptionExpectations(Throwable $throwable): bool return $result; } + + private function runInSeparateProcess(): bool + { + return ($this->runTestInSeparateProcess === true || $this->runClassInSeparateProcess === true) && + $this->inIsolation !== true && !$this instanceof PhptTestCase; + } } From 1bb3ca072ba1bac126530aed42c2027e9f1679e3 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 8 Nov 2018 06:38:42 -0500 Subject: [PATCH 3/4] Closes #3394 --- ChangeLog-7.4.md | 1 + build/binary-phar-autoload.php.in | 18 ++++++++---------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ChangeLog-7.4.md b/ChangeLog-7.4.md index 38de33d8257..6c76518d3a7 100644 --- a/ChangeLog-7.4.md +++ b/ChangeLog-7.4.md @@ -7,6 +7,7 @@ All notable changes of the PHPUnit 7.4 release series are documented in this fil ### Fixed * Fixed [#3379](https://github.com/sebastianbergmann/phpunit/issues/3379): Dependent test of skipped test has status `-1` +* Fixed [#3394](https://github.com/sebastianbergmann/phpunit/issues/3394): Process Isolation does not work when PHPUnit is used as PHAR ## [7.4.3] - 2018-10-23 diff --git a/build/binary-phar-autoload.php.in b/build/binary-phar-autoload.php.in index cab03d3f929..e65915726f8 100644 --- a/build/binary-phar-autoload.php.in +++ b/build/binary-phar-autoload.php.in @@ -40,18 +40,16 @@ Phar::mapPhar('___PHAR___'); ___FILELIST___ -if (!$execute) { - exit; -} - -if (isset($printManifest)) { - print file_get_contents(__PHPUNIT_PHAR_ROOT__ . '/manifest.txt'); +if ($execute) { + if (isset($printManifest)) { + print file_get_contents(__PHPUNIT_PHAR_ROOT__ . '/manifest.txt'); - exit; -} + exit; + } -unset($execute); + unset($execute); -PHPUnit\TextUI\Command::main(); + PHPUnit\TextUI\Command::main(); +} __HALT_COMPILER(); From 9f149b9b9a89e76be4296de81d7bcf486dedff84 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 8 Nov 2018 06:40:15 -0500 Subject: [PATCH 4/4] Fix --- build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.xml b/build.xml index c0d4291c784..ae14a6d9c86 100644 --- a/build.xml +++ b/build.xml @@ -110,7 +110,7 @@ - +