Skip to content

Commit

Permalink
Handle null as reference (#36)
Browse files Browse the repository at this point in the history
* Add changelog entry

* Handle null as a reference

* Add changelog entry, fix release date
  • Loading branch information
Jean85 authored Feb 3, 2021
1 parent a1cfeec commit 2053f8d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes of the `jean85/pretty-package-versions` package are documented in this file using the
[Keep a CHANGELOG](http://keepachangelog.com/) principles.

## [2.0.2] - 2021-02-03
### Changed
* Retrieve root package information without indirection (a1cfeec)
### Fixed
* Handle `null` as reference when constructing `Version` (#36)

## [2.0.1] - 2021-01-28
This small patch handles replaced and provided packages, so that consumers of this library can handle bad requests gracefully.

Expand Down
4 changes: 2 additions & 2 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class Version
/** @var bool */
private $versionIsTagged;

public function __construct(string $packageName, string $prettyVersion, string $reference)
public function __construct(string $packageName, string $prettyVersion, ?string $reference = null)
{
$this->packageName = $packageName;
$this->prettyVersion = $prettyVersion;
$this->reference = $reference;
$this->reference = $reference ?? '{no reference}';
$this->versionIsTagged = preg_match('/[^v\d\.]/', $this->getShortVersion()) === 0;
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Unit/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ public function shortReferenceHashProvider(): array
];
}

public function testCreateWithNullReference(): void
{
$version = new Version('test/package', '1.0.0', null);

$this->assertSame('{no reference}', $version->getReference());
}

public function testCreateWithNoReference(): void
{
$version = new Version('test/package', '1.0.0');

$this->assertSame('{no reference}', $version->getReference());
}

/**
* @param string[] $fixture
*/
Expand Down

0 comments on commit 2053f8d

Please sign in to comment.