Created
February 15, 2023 21:21
-
-
Save mglaman/8ffe67a117f2aa4f41839420d2e7abb9 to your computer and use it in GitHub Desktop.
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
<?php | |
use PHPUnit\Framework\TestCase; | |
use SebastianBergmann\CodeCoverage\CodeCoverage; | |
use SebastianBergmann\CodeCoverage\Driver\Selector; | |
use PHPUnit\TextUI\XmlConfiguration\Loader; | |
use PHPUnit\TextUI\XmlConfiguration\PhpHandler; | |
if (!defined('STDOUT')) { | |
// php://stdout does not obey output buffering. Any output would break | |
// unserialization of child process results in the parent process. | |
define('STDOUT', fopen('php://temp', 'w+b')); | |
define('STDERR', fopen('php://stderr', 'wb')); | |
} | |
ini_set('display_errors', 'stderr'); | |
set_include_path(''.'/Users/mglaman/Sites/pest-drupal/vendor/pear/archive_tar:/Users/mglaman/Sites/pest-drupal/vendor/pear/console_getopt:/Users/mglaman/Sites/pest-drupal/vendor/pear/pear-core-minimal/src:/Users/mglaman/Sites/pest-drupal/vendor/pear/pear_exception:.:/usr/local/Cellar/php@8.1/8.1.15/share/php@8.1/pear'.''); | |
$composerAutoload = ''; | |
$phar = ''; | |
ob_start(); | |
if ($composerAutoload) { | |
require_once $composerAutoload; | |
define('PHPUNIT_COMPOSER_INSTALL', $composerAutoload); | |
} else if ($phar) { | |
require $phar; | |
} | |
function __phpunit_run_isolated_test() | |
{ | |
if (!class_exists('P\Tests\Kernel\ExampleTest')) { | |
require_once '/Users/mglaman/Sites/pest-drupal/vendor/pestphp/pest/src/Factories/TestCaseFactory.php(223) : eval()'d code'; | |
} | |
$result = new PHPUnit\Framework\TestResult; | |
if (false) { | |
$filter = unserialize(''.'N;'.''); | |
$codeCoverage = new CodeCoverage( | |
(new Selector)->forLineCoverage($filter), | |
$filter | |
); | |
if (false) { | |
$codeCoverage->cacheStaticAnalysis(unserialize(''.'N;'.'')); | |
} | |
$result->setCodeCoverage($codeCoverage); | |
} | |
$result->beStrictAboutTestsThatDoNotTestAnything(true); | |
$result->beStrictAboutOutputDuringTests(false); | |
$result->enforceTimeLimit(false); | |
$result->beStrictAboutTodoAnnotatedTests(false); | |
$result->beStrictAboutResourceUsageDuringSmallTests(false); | |
$test = new P\Tests\Kernel\ExampleTest('__test', unserialize(''.'a:0:{}'.''), ''.('').''); | |
\assert($test instanceof TestCase); | |
$test->setDependencyInput(unserialize(''.'a:0:{}'.'')); | |
$test->setInIsolation(true); | |
ob_end_clean(); | |
$test->run($result); | |
$output = ''; | |
if (!$test->hasExpectationOnOutput()) { | |
$output = $test->getActualOutput(); | |
} | |
ini_set('xdebug.scream', '0'); | |
@rewind(STDOUT); /* @ as not every STDOUT target stream is rewindable */ | |
if ($stdout = @stream_get_contents(STDOUT)) { | |
$output = $stdout . $output; | |
$streamMetaData = stream_get_meta_data(STDOUT); | |
if (!empty($streamMetaData['stream_type']) && 'STDIO' === $streamMetaData['stream_type']) { | |
@ftruncate(STDOUT, 0); | |
@rewind(STDOUT); | |
} | |
} | |
print serialize( | |
[ | |
'testResult' => $test->getResult(), | |
'numAssertions' => $test->getNumAssertions(), | |
'result' => $result, | |
'output' => $output | |
] | |
); | |
} | |
$configurationFilePath = '/Users/mglaman/Sites/pest-drupal/phpunit.xml'; | |
if ('' !== $configurationFilePath) { | |
$configuration = (new Loader)->load($configurationFilePath); | |
(new PhpHandler)->handle($configuration->php()); | |
unset($configuration); | |
} | |
function __phpunit_error_handler($errno, $errstr, $errfile, $errline) | |
{ | |
return true; | |
} | |
set_error_handler('__phpunit_error_handler'); | |
$GLOBALS['__PHPUNIT_BOOTSTRAP'] = '/Users/mglaman/Sites/pest-drupal/vendor/autoload.php'; | |
restore_error_handler(); | |
if (isset($GLOBALS['__PHPUNIT_BOOTSTRAP'])) { | |
require_once $GLOBALS['__PHPUNIT_BOOTSTRAP']; | |
unset($GLOBALS['__PHPUNIT_BOOTSTRAP']); | |
} | |
__phpunit_run_isolated_test(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment