Skip to content

Commit

Permalink
Fix: Show version of plugin instead of version of application
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 29, 2020
1 parent 4a220a1 commit 8c9dea2
Show file tree
Hide file tree
Showing 25 changed files with 70 additions and 34 deletions.
15 changes: 13 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

For a full diff see [`2.12.0...main`][2.12.0...main].
For a full diff see [`2.12.1...main`][2.12.1...main].

## [`2.12.1`][2.12.1]

For a full diff see [`2.12.0...2.12.1`][2.12.0...2.12.1].

### Fixed

* Show version of plugin instead of version of `Composer\Console\Application` when running as development dependency ([#643]), by [@localheinz]

## [`2.12.0`][2.12.0]

Expand Down Expand Up @@ -510,6 +518,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0].
[2.10.0]: https://github.com/ergebnis/composer-normalize/releases/tag/2.10.0
[2.11.0]: https://github.com/ergebnis/composer-normalize/releases/tag/2.11.0
[2.12.0]: https://github.com/ergebnis/composer-normalize/releases/tag/2.12.0
[2.12.1]: https://github.com/ergebnis/composer-normalize/releases/tag/2.12.1

[81bc3a8...0.1.0]: https://github.com/ergebnis/composer-normalize/compare/81bc3a8...0.1.0
[0.1.0...0.2.0]: https://github.com/ergebnis/composer-normalize/compare/0.1.0...0.2.0
Expand Down Expand Up @@ -558,7 +567,8 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0].
[2.9.1...2.10.0]: https://github.com/ergebnis/composer-normalize/compare/2.9.1...2.10.0
[2.10.0...2.11.0]: https://github.com/ergebnis/composer-normalize/compare/2.10.0...2.11.0
[2.11.0...2.12.0]: https://github.com/ergebnis/composer-normalize/compare/2.11.0...2.12.0
[2.12.0...main]: https://github.com/ergebnis/composer-normalize/compare/2.12.0...main
[2.12.0...2.12.1]: https://github.com/ergebnis/composer-normalize/compare/2.12.0...2.12.1
[2.12.1...main]: https://github.com/ergebnis/composer-normalize/compare/2.12.1...main

[#1]: https://github.com/ergebnis/composer-normalize/pull/1
[#2]: https://github.com/ergebnis/composer-normalize/pull/2
Expand Down Expand Up @@ -631,6 +641,7 @@ For a full diff see [`81bc3a8...0.1.0`][81bc3a8...0.1.0].
[#634]: https://github.com/ergebnis/composer-normalize/pull/634
[#640]: https://github.com/ergebnis/composer-normalize/pull/640
[#641]: https://github.com/ergebnis/composer-normalize/pull/641
[#643]: https://github.com/ergebnis/composer-normalize/pull/643

[@core23]: https://github.com/core23
[@dependabot]: https://github.com/dependabot
Expand Down
3 changes: 2 additions & 1 deletion phar/composer-normalize.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @see https://github.com/ergebnis/composer-normalize
*/

use Composer\Console\Application;
use Composer\Factory;
use Ergebnis\Composer\Normalize;
use Ergebnis\Json\Normalizer;
Expand All @@ -30,7 +31,7 @@
]))
);

$application = new Normalize\Application();
$application = new Application();

$application->add($command);

Expand Down
3 changes: 2 additions & 1 deletion src/Command/NormalizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Composer\Factory;
use Composer\IO;
use Ergebnis\Composer\Normalize\Exception;
use Ergebnis\Composer\Normalize\Version;
use Ergebnis\Json\Normalizer;
use Localheinz\Diff;
use Symfony\Component\Console;
Expand Down Expand Up @@ -107,7 +108,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
$io->write([
\sprintf(
'Running %s.',
$this->getApplication()->getLongVersion()
Version::long()
),
'',
]);
Expand Down
31 changes: 8 additions & 23 deletions src/Application.php → src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,38 @@

namespace Ergebnis\Composer\Normalize;

use Composer\Console;

/**
* @internal
*/
final class Application extends Console\Application
final class Version
{
/**
* @see https://github.com/box-project/box/blob/master/doc/configuration.md#pretty-git-tag-placeholder-git
*
* @var string
*/
private $version = '@git@';
private static $version = '@git@';

public function getLongVersion(): string
public static function long(): string
{
$name = 'ergebnis/composer-normalize';
$attribution = 'by <info>Andreas Möller</info> and contributors';

$version = $this->getVersion();
$version = self::$version;

if ('' === $version) {
if ('@' . 'git@' === $version) {
return \sprintf(
'<info>%s</info> %s',
$this->getName(),
$name,
$attribution
);
}

return \sprintf(
'<info>%s</info> %s %s',
$this->getName(),
$name,
$version,
$attribution
);
}

public function getName(): string
{
return 'ergebnis/composer-normalize';
}

public function getVersion(): string
{
if ('@' . 'git@' === $this->version) {
return '';
}

return $this->version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*
* @covers \Ergebnis\Composer\Normalize\Command\NormalizeCommand
* @covers \Ergebnis\Composer\Normalize\NormalizePlugin
*
* @uses \Ergebnis\Composer\Normalize\Version
*/
final class Test extends Integration\Command\NormalizeCommand\AbstractTestCase
{
Expand Down
12 changes: 5 additions & 7 deletions test/Unit/ApplicationTest.php → test/Unit/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@

namespace Ergebnis\Composer\Normalize\Test\Unit;

use Ergebnis\Composer\Normalize\Application;
use Ergebnis\Composer\Normalize\Version;
use PHPUnit\Framework;

/**
* @internal
*
* @covers \Ergebnis\Composer\Normalize\Application
* @covers \Ergebnis\Composer\Normalize\Version
*/
final class ApplicationTest extends Framework\TestCase
final class VersionTest extends Framework\TestCase
{
public function testGetLongVersionReturnsVersion(): void
public function testLongReturnsVersion(): void
{
$application = new Application();

$expected = '<info>ergebnis/composer-normalize</info> by <info>Andreas Möller</info> and contributors';

self::assertSame($expected, $application->getLongVersion());
self::assertSame($expected, Version::long());
}
}

0 comments on commit 8c9dea2

Please sign in to comment.