Skip to content

Commit

Permalink
fix calling VersionFactory::fromString with an invalid string
Browse files Browse the repository at this point in the history
  • Loading branch information
wizacedric committed Jan 22, 2019
1 parent bbc2e77 commit 860f065
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/VersionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function fromString(string $versionString): Version
self::REGEXP_DOT_SEPARATED_IDENTIFIERS
);

if (false === preg_match($regexp, $versionString, $matches, PREG_UNMATCHED_AS_NULL)) {
if (1 !== preg_match($regexp, $versionString, $matches, PREG_UNMATCHED_AS_NULL)) {
throw new \RuntimeException('Version string does not follow semantic versioning: ' . $versionString);
}

Expand Down
6 changes: 6 additions & 0 deletions tests/VersionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ public function testNextPatch()
{
$this->assertEquals(new Version(1, 2, 4), VersionFactory::nextPatch(new Version(1, 2, 3)));
}

public function testFromStringEmpty()
{
$this->expectException(RuntimeException::class);
VersionFactory::fromString('');
}
}

0 comments on commit 860f065

Please sign in to comment.