Skip to content
This repository
Browse code

Display the version number when using PHPUnit from a Composer install…

… or Git checkout. Closes #654.
  • Loading branch information...
commit 25fbf631f944be48722dfcb1454080dfe10fd400 1 parent 47cb3be
Sebastian Bergmann authored

Showing 2 changed files with 25 additions and 2 deletions. Show diff stats Hide diff stats

  1. +5 0 ChangeLog.md
  2. +20 2 PHPUnit/Runner/Version.php
5 ChangeLog.md
Source Rendered
@@ -3,6 +3,11 @@ PHPUnit 3.7
3 3
4 4 This is the list of changes for the PHPUnit 3.7 release series.
5 5
  6 +PHPUnit 3.7.1
  7 +-------------
  8 +
  9 +* The version number is now displayed when using PHPUnit from a Composer install or Git checkout.
  10 +
6 11 PHPUnit 3.7.0
7 12 -------------
8 13
22 PHPUnit/Runner/Version.php
@@ -57,6 +57,9 @@
57 57 */
58 58 class PHPUnit_Runner_Version
59 59 {
  60 + const VERSION = '@package_version@';
  61 + protected static $version;
  62 +
60 63 /**
61 64 * Returns the current version of PHPUnit.
62 65 *
@@ -64,7 +67,22 @@ class PHPUnit_Runner_Version
64 67 */
65 68 public static function id()
66 69 {
67   - return '@package_version@';
  70 + if (self::$version === NULL) {
  71 + if (strpos(self::VERSION, '@package_version') === 0) {
  72 + $dir = getcwd();
  73 + chdir(__DIR__);
  74 + $version = exec('git describe --tags');
  75 + chdir($dir);
  76 +
  77 + if ($version) {
  78 + self::$version = $version;
  79 + }
  80 + } else {
  81 + self::$version = self::VERSION;
  82 + }
  83 + }
  84 +
  85 + return self::$version;
68 86 }
69 87
70 88 /**
@@ -72,6 +90,6 @@ public static function id()
72 90 */
73 91 public static function getVersionString()
74 92 {
75   - return 'PHPUnit @package_version@ by Sebastian Bergmann.';
  93 + return 'PHPUnit ' . self::id() . ' by Sebastian Bergmann.';
76 94 }
77 95 }

0 comments on commit 25fbf63

Please sign in to comment.
Something went wrong with that request. Please try again.