diff --git a/src/VersionFactory.php b/src/VersionFactory.php index 15d4945..cc72fdc 100644 --- a/src/VersionFactory.php +++ b/src/VersionFactory.php @@ -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); } diff --git a/tests/VersionFactoryTest.php b/tests/VersionFactoryTest.php index 8fe306f..a66c72c 100644 --- a/tests/VersionFactoryTest.php +++ b/tests/VersionFactoryTest.php @@ -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(''); + } }