Repository: phpbench/phpbench (php)

Issue:
"PHPBench @git_tag@ running benchmarks" on CLI output
Is it normal to have `@git_tag@` in the CLI output rather than a replacement ?
```
phpMyAdmin$ composer require phpbench/phpbench --dev
Using version ^1.0 for phpbench/phpbench
./composer.json has been updated
Running composer update phpbench/phpbench
Loading composer repositories with package information
Updating dependencies
Lock file operations: 9 installs, 0 updates, 0 removals
  - Locking beberlei/assert (v3.3.0)
  - Locking doctrine/annotations (1.12.1)
  - Locking doctrine/lexer (1.2.1)
  - Locking phpbench/container (2.1.0)
  - Locking phpbench/dom (0.3.0)
  - Locking phpbench/phpbench (1.0.0)
  - Locking seld/jsonlint (1.8.3)
  - Locking symfony/deprecation-contracts (v2.2.0)
  - Locking symfony/options-resolver (v5.2.4)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 9 installs, 0 updates, 0 removals
  - Downloading seld/jsonlint (1.8.3)
  - Downloading phpbench/dom (0.3.0)
  - Downloading phpbench/container (2.1.0)
  - Downloading beberlei/assert (v3.3.0)
  - Downloading phpbench/phpbench (1.0.0)
  - Installing doctrine/lexer (1.2.1): Extracting archive
  - Installing symfony/deprecation-contracts (v2.2.0): Extracting archive
  - Installing symfony/options-resolver (v5.2.4): Extracting archive
  - Installing seld/jsonlint (1.8.3): Extracting archive
  - Installing phpbench/dom (0.3.0): Extracting archive
  - Installing phpbench/container (2.1.0): Extracting archive
  - Installing doctrine/annotations (1.12.1): Extracting archive
  - Installing beberlei/assert (v3.3.0): Extracting archive
  - Installing phpbench/phpbench (1.0.0): Extracting archive
1 package suggestions were added by new dependencies, use `composer suggest` to see details.
Generating autoload files
composer/package-versions-deprecated: Generating version class...
composer/package-versions-deprecated: ...done generating version class
56 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
phpstan/extension-installer: Extensions installed
williamdes@williamdes:/mnt/Dev/@phpmyadmin/theREALphpMyAdminREPO$ composer run phpbench
> phpbench run test/benchmarks --progress=dots
PHPBench @git_tag@ running benchmarks...
with PHP version 7.4.16, xdebug ❌, opcache ❌

.. 

Subjects: 2, Assertions: 0, Failures: 0, Errors: 0
```

Pull request description:
Package versions
Use Package Versions to determine PHPBench version if not using a PHAR, fixes #810 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d97f15b3..64078eec 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,13 @@
 CHANGELOG
 =========
 
+dev-master
+----------
+
+Improvements:
+
+- Use package versions to show PHPBench version if not PHAR
+
 1.0.0-beta1
 -----------
 
diff --git a/composer.json b/composer.json
index 6b1d45f0..f8c01105 100644
--- a/composer.json
+++ b/composer.json
@@ -18,6 +18,7 @@
         "ext-reflection": "*",
         "ext-spl": "*",
         "ext-tokenizer": "*",
+        "composer/package-versions-deprecated": "^1.8",
         "doctrine/annotations": "^1.2.7",
         "phpbench/container": "^2.1",
         "phpbench/dom": "~0.3.0",
diff --git a/lib/Console/Application.php b/lib/Console/Application.php
index 5ef8b5e5..f64c6ebd 100644
--- a/lib/Console/Application.php
+++ b/lib/Console/Application.php
@@ -27,7 +27,7 @@ class Application extends BaseApplication
     {
         parent::__construct(
             'phpbench',
-            PhpBench::VERSION
+            PhpBench::version()
         );
     }
 
diff --git a/lib/PhpBench.php b/lib/PhpBench.php
index b0431846..1664e736 100644
--- a/lib/PhpBench.php
+++ b/lib/PhpBench.php
@@ -12,6 +12,7 @@
 
 namespace PhpBench;
 
+use Composer\InstalledVersions;
 use PhpBench\Console\Application;
 use PhpBench\DependencyInjection\Container;
 use PhpBench\Exception\ConfigurationPreProcessingError;
@@ -37,11 +38,7 @@ use Webmozart\PathUtil\Path;
 class PhpBench
 {
     // PHPBench version: @git_tag@ will be replaced by box.
-    const VERSION = '@git_tag@';
-
-    // URL to phar and version file for self-updating
-    const PHAR_URL = 'https://phpbench.github.io/phpbench/phpbench.phar';
-    const PHAR_VERSION_URL = 'https://phpbench.github.io/phpbench/phpbench.phar.version';
+    public const VERSION = '@git_tag@';
 
     public static function run(?InputInterface $input = null, ?OutputInterface $output = null): void
     {
@@ -253,4 +250,15 @@ class PhpBench
             exit(255);
         });
     }
+
+    public static function version(): string
+    {
+        // do not use the literal `@git_tag@` as it would be replaced by box.
+        if (self::VERSION === '@' . 'git_tag' . '@') {
+            return InstalledVersions::getPrettyVersion('phpbench/phpbench');
+        }
+
+        /** @phpstan-ignore-next-line */
+        return self::VERSION;
+    }
 }
diff --git a/lib/Progress/Logger/PhpBenchLogger.php b/lib/Progress/Logger/PhpBenchLogger.php
index 2d5678dc..a025d627 100644
--- a/lib/Progress/Logger/PhpBenchLogger.php
+++ b/lib/Progress/Logger/PhpBenchLogger.php
@@ -51,7 +51,7 @@ abstract class PhpBenchLogger extends NullLogger
 
     public function startSuite(Suite $suite): void
     {
-        $this->output->writeln('PHPBench ' . PhpBench::VERSION . ' running benchmarks...');
+        $this->output->writeln('PHPBench (' . PhpBench::version() . ') running benchmarks...');
 
         if ($configPath = $suite->getConfigPath()) {
             $this->output->writeln(sprintf('with configuration file: %s', $configPath));
diff --git a/lib/Serializer/XmlEncoder.php b/lib/Serializer/XmlEncoder.php
index 1ad44e23..a0ca673e 100644
--- a/lib/Serializer/XmlEncoder.php
+++ b/lib/Serializer/XmlEncoder.php
@@ -37,7 +37,7 @@ class XmlEncoder
         $dom = new Document();
 
         $rootEl = $dom->createRoot('phpbench');
-        $rootEl->setAttribute('version', PhpBench::VERSION);
+        $rootEl->setAttribute('version', PhpBench::version());
         $rootEl->setAttributeNS(
             'http://www.w3.org/2000/xmlns/',
             'xmlns:xsi',


Test patch:
diff --git a/tests/Unit/Serializer/XmlEncoderTest.php b/tests/Unit/Serializer/XmlEncoderTest.php
index cc5bc9da..19fb72ce 100644
--- a/tests/Unit/Serializer/XmlEncoderTest.php
+++ b/tests/Unit/Serializer/XmlEncoderTest.php
@@ -42,7 +42,7 @@ class XmlEncoderTest extends XmlTestCase
      */
     public function testEncode(array $params, $expected): void
     {
-        $expected = str_replace('PHPBENCH_VERSION', PhpBench::VERSION, $expected);
+        $expected = str_replace('PHPBENCH_VERSION', PhpBench::version(), $expected);
         $collection = $this->getSuiteCollection($params);
         $xmlEncoder = new XmlEncoder();
         $dom = $xmlEncoder->encode($collection);