Overriding "@package_version@" in PHPUnit output when installing from Git repo
I added PHPUnit to a project via git submodule add
per the instructions in this blog post. Everything is working开发者_如何学Go beautifully, except the output at the top of each execution looks like this:
PHPUnit @package_version@ by Sebastian Bergmann.
It looks like PEAR replaces that value with the version number during its install process, which doesn't help me much since I'm using Git to install the files.
Has anyone encountered this issue, and how did you solve/work around it?
You pretty answered everything in the question. It's not a bug, it's a feature - the string @package_version@ is a placeholder that is replaced upon installing the package via PEAR.
Since you are using a version intended for development (repo clone from GitHub), you should be ready for issues like this.
If you want there some specific version instead, install this specific version via PEAR.
I can think of some post-checkout hook that would replace the string with revision sha1 hash, but that wouldn't be much useful.
So, in one sentence - it's intended to be this way.
It looks like this is no longer necessary. From PHPUnit 3.7.1's changelog:
The version number is now displayed when using PHPUnit from a Composer install or Git checkout.
As it happens, the project I'm working on is going to be distributed via PEAR, so I'll just list PHPUnit as a dependency in the package.xml file. This will also allow the user some flexibility as to which version of PHPUnit she'd like to run her tests with.
This is my workaround, and yes it's not super-clean ;)
I have edited my phpunit file, don't forget to replace with your own paths :
#!/usr/bin/env php
<?php
while (substr(getcwd(), -3) != "Project_Folder") chdir('../');
if (in_array('--version', $argv)) {
echo 'PHPUnit 3.6.0 by Sebastian Bergmann.';
return;
}
// set main method
define('PHPUnit_MAIN_METHOD','PHPUnit_TextUI_Command::main');
// add phpunit to the include path
$paths = scandir('./var/lib/phpunit');
$includes = array();
foreach($paths as $path){
if (!preg_match('/^\./', $path)){
$includes[] = './var/lib/phpunit/' . $path;
}
}
set_include_path(implode(PATH_SEPARATOR,$includes).PATH_SEPARATOR.get_include_path());
// set the auto loader
require 'PHPUnit/Autoload.php';
// execute
PHPUnit_TextUI_Command::main();
精彩评论