1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
<?php
/*
* This file is part of composer/xdebug-handler.
*
* (c) Composer <https://github.com/composer>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Composer\XdebugHandler\Tests;
use Composer\XdebugHandler\Tests\App\Framework\AppRunner;
use Composer\XdebugHandler\Tests\App\Framework\LogItem;
use Composer\XdebugHandler\Tests\App\Framework\PhpOptions;
use Composer\XdebugHandler\Tests\App\Helpers\FunctionalTestCase;
use PHPUnit\Framework\TestCase;
/**
* @group functional
*/
class AppRestartTest extends FunctionalTestCase
{
/**
*
* @requires extension xdebug
*/
public function testRestart(): void
{
$script = 'app-basic.php';
$logs = $this->runner->run($script);
$this->checkRestart($logs);
}
/**
*
* @requires extension xdebug
*/
public function testRestartWithPrependFile(): void
{
$script = 'app-plain.php';
$options = new PhpOptions();
$options->addPhpArgs('-dauto_prepend_file=app-prepend.php');
$logs = $this->runner->run($script, $options);
$this->checkRestart($logs);
// check app-plain has run
$appName = $this->runner->getAppName($script);
$child = $logs->getValuesForProcessName(2, $appName);
self::assertNotEmpty($child);
}
/**
*
* @requires extension xdebug
*/
public function testRestartWithPrependFileStdin(): void
{
$script = 'app-plain.php';
$options = new PhpOptions();
$options->addPhpArgs('-dauto_prepend_file=app-prepend.php');
$options->setStdin(true);
$logs = $this->runner->run($script, $options);
$this->checkRestart($logs);
// check app-plain has run
$appName = 'Standard input code';
$child = $logs->getValuesForProcessName(2, $appName);
self::assertNotEmpty($child);
}
/**
*
* @requires extension xdebug
*/
public function testRestartWithStdin(): void
{
$script = 'app-stdin.php';
$options = new PhpOptions();
$options->addPhpArgs('--');
$options->addScriptArgs('app-plain.php');
$options->setStdin(true);
$logs = $this->runner->run($script, $options);
$this->checkRestart($logs, 0);
// check not loaded from app-plain
$appName = $this->runner->getAppName('app-plain.php');
$child = $logs->getValuesForProcessName(2, $appName);
$item = $logs->getItemFromList($child, 2);
self::assertStringContainsString('The Xdebug extension is not loaded', $item);
}
/**
*
* @requires extension xdebug
*/
public function testRestartWithIniChange(): void
{
$script = 'app-extend-ini.php';
$options = new PhpOptions();
$options->addPhpArgs('-dphar.read_only=1');
$logs = $this->runner->run($script, $options);
$this->checkRestart($logs);
// check ini setting has changed in child
$appName = $this->runner->getAppName($script);
$child = $logs->getValuesForProcessName(2, $appName);
$item = $logs->getItemFromList($child, 2);
self::assertStringContainsString('phar.readonly=0', $item);
}
/**
*
* @requires extension xdebug
*/
public function testRestartWithXdebug(): void
{
$version = (string) phpversion('xdebug');
if (version_compare($version, '3.0', '<')) {
self::markTestSkipped('Not supported in xdebug version '.$version);
}
$script = 'app-extend-mode.php';
$options = new PhpOptions();
$options->addPhpArgs('-dxdebug.mode=develop');
$logs = $this->runner->run($script, $options);
$this->checkRestart($logs, 2);
$child = $logs->getValuesForProcess(2);
$item = $logs->getItemFromList($child, 2);
self::assertStringContainsString('The Xdebug extension is loaded', $item);
self::assertStringContainsString('xdebug.mode=coverage', $item);
}
/**
*
* @requires extension xdebug
*/
public function testRestartWithProcessPersistent(): void
{
$script = 'app-persistent.php';
$logs = $this->runner->run($script);
$this->checkRestart($logs);
// first sub-process - check not loaded from app-plain
$appName = $this->runner->getAppName('app-plain.php');
$child = $logs->getValuesForProcessName(3, $appName);
$item = $logs->getItemFromList($child, 2);
self::assertStringContainsString('The Xdebug extension is not loaded', $item);
// second sub-process - check loaded from app-plain
$appName = $this->runner->getAppName('app-plain.php');
$child = $logs->getValuesForProcessName(4, $appName);
$item = $logs->getItemFromList($child, 2);
self::assertStringContainsString('The Xdebug extension is loaded', $item);
// third sub-process - check not loaded from app-basic
$child = $logs->getValuesForProcess(5);
$item = $logs->getItemFromList($child, 2);
self::assertStringContainsString('The Xdebug extension is not loaded', $item);
$item = $logs->getItemFromList($child, 3);
self::assertStringContainsString('Process called with existing restart settings', $item);
}
}
|