Skip to content

Commit ac804a2

Browse files
committed
Add test / fix static analysis error
1 parent d43990b commit ac804a2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Traits/Copyable.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ public function copy(
3434
$major == null ? $this->major : $major,
3535
$minor == null ? $this->minor : $minor,
3636
$patch == null ? $this->patch : $patch,
37-
$preRelease === null ? $this->preRelease : $preRelease,
37+
$preRelease === null
38+
? $this->preRelease === null
39+
? null
40+
: (string)$this->preRelease
41+
: $preRelease,
3842
$buildMeta === null ? $this->buildMeta : $buildMeta
3943
);
4044
}

tests/CreateTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ public function testCopy()
4444
$this->assertEquals("2.3.4-alpha+build", (string)$version->copy(2, 3, 4));
4545
}
4646

47+
public function testCopyStable()
48+
{
49+
$version = Version::create(0, 0,0);
50+
$this->assertEquals($version, $version->copy());
51+
52+
$this->assertEquals("2.0.0", (string)$version->copy(2));
53+
$this->assertEquals("0.2.0", (string)$version->copy(null, 2));
54+
$this->assertEquals("0.0.2", (string)$version->copy(null, null, 2));
55+
$this->assertEquals("0.0.0-beta", (string)$version->copy(null, null, null, "beta"));
56+
$this->assertEquals("0.0.0+build2", (string)$version->copy(null, null, null, null, "build2"));
57+
$this->assertEquals("2.3.4", (string)$version->copy(2, 3, 4));
58+
}
59+
4760
public function testSuffixes()
4861
{
4962
$version = Version::parse("0.1.2-alpha+build");

0 commit comments

Comments
 (0)