93% of 1509OPs |
85% of 363Lines |
77% of 181Branches |
14% of 430Paths |
| # | |
|---|---|
| 1 |
<?php |
| 2 |
|
| 3 |
namespace mageekguy\atoum\scripts; |
| 4 |
|
| 5 |
use |
| 6 |
mageekguy\atoum, |
| 7 |
mageekguy\atoum\exceptions, |
| 8 |
mageekguy\atoum\scripts\phar, |
| 9 |
mageekguy\atoum\scripts\builder |
| 10 |
; |
| 11 |
|
| 12 |
class builder extends atoum\script\configurable |
| 13 |
{
|
| 14 |
const defaultConfigFile = '.builder.php'; |
| 15 |
const defaultUnitTestRunnerScript = 'scripts/runner.php'; |
| 16 |
const defaultPharGeneratorScript = 'scripts/phar/generator.php'; |
| 17 |
|
| 18 |
protected $php = null; |
| 19 |
protected $vcs = null; |
| 20 |
protected $taggerEngine = null; |
| 21 |
protected $revision = null; |
| 22 |
protected $version = null; |
| 23 |
protected $unitTestRunnerScript = null; |
| 24 |
protected $pharGeneratorScript = null; |
| 25 |
protected $workingDirectory = null; |
| 26 |
protected $destinationDirectory = null; |
| 27 |
protected $scoreDirectory = null; |
| 28 |
protected $errorsDirectory = null; |
| 29 |
protected $revisionFile = null; |
| 30 |
protected $runFile = null; |
| 31 |
protected $pharCreationEnabled = true; |
| 32 |
protected $checkUnitTests = true; |
| 33 |
protected $reportTitle = null; |
| 34 |
protected $runnerConfigurationFiles = array(); |
| 35 |
|
| 36 |
public function __construct($name, atoum\adapter $adapter = null)100% |
| 37 |
{
|
| 38 |
parent::__construct($name, $adapter); |
| 39 |
|
| 40 |
$this |
| 41 |
->setVcs() |
| 42 |
->setPhp() |
| 43 |
->setUnitTestRunnerScript(self::defaultUnitTestRunnerScript) |
| 44 |
->setPharGeneratorScript(self::defaultPharGeneratorScript) |
| 45 |
; |
| 46 |
} |
| 47 |
|
| 48 |
public function setVcs(builder\vcs $vcs = null)100% |
| 49 |
{
|
| 50 |
$this->vcs = $vcs ?: new builder\vcs\svn(); |
| 51 |
|
| 52 |
return $this; |
| 53 |
} |
| 54 |
|
| 55 |
public function getVcs()100% |
| 56 |
{
|
| 57 |
return $this->vcs; |
| 58 |
} |
| 59 |
|
| 60 |
public function setTaggerEngine(atoum\scripts\tagger\engine $engine)100% |
| 61 |
{
|
| 62 |
$this->taggerEngine = $engine; |
| 63 |
|
| 64 |
return $this; |
| 65 |
} |
| 66 |
|
| 67 |
public function getTaggerEngine()100% |
| 68 |
{
|
| 69 |
return $this->taggerEngine; |
| 70 |
} |
| 71 |
|
| 72 |
public function setPhp(atoum\php $php = null) |
| 73 |
{
|
| 74 |
$this->php = $php ?: new atoum\php(); |
| 75 |
|
| 76 |
return $this; |
| 77 |
} |
| 78 |
|
| 79 |
public function getPhp()100% |
| 80 |
{
|
| 81 |
return $this->php; |
| 82 |
} |
| 83 |
|
| 84 |
public function setPhpPath($path)100% |
| 85 |
{
|
| 86 |
$this->php->setBinaryPath($path); |
| 87 |
|
| 88 |
return $this; |
| 89 |
} |
| 90 |
|
| 91 |
public function getPhpPath() |
| 92 |
{
|
| 93 |
return $this->php->getBinaryPath(); |
| 94 |
} |
| 95 |
|
| 96 |
public function getRunnerConfigurationFiles()100% |
| 97 |
{
|
| 98 |
return $this->runnerConfigurationFiles; |
| 99 |
} |
| 100 |
|
| 101 |
public function addRunnerConfigurationFile($file)100% |
| 102 |
{
|
| 103 |
$this->runnerConfigurationFiles[] = (string) $file; |
| 104 |
|
| 105 |
return $this; |
| 106 |
} |
| 107 |
|
| 108 |
public function enablePharCreation()100% |
| 109 |
{
|
| 110 |
$this->pharCreationEnabled = true; |
| 111 |
|
| 112 |
return $this; |
| 113 |
} |
| 114 |
|
| 115 |
public function disablePharCreation()100% |
| 116 |
{
|
| 117 |
$this->pharCreationEnabled = false; |
| 118 |
|
| 119 |
return $this; |
| 120 |
} |
| 121 |
|
| 122 |
public function pharCreationIsEnabled()100% |
| 123 |
{
|
| 124 |
return $this->pharCreationEnabled; |
| 125 |
} |
| 126 |
|
| 127 |
public function disableUnitTestChecking()100% |
| 128 |
{
|
| 129 |
$this->checkUnitTests = false; |
| 130 |
|
| 131 |
return $this; |
| 132 |
} |
| 133 |
|
| 134 |
public function enableUnitTestChecking()100% |
| 135 |
{
|
| 136 |
$this->checkUnitTests = true; |
| 137 |
|
| 138 |
return $this; |
| 139 |
} |
| 140 |
|
| 141 |
public function unitTestCheckingIsEnabled()100% |
| 142 |
{
|
| 143 |
return $this->checkUnitTests; |
| 144 |
} |
| 145 |
|
| 146 |
public function setVersion($version)100% |
| 147 |
{
|
| 148 |
$this->version = (string) $version; |
| 149 |
|
| 150 |
return $this; |
| 151 |
} |
| 152 |
|
| 153 |
public function getVersion()100% |
| 154 |
{
|
| 155 |
return $this->version; |
| 156 |
} |
| 157 |
|
| 158 |
public function setScoreDirectory($path)100% |
| 159 |
{
|
| 160 |
$this->scoreDirectory = static::cleanDirectoryPath($path); |
| 161 |
|
| 162 |
return $this; |
| 163 |
} |
| 164 |
|
| 165 |
public function getScoreDirectory()100% |
| 166 |
{
|
| 167 |
return $this->scoreDirectory; |
| 168 |
} |
| 169 |
|
| 170 |
public function setErrorsDirectory($path)100% |
| 171 |
{
|
| 172 |
$this->errorsDirectory = static::cleanDirectoryPath($path); |
| 173 |
|
| 174 |
return $this; |
| 175 |
} |
| 176 |
|
| 177 |
public function getErrorsDirectory()100% |
| 178 |
{
|
| 179 |
return $this->errorsDirectory; |
| 180 |
} |
| 181 |
|
| 182 |
public function setDestinationDirectory($path)100% |
| 183 |
{
|
| 184 |
$this->destinationDirectory = static::cleanDirectoryPath($path); |
| 185 |
|
| 186 |
return $this; |
| 187 |
} |
| 188 |
|
| 189 |
public function getDestinationDirectory()100% |
| 190 |
{
|
| 191 |
return $this->destinationDirectory; |
| 192 |
} |
| 193 |
|
| 194 |
public function setWorkingDirectory($path)100% |
| 195 |
{
|
| 196 |
$this->workingDirectory = static::cleanDirectoryPath($path); |
| 197 |
|
| 198 |
return $this; |
| 199 |
} |
| 200 |
|
| 201 |
public function getWorkingDirectory()100% |
| 202 |
{
|
| 203 |
return $this->workingDirectory; |
| 204 |
} |
| 205 |
|
| 206 |
public function setRevisionFile($path)100% |
| 207 |
{
|
| 208 |
$this->revisionFile = (string) $path; |
| 209 |
|
| 210 |
return $this; |
| 211 |
} |
| 212 |
|
| 213 |
public function getRevisionFile()100% |
| 214 |
{
|
| 215 |
return $this->revisionFile; |
| 216 |
} |
| 217 |
|
| 218 |
public function setReportTitle($title)100% |
| 219 |
{
|
| 220 |
$this->reportTitle = (string) $title; |
| 221 |
|
| 222 |
return $this; |
| 223 |
} |
| 224 |
|
| 225 |
public function getReportTitle()100% |
| 226 |
{
|
| 227 |
return $this->reportTitle; |
| 228 |
} |
| 229 |
|
| 230 |
public function setUnitTestRunnerScript($path)100% |
| 231 |
{
|
| 232 |
$this->unitTestRunnerScript = (string) $path; |
| 233 |
|
| 234 |
return $this; |
| 235 |
} |
| 236 |
|
| 237 |
public function getUnitTestRunnerScript() |
| 238 |
{
|
| 239 |
return $this->unitTestRunnerScript; |
| 240 |
} |
| 241 |
|
| 242 |
public function setPharGeneratorScript($path)100% |
| 243 |
{
|
| 244 |
$this->pharGeneratorScript = (string) $path; |
| 245 |
|
| 246 |
return $this; |
| 247 |
} |
| 248 |
|
| 249 |
public function getPharGeneratorScript()100% |
| 250 |
{
|
| 251 |
return $this->pharGeneratorScript; |
| 252 |
} |
| 253 |
|
| 254 |
public function setRunFile($path)100% |
| 255 |
{
|
| 256 |
$this->runFile = $path; |
| 257 |
|
| 258 |
return $this; |
| 259 |
} |
| 260 |
|
| 261 |
public function getRunFile()100% |
| 262 |
{
|
| 263 |
return $this->runFile !== null ? $this->runFile : $this->adapter->sys_get_temp_dir() . \DIRECTORY_SEPARATOR . md5(get_class($this)); |
| 264 |
} |
| 265 |
|
| 266 |
public function checkUnitTests()100% |
| 267 |
{
|
| 268 |
$status = true; |
| 269 |
|
| 270 |
if ($this->checkUnitTests === true) |
| 271 |
{
|
| 272 |
if ($this->workingDirectory === null) |
| 273 |
{
|
| 274 |
throw new exceptions\logic('Unable to check unit tests, working directory is undefined');
|
| 275 |
} |
| 276 |
|
| 277 |
$this->vcs |
| 278 |
->setWorkingDirectory($this->workingDirectory) |
| 279 |
->exportRepository() |
| 280 |
; |
| 281 |
|
| 282 |
$this->php |
| 283 |
->reset() |
| 284 |
->addOption('-f', $this->workingDirectory . \DIRECTORY_SEPARATOR . $this->unitTestRunnerScript)
|
| 285 |
->addArgument('-ncc')
|
| 286 |
->addArgument('-d', $this->workingDirectory . \DIRECTORY_SEPARATOR . 'tests' . \DIRECTORY_SEPARATOR . 'units' . \DIRECTORY_SEPARATOR . 'classes')
|
| 287 |
->addArgument('-p', $this->php->getBinaryPath())
|
| 288 |
; |
| 289 |
|
| 290 |
$scoreFile = $this->scoreDirectory === null ? $this->adapter->tempnam($this->adapter->sys_get_temp_dir(), '') : $this->scoreDirectory . DIRECTORY_SEPARATOR . $this->vcs->getRevision(); |
| 291 |
|
| 292 |
$this->php->addArgument('-sf', $scoreFile);
|
| 293 |
|
| 294 |
if ($this->reportTitle !== null) |
| 295 |
{
|
| 296 |
$this->php->addArgument('-drt', sprintf($this->reportTitle, '%1$s', '%2$s', '%3$s', $this->vcs->getRevision()));
|
| 297 |
} |
| 298 |
|
| 299 |
foreach ($this->runnerConfigurationFiles as $runnerConfigurationFile) |
| 300 |
{
|
| 301 |
$this->php->addArgument('-c', $runnerConfigurationFile);
|
| 302 |
} |
| 303 |
|
| 304 |
try |
| 305 |
{
|
| 306 |
$exitCode = $this->php->run()->getExitCode(); |
| 307 |
|
| 308 |
if ($exitCode > 0) |
| 309 |
{
|
| 310 |
switch ($exitCode) |
| 311 |
{
|
| 312 |
case 126: |
| 313 |
case 127: |
| 314 |
throw new exceptions\runtime('Unable to find \'' . $this->php->getBinaryPath() . '\' or it is not executable');
|
| 315 |
|
| 316 |
default: |
| 317 |
throw new exceptions\runtime($this->php . ' failed with exit code \'' . $exitCode . '\': ' . $this->php->getStderr()); |
| 318 |
} |
| 319 |
} |
| 320 |
|
| 321 |
$stdErr = $this->php->getStdErr(); |
| 322 |
|
| 323 |
if ($stdErr != '') |
| 324 |
{
|
| 325 |
throw new exceptions\runtime($stdErr); |
| 326 |
} |
| 327 |
|
| 328 |
$score = @$this->adapter->file_get_contents($scoreFile); |
| 329 |
|
| 330 |
if ($score === false) |
| 331 |
{
|
| 332 |
throw new exceptions\runtime('Unable to read score from file \'' . $scoreFile . '\'');
|
| 333 |
} |
| 334 |
|
| 335 |
$score = $this->adapter->unserialize($score); |
| 336 |
|
| 337 |
if ($score === false) |
| 338 |
{
|
| 339 |
throw new exceptions\runtime('Unable to unserialize score from file \'' . $scoreFile . '\'');
|
| 340 |
} |
| 341 |
|
| 342 |
if ($score instanceof atoum\score === false) |
| 343 |
{
|
| 344 |
throw new exceptions\runtime('Contents of file \'' . $scoreFile . '\' is not a score');
|
| 345 |
} |
| 346 |
|
| 347 |
$status = $score->getFailNumber() === 0 && $score->getExceptionNumber() === 0 && $score->getErrorNumber() === 0; |
| 348 |
} |
| 349 |
catch (\exception $exception) |
| 350 |
{
|
| 351 |
$this->writeErrorInErrorsDirectory($exception->getMessage()); |
| 352 |
|
| 353 |
$status = false; |
| 354 |
} |
| 355 |
|
| 356 |
if ($this->scoreDirectory === null) |
| 357 |
{
|
| 358 |
if ($this->adapter->unlink($scoreFile) === false) |
| 359 |
{
|
| 360 |
throw new exceptions\runtime('Unable to delete score file \'' . $scoreFile . '\'');
|
| 361 |
} |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
return $status; |
| 366 |
} |
| 367 |
|
| 368 |
public function createPhar($version = null)100% |
| 369 |
{
|
| 370 |
$pharBuilt = true; |
| 371 |
|
| 372 |
if ($this->pharCreationEnabled === true) |
| 373 |
{
|
| 374 |
if ($this->destinationDirectory === null) |
| 375 |
{
|
| 376 |
throw new exceptions\logic('Unable to create phar, destination directory is undefined');
|
| 377 |
} |
| 378 |
|
| 379 |
if ($this->workingDirectory === null) |
| 380 |
{
|
| 381 |
throw new exceptions\logic('Unable to create phar, working directory is undefined');
|
| 382 |
} |
| 383 |
|
| 384 |
if ($this->revisionFile !== null) |
| 385 |
{
|
| 386 |
$revision = trim(@$this->adapter->file_get_contents($this->revisionFile)); |
| 387 |
|
| 388 |
if (is_numeric($revision) === true) |
| 389 |
{
|
| 390 |
$this->vcs->setRevision($revision); |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
$revisions = $this->vcs->getNextRevisions(); |
| 395 |
|
| 396 |
while (sizeof($revisions) > 0) |
| 397 |
{
|
| 398 |
$revision = array_shift($revisions); |
| 399 |
|
| 400 |
$this->vcs->setRevision($revision); |
| 401 |
|
| 402 |
try |
| 403 |
{
|
| 404 |
if ($this->checkUnitTests() === true) |
| 405 |
{
|
| 406 |
if ($this->checkUnitTests === false) |
| 407 |
{
|
| 408 |
$this->vcs |
| 409 |
->setWorkingDirectory($this->workingDirectory) |
| 410 |
->exportRepository() |
| 411 |
; |
| 412 |
} |
| 413 |
|
| 414 |
if ($this->taggerEngine !== null) |
| 415 |
{
|
| 416 |
$this->taggerEngine |
| 417 |
->setSrcDirectory($this->workingDirectory) |
| 418 |
->setVersion($version !== null ? $version : 'nightly-' . $revision . '-' . $this->adapter->date('YmdHi'))
|
| 419 |
->tagVersion() |
| 420 |
; |
| 421 |
} |
| 422 |
|
| 423 |
$this->php |
| 424 |
->reset() |
| 425 |
->addOption('-d', 'phar.readonly=0')
|
| 426 |
->addOption('-f', $this->workingDirectory . DIRECTORY_SEPARATOR . $this->pharGeneratorScript)
|
| 427 |
->addArgument('-d', $this->destinationDirectory)
|
| 428 |
; |
| 429 |
|
| 430 |
if ($this->php->run()->getExitCode() > 0) |
| 431 |
{
|
| 432 |
throw new exceptions\runtime('Unable to run ' . $this->php . ': ' . $this->php->getStdErr());
|
| 433 |
} |
| 434 |
} |
| 435 |
} |
| 436 |
catch (\exception $exception) |
| 437 |
{
|
| 438 |
$pharBuilt = false; |
| 439 |
|
| 440 |
$this->writeErrorInErrorsDirectory($exception->getMessage()); |
| 441 |
} |
| 442 |
|
| 443 |
if ($this->revisionFile !== null && $this->adapter->file_put_contents($this->revisionFile, $revision, \LOCK_EX) === false) |
| 444 |
{
|
| 445 |
throw new exceptions\runtime('Unable to save last revision in file \'' . $this->revisionFile . '\'');
|
| 446 |
} |
| 447 |
|
| 448 |
$revisions = $this->vcs->getNextRevisions(); |
| 449 |
} |
| 450 |
} |
| 451 | |
| 452 |
return $pharBuilt; |
| 453 |
} |
| 454 |
|
| 455 |
public function writeErrorInErrorsDirectory($error)100% |
| 456 |
{
|
| 457 |
if ($this->errorsDirectory !== null) |
| 458 |
{
|
| 459 |
$revision = $this->vcs === null ? null : $this->vcs->getRevision(); |
| 460 |
|
| 461 |
if ($revision === null) |
| 462 |
{
|
| 463 |
throw new exceptions\logic('Revision is undefined');
|
| 464 |
} |
| 465 |
|
| 466 |
$errorFile = $this->errorsDirectory . \DIRECTORY_SEPARATOR . $revision; |
| 467 |
|
| 468 |
if ($this->adapter->file_put_contents($errorFile, $error, \LOCK_EX | \FILE_APPEND) === false) |
| 469 |
{
|
| 470 |
throw new exceptions\runtime('Unable to save error in file \'' . $errorFile . '\'');
|
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
return $this; |
| 475 |
} |
| 476 |
|
| 477 |
protected function includeConfigFile($path, \closure $callback = null)100% |
| 478 |
{
|
| 479 |
if ($callback === null) |
| 480 |
{
|
| 481 |
$builder = $this; |
| 482 |
|
| 483 |
$callback = function($path) use ($builder) { include_once($path); };
|
| 484 |
} |
| 485 |
|
| 486 |
return parent::includeConfigFile($path, $callback); |
| 487 |
} |
| 488 |
|
| 489 |
protected function setArgumentHandlers()62% |
| 490 |
{
|
| 491 |
$builder = $this; |
| 492 |
|
| 493 |
return parent::setArgumentHandlers() |
| 494 |
->addArgumentHandler( |
| 495 |
function($script, $argument, $files) use ($builder) {
|
| 496 |
if (sizeof($files) <= 0) |
| 497 |
{
|
| 498 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
|
| 499 |
} |
| 500 |
|
| 501 |
foreach ($files as $file) |
| 502 |
{
|
| 503 |
if (file_exists($file) === false) |
| 504 |
{
|
| 505 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Runner configuration file path \'%s\' is invalid'), $file));
|
| 506 |
} |
| 507 |
|
| 508 |
if (is_readable($file) === false) |
| 509 |
{
|
| 510 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Unable to read runner configuration file \'%s\''), $file));
|
| 511 |
} |
| 512 |
|
| 513 |
$script->addRunnerConfigurationFile($file); |
| 514 |
} |
| 515 |
}, |
| 516 |
array('-rc', '--runner-configuration-files'),
|
| 517 |
'<file>', |
| 518 |
$this->locale->_('Use <file> as configuration file for runner')
|
| 519 |
) |
| 520 |
->addArgumentHandler( |
| 521 |
function($script, $argument, $path) {
|
| 522 |
if (sizeof($path) != 1) |
| 523 |
{
|
| 524 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
|
| 525 |
} |
| 526 | |
| 527 |
$script->setPhpPath(current($path)); |
| 528 |
}, |
| 529 |
array('-p', '--php'),
|
| 530 |
'<path>', |
| 531 |
$this->locale->_('Path to PHP binary')
|
| 532 |
) |
| 533 |
->addArgumentHandler( |
| 534 |
function($script, $argument, $directory) {
|
| 535 |
if (sizeof($directory) != 1) |
| 536 |
{
|
| 537 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
|
| 538 |
} |
| 539 |
|
| 540 |
$script->setWorkingDirectory(current($directory)); |
| 541 |
}, |
| 542 |
array('-w', '--working-directory'),
|
| 543 |
'<directory>', |
| 544 |
$this->locale->_('Checkout file from repository in <directory>')
|
| 545 |
) |
| 546 |
->addArgumentHandler( |
| 547 |
function($script, $argument, $directory) {
|
| 548 |
if (sizeof($directory) != 1) |
| 549 |
{
|
| 550 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
|
| 551 |
} |
| 552 |
|
| 553 |
$script->setDestinationDirectory(current($directory)); |
| 554 |
}, |
| 555 |
array('-d', '--destination-directory'),
|
| 556 |
'<directory>', |
| 557 |
$this->locale->_('Save phar in <directory>')
|
| 558 |
|
| 559 |
) |
| 560 |
->addArgumentHandler( |
| 561 |
function($script, $argument, $directory) {
|
| 562 |
if (sizeof($directory) != 1) |
| 563 |
{
|
| 564 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
|
| 565 |
} |
| 566 |
|
| 567 |
$script->setScoreDirectory(current($directory)); |
| 568 |
}, |
| 569 |
array('-sd', '--score-directory'),
|
| 570 |
'<directory>', |
| 571 |
$this->locale->_('Save score in <directory>')
|
| 572 |
) |
| 573 |
->addArgumentHandler( |
| 574 |
function($script, $argument, $directory) {
|
| 575 |
if (sizeof($directory) != 1) |
| 576 |
{
|
| 577 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
|
| 578 |
} |
| 579 |
|
| 580 |
$script->setErrorsDirectory(current($directory)); |
| 581 |
}, |
| 582 |
array('-ed', '--errors-directory'),
|
| 583 |
'<directory>', |
| 584 |
$this->locale->_('Save errors in <directory>')
|
| 585 |
) |
| 586 |
->addArgumentHandler( |
| 587 |
function($script, $argument, $url) {
|
| 588 |
if (sizeof($url) != 1) |
| 589 |
{
|
| 590 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
|
| 591 |
} |
| 592 |
|
| 593 |
$script->getVcs()->setRepositoryUrl(current($url)); |
| 594 |
}, |
| 595 |
array('-r', '--repository-url'),
|
| 596 |
'<url>', |
| 597 |
$this->locale->_('Url of repository')
|
| 598 |
) |
| 599 |
->addArgumentHandler( |
| 600 |
function($script, $argument, $file) {
|
| 601 |
if (sizeof($file) != 1) |
| 602 |
{
|
| 603 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
|
| 604 |
} |
| 605 |
|
| 606 |
$script->setRevisionFile(current($file)); |
| 607 |
}, |
| 608 |
array('-rf', '--revision-file'),
|
| 609 |
'<file>', |
| 610 |
$this->locale->_('Save last revision in <file>')
|
| 611 |
) |
| 612 |
->addArgumentHandler( |
| 613 |
function($script, $argument, $version) {
|
| 614 |
if (sizeof($version) != 1) |
| 615 |
{
|
| 616 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
|
| 617 |
} |
| 618 |
|
| 619 |
$script->setVersion(current($version)); |
| 620 |
}, |
| 621 |
array('-v', '--version'),
|
| 622 |
'<string>', |
| 623 |
$this->locale->_('Version <string> will be used as version name')
|
| 624 |
) |
| 625 |
->addArgumentHandler( |
| 626 |
function($script, $argument, $unitTestRunnerScript) {
|
| 627 |
if (sizeof($unitTestRunnerScript) != 1) |
| 628 |
{
|
| 629 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
|
| 630 |
} |
| 631 |
|
| 632 |
$script->setUnitTestRunnerScript(current($unitTestRunnerScript)); |
| 633 |
}, |
| 634 |
array('-utrs', '--unit-test-runner-script')
|
| 635 |
) |
| 636 |
->addArgumentHandler( |
| 637 |
function($script, $argument, $pharGeneratorScript) {
|
| 638 |
if (sizeof($pharGeneratorScript) != 1) |
| 639 |
{
|
| 640 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
|
| 641 |
} |
| 642 |
|
| 643 |
$script->setPharGeneratorScript(current($pharGeneratorScript)); |
| 644 |
}, |
| 645 |
array('-pgs', '--phar-generator-script')
|
| 646 |
) |
| 647 |
->addArgumentHandler( |
| 648 |
function($script, $argument, $reportTitle) {
|
| 649 |
if (sizeof($reportTitle) != 1) |
| 650 |
{
|
| 651 |
throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
|
| 652 |
} |
| 653 |
|
| 654 |
$script->setReportTitle(current($reportTitle)); |
| 655 |
}, |
| 656 |
array('-rt', '--report-title')
|
| 657 |
) |
| 658 |
; |
| 659 |
} |
| 660 |
|
| 661 |
protected function doRun()90% |
| 662 |
{
|
| 663 |
$runFile = $this->getRunFile(); |
| 664 |
|
| 665 |
$pid = trim(@$this->adapter->file_get_contents($runFile)); |
| 666 |
|
| 667 |
if (is_numeric($pid) === false || $this->adapter->posix_kill($pid, 0) === false) |
| 668 |
{
|
| 669 |
if ($this->pharCreationEnabled === true) |
| 670 |
{
|
| 671 |
$runFileResource = @$this->adapter->fopen($runFile, 'w+'); |
| 672 |
|
| 673 |
if ($runFileResource === false) |
| 674 |
{
|
| 675 |
throw new exceptions\runtime(sprintf($this->locale->_('Unable to open run file \'%s\''), $runFile));
|
| 676 |
} |
| 677 |
|
| 678 |
if ($this->adapter->flock($runFileResource, \LOCK_EX | \LOCK_NB) === false) |
| 679 |
{
|
| 680 |
throw new exceptions\runtime(sprintf($this->locale->_('Unable to get exclusive lock on run file \'%s\''), $runFile));
|
| 681 |
} |
| 682 |
|
| 683 |
$this->adapter->fwrite($runFileResource, $this->adapter->getmypid()); |
| 684 |
|
| 685 |
$this->createPhar($this->version); |
| 686 |
|
| 687 |
$this->adapter->fclose($runFileResource); |
| 688 |
|
| 689 |
@$this->adapter->unlink($runFile); |
| 690 |
} |
| 691 |
} |
| 692 |
|
| 693 |
return $this; |
| 694 |
} |
| 695 |
|
| 696 |
protected function cleanDirectoryPath($path)100% |
| 697 |
{
|
| 698 |
return rtrim($path, DIRECTORY_SEPARATOR); |
| 699 |
} |
| 700 |
} |