From 860f06502180042aad647c4e7e1c6bf6829542c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bertolini?= Date: Tue, 22 Jan 2019 13:48:52 +0100 Subject: [PATCH] fix calling VersionFactory::fromString with an invalid string --- src/VersionFactory.php | 2 +- tests/VersionFactoryTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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(''); + } }