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
|
<?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.
*/
namespace Composer\XdebugHandler;
use Composer\XdebugHandler\Helpers\BaseTestCase;
use Composer\XdebugHandler\Mocks\CoreMock;
use Composer\XdebugHandler\Mocks\FailMock;
use Composer\XdebugHandler\Mocks\PartialMock;
use Composer\XdebugHandler\Mocks\RequiredMock;
/**
* We use PHP_BINARY which only became available in PHP 5.4
*
* @requires PHP 5.4
*/
class RestartTest extends BaseTestCase
{
public function testRestartWhenLoaded()
{
$loaded = true;
$this->setArgv();
$xdebug = CoreMock::createAndCheck($loaded);
$this->checkRestart($xdebug);
// Check command
$xdebug = PartialMock::createAndCheck($loaded);
$command = $xdebug->getCommand();
$n = Process::escape('-n');
$c = Process::escape('-c');
$tmpIni = Process::escape($xdebug->getTmpIni());
$pattern = preg_quote(sprintf('%s %s %s', $n, $c, $tmpIni), '/');
$this->assertRegExp('/'.$pattern.'/', $command);
}
public function testNoRestartWhenNotLoaded()
{
$loaded = false;
$xdebug = CoreMock::createAndCheck($loaded);
$this->checkNoRestart($xdebug);
}
public function testNoRestartWhenLoadedAndAllowed()
{
$loaded = true;
putenv(CoreMock::ALLOW_XDEBUG.'=1');
$xdebug = CoreMock::createAndCheck($loaded);
$this->checkNoRestart($xdebug);
}
public function testFailedRestart()
{
$loaded = true;
$xdebug = FailMock::createAndCheck($loaded);
$this->checkRestart($xdebug);
}
/**
* @dataProvider unreachableScriptProvider
*/
public function testNoRestartWithUnreachableScript($script)
{
$loaded = true;
// We can only check this by setting a script
$settings = array('setMainScript' => array($script));
$xdebug = CoreMock::createAndCheck($loaded, null, $settings);
$this->checkNoRestart($xdebug);
}
public function unreachableScriptProvider()
{
return array(
array('nonexistent.php'),
array('-'),
array('Standard input code'),
);
}
/**
* @dataProvider scriptSetterProvider
*/
public function testRestartWithScriptSetter($script)
{
$loaded = true;
$this->setArgv();
$settings = array('setMainScript' => array($script));
$xdebug = CoreMock::createAndCheck($loaded, null, $settings);
$this->checkRestart($xdebug);
// Check command
$xdebug = PartialMock::createAndCheck($loaded, null, $settings);
$command = $xdebug->getCommand();
$pattern = preg_quote(Process::escape($script), '/');
$this->assertRegExp('/'.$pattern.'/', $command);
}
public function scriptSetterProvider()
{
return array(
array(realpath($_SERVER['argv'][0])),
array('--'),
);
}
public function testSetPersistent()
{
$loaded = true;
$this->setArgv();
$settings = array('setPersistent' => array());
// Check command
$xdebug = PartialMock::createAndCheck($loaded, null, $settings);
$command = $xdebug->getCommand();
$tmpIni = $xdebug->getTmpIni();
foreach (array('-n', '-c', $tmpIni) as $param) {
$pattern = preg_quote(Process::escape($param), '/');
$matched = (bool) preg_match('/'.$pattern.'/', $command);
$this->assertFalse($matched);
}
}
public function testNoRestartWhenNotRequired()
{
$loaded = true;
$required = false;
$xdebug = RequiredMock::runCoreMock($loaded, $required);
$this->checkNoRestart($xdebug);
}
public function testNoRestartWhenRequiredAndAllowed()
{
$loaded = true;
putenv(CoreMock::ALLOW_XDEBUG.'=1');
$required = true;
$xdebug = RequiredMock::runCoreMock($loaded, $required);
$this->checkNoRestart($xdebug);
}
/**
* Sets $_SERVER['argv'] for testing commands
*/
private function setArgv()
{
$_SERVER['argv'] = array(__FILE__, 'command', '--param1, --param2');
}
}
|