generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Implement Markdown\VersionCollector
- Loading branch information
1 parent
d074fbc
commit c51f26d
Showing
8 changed files
with
243 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2024 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/keep-a-changelog | ||
*/ | ||
|
||
namespace Ergebnis\KeepAChangelog\Markdown; | ||
|
||
use Ergebnis\Version; | ||
|
||
final class VersionCollector | ||
{ | ||
/** | ||
* @return list<Version\Version> | ||
*/ | ||
public function collect(string $content): array | ||
{ | ||
$versions = []; | ||
|
||
foreach (\explode("\n", $content) as $line) { | ||
if (0 === \preg_match('/^## \[`(?P<version>[^`]+)`\]/', $line, $matches)) { | ||
continue; | ||
} | ||
|
||
try { | ||
$version = Version\Version::fromString($matches['version']); | ||
} catch (Version\Exception\InvalidVersion $exception) { | ||
continue; | ||
} | ||
|
||
$versions[] = $version; | ||
} | ||
|
||
\usort($versions, static function (Version\Version $a, Version\Version $b): int { | ||
return $a->compare($b); | ||
}); | ||
|
||
return $versions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## Unreleased | ||
|
||
For a full diff see [`1.1.0...main`][1.1.0...main]. | ||
|
||
## [`1.1.0`][1.1.0] | ||
|
||
For a full diff see [`1.0.0...1.1.0`][1.0.0...1.1.0]. | ||
|
||
### Added | ||
|
||
- Added support for PHP 8.0 ([#77]), by [@localheinz] | ||
- Added support for PHP 7.4 ([#78]), by [@localheinz] | ||
|
||
## [`1.0.0`][1.0.0] | ||
|
||
For a full diff see [`64ced12...1.0.0`][64ced12...1.0.0]. | ||
|
||
### Added | ||
|
||
- Added `Version` as a value object ([#1]), by [@localheinz] | ||
- Added `Major` as a value object ([#3]), by [@localheinz] | ||
- Added `Minor` as a value object ([#4]), by [@localheinz] | ||
- Added `Patch` as a value object ([#5]), by [@localheinz] | ||
- Added `PreRelease` as a value object ([#8]), by [@localheinz] | ||
- Added `BuildMetaData` as a value object ([#9]), by [@localheinz] | ||
|
||
[1.0.0]: https://github.com/ergebnis/version/releases/tag/1.0.0 | ||
[1.1.0]: https://github.com/ergebnis/version/releases/tag/1.1.0 | ||
|
||
[64ced12...1.0.0]: https://github.com/ergebnis/version/compare/64ced12...1.0.0 | ||
[1.0.0...1.1.0]: https://github.com/ergebnis/version/compare/1.0.0...1.1.0 | ||
[1.1.0...main]: https://github.com/ergebnis/version/compare/1.1.0...main | ||
|
||
[#1]: https://github.com/ergebnis/version/pull/1 | ||
[#3]: https://github.com/ergebnis/version/pull/3 | ||
[#4]: https://github.com/ergebnis/version/pull/4 | ||
[#5]: https://github.com/ergebnis/version/pull/5 | ||
[#8]: https://github.com/ergebnis/version/pull/8 | ||
[#9]: https://github.com/ergebnis/version/pull/9 | ||
[#77]: https://github.com/ergebnis/version/pull/77 | ||
|
||
[@localheinz]: https://github.com/localheinz |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2024 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/keep-a-changelog | ||
*/ | ||
|
||
namespace Ergebnis\KeepAChangelog\Test\Unit\Markdown; | ||
|
||
use Ergebnis\KeepAChangelog\Markdown; | ||
use Ergebnis\KeepAChangelog\Test; | ||
use Ergebnis\Version; | ||
use PHPUnit\Framework; | ||
|
||
/** | ||
* @covers \Ergebnis\KeepAChangelog\Markdown\VersionCollector | ||
*/ | ||
final class VersionCollectorTest extends Framework\TestCase | ||
{ | ||
use Test\Util\Helper; | ||
|
||
public function testCollectReturnsEmptyArrayWhenContentIsEmptyString(): void | ||
{ | ||
$content = ''; | ||
|
||
$versionCollector = new Markdown\VersionCollector(); | ||
|
||
$collected = $versionCollector->collect($content); | ||
|
||
self::assertSame([], $collected); | ||
} | ||
|
||
public function testCollectReturnsEmptyArrayWhenContentDoesNotContainAnyVersions(): void | ||
{ | ||
$content = self::faker()->realText(); | ||
|
||
$versionCollector = new Markdown\VersionCollector(); | ||
|
||
$collected = $versionCollector->collect($content); | ||
|
||
self::assertSame([], $collected); | ||
} | ||
|
||
public function testCollectArrayWithVersionWhenContentContainsVersions(): void | ||
{ | ||
$content = \file_get_contents(__DIR__ . '/../../Fixture/ergebnis/version/CHANGELOG.md'); | ||
|
||
$versionCollector = new Markdown\VersionCollector(); | ||
|
||
$collected = $versionCollector->collect($content); | ||
|
||
$expected = [ | ||
Version\Version::fromString('1.0.0'), | ||
Version\Version::fromString('1.1.0'), | ||
]; | ||
|
||
self::assertEquals($expected, $collected); | ||
} | ||
} |