Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed PHPUnit 8.3 incompatibility: method handleError was renamed to …
…__invoke
- Loading branch information
Showing
2 changed files
with
106 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/Symfony/Bridge/PhpUnit/Legacy/ErrorHandlerCallerV83.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\PhpUnit\Legacy; | ||
|
||
use PHPUnit\TextUI\Command; | ||
use PHPUnit\Util\Configuration; | ||
use PHPUnit\Util\ErrorHandler; | ||
|
||
/** | ||
* Since PHPUnit v8.3 ErrorHandler is invokable and requires variables in constructor. | ||
* This class reuses PHPUnit infrastructure to get these variables. | ||
* | ||
* @author Dmitrii Poddubnyi <dpoddubny@gmail.com> | ||
* | ||
* @internal | ||
*/ | ||
class ErrorHandlerCallerV83 extends Command | ||
{ | ||
public function __construct(array $argv) | ||
{ | ||
$this->handleArguments($argv); | ||
} | ||
|
||
public function handleError($type, $msg, $file, $line, $context) | ||
{ | ||
$arguments = $this->arguments; | ||
$this->handleConfiguration($arguments); | ||
$object = new ErrorHandler( | ||
$arguments['convertDeprecationsToExceptions'], | ||
$arguments['convertErrorsToExceptions'], | ||
$arguments['convertNoticesToExceptions'], | ||
$arguments['convertWarningsToExceptions'] | ||
); | ||
|
||
return $object($type, $msg, $file, $line, $context); | ||
} | ||
|
||
/** | ||
* This is simplified version of PHPUnit\TextUI\TestRunner::handleConfiguration. | ||
* https://github.com/sebastianbergmann/phpunit/blob/8.3.2/src/TextUI/TestRunner.php#L815-L1243 | ||
*/ | ||
private function handleConfiguration(array &$arguments): void | ||
{ | ||
if (isset($arguments['configuration']) && | ||
!$arguments['configuration'] instanceof Configuration) { | ||
$arguments['configuration'] = Configuration::getInstance( | ||
$arguments['configuration'] | ||
); | ||
} | ||
|
||
if (isset($arguments['configuration'])) { | ||
$arguments['configuration']->handlePHPConfiguration(); | ||
|
||
$phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration(); | ||
|
||
if (isset($phpunitConfiguration['convertDeprecationsToExceptions']) && !isset($arguments['convertDeprecationsToExceptions'])) { | ||
$arguments['convertDeprecationsToExceptions'] = $phpunitConfiguration['convertDeprecationsToExceptions']; | ||
} | ||
|
||
if (isset($phpunitConfiguration['convertErrorsToExceptions']) && !isset($arguments['convertErrorsToExceptions'])) { | ||
$arguments['convertErrorsToExceptions'] = $phpunitConfiguration['convertErrorsToExceptions']; | ||
} | ||
|
||
if (isset($phpunitConfiguration['convertNoticesToExceptions']) && !isset($arguments['convertNoticesToExceptions'])) { | ||
$arguments['convertNoticesToExceptions'] = $phpunitConfiguration['convertNoticesToExceptions']; | ||
} | ||
|
||
if (isset($phpunitConfiguration['convertWarningsToExceptions']) && !isset($arguments['convertWarningsToExceptions'])) { | ||
$arguments['convertWarningsToExceptions'] = $phpunitConfiguration['convertWarningsToExceptions']; | ||
} | ||
} | ||
$arguments['convertDeprecationsToExceptions'] = $arguments['convertDeprecationsToExceptions'] ?? true; | ||
$arguments['convertErrorsToExceptions'] = $arguments['convertErrorsToExceptions'] ?? true; | ||
$arguments['convertNoticesToExceptions'] = $arguments['convertNoticesToExceptions'] ?? true; | ||
$arguments['convertWarningsToExceptions'] = $arguments['convertWarningsToExceptions'] ?? true; | ||
} | ||
} |