diff --git a/.gitignore b/.gitignore index 7579f74..d0072f1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ -vendor +/bootstrap/compiled.php +/vendor +composer.phar composer.lock +.DS_Store +build +dist \ No newline at end of file diff --git a/Tests/CompareTest.php b/Tests/CompareTest.php deleted file mode 100644 index 6e96518..0000000 --- a/Tests/CompareTest.php +++ /dev/null @@ -1,234 +0,0 @@ -assertTrue( - Compare::equals( - Parser::parse('0.0.1'), - Parser::parse('0.0.1') - ) - ); - $this->assertFalse( - Compare::equals( - Parser::parse('0.0.2'), - Parser::parse('0.0.1') - ) - ); - - $this->assertTrue( - Compare::equals( - Parser::parse('0.0.1-alpha'), - Parser::parse('0.0.1-alpha') - ) - ); - $this->assertFalse( - Compare::equals( - Parser::parse('0.0.1-alpha'), - Parser::parse('0.0.1-rc') - ) - ); - - $this->assertTrue( - Compare::equals( - Parser::parse('0.0.1-alpha.1'), - Parser::parse('0.0.1-alpha.1') - ) - ); - $this->assertFalse( - Compare::equals( - Parser::parse('0.0.1-alpha.1'), - Parser::parse('0.0.1-alpha.2') - ) - ); - - $this->assertTrue( - Compare::equals( - Parser::parse('0.0.1+build.1'), - Parser::parse('0.0.1+build.1') - ) - ); - $this->assertFalse( - Compare::equals( - Parser::parse('0.0.1+build.1'), - Parser::parse('0.0.1+build.2') - ) - ); - - $this->assertTrue( - Compare::equals( - parser::parse('0.0.1-alpha.1+build.1'), - parser::parse('0.0.1-alpha.1+build.1') - ) - ); - $this->assertFalse( - Compare::equals( - parser::parse('0.0.1-alpha.1+build.1'), - parser::parse('0.0.1-alpha.2+build.1') - ) - ); - } - - /** - * Testing greater than compare of versions - * - * @return void - **/ - public function testCompareVersionable() - { - $this->assertVersionBiggerThan('2.0.2', '0.0.4'); - $this->assertVersionBiggerThan('1.2.3', '1.2.2'); - $this->assertVersionBiggerThan('0.0.1', '0.0.0'); - - // Check that versions that are equal are not bigger/smaller - $this->assertFalse( - Compare::greaterThan( - parser::parse('4.0.0'), - parser::parse('4.0.0') - ) - ); - $this->assertFalse( - Compare::smallerThan( - parser::parse('4.0.0'), - parser::parse('4.0.0') - ) - ); - } - - /** - * Test pre release comparison - * - * @return void - **/ - public function testPreReleaseCompare() - { - // No prerelease versus pre-release - $this->assertVersionBiggerThan('1.2.3', '1.2.3-alpha'); - $this->assertVersionBiggerThan('1.2.3', '1.2.3-rc.6'); - - // Greek - $this->assertVersionBiggerThan('1.2.3-beta', '1.2.3-alpha.1'); - $this->assertVersionBiggerThan('1.2.3-beta.1', '1.2.3-alpha.1'); - $this->assertVersionBiggerThan('1.2.3-beta.1', '1.2.3-beta'); - $this->assertVersionBiggerThan('1.2.3-beta.2', '1.2.3-beta.1'); - $this->assertVersionBiggerThan('1.2.3-beta.2', '1.2.3-beta.1'); - $this->assertVersionBiggerThan('1.2.3-rc.6', '1.2.3-alpha.1'); - - // Versionable - $this->assertVersionBiggerThan('1.2.3-0.0.2', '1.2.3-0.0.1'); - } - - /** - * Test comparison of build numbers - * - * @return void - **/ - public function testBuildCompare() - { - $this->assertVersionBiggerThan('1.2.3+build', '1.2.3'); - $this->assertVersionBiggerThan('1.2.3+build.2', '1.2.3+build.1'); - $this->assertVersionBiggerThan('1.2.3+build.2.foo', '1.2.3+build.1.bar'); - } - - /** - * Test comparison of pre-releases compared with builds - * - * @return void - **/ - public function testBuildAndPreReleaseCompare() - { - $this->assertVersionBiggerThan('1.2.3+build', '1.2.3-rc.1'); - $this->assertVersionBiggerThan('1.2.3-rc.1+build', '1.2.3-rc.1'); - $this->assertVersionBiggerThan('1.2.3-rc.1+build.2', '1.2.3-rc.1+build.1'); - $this->assertVersionBiggerThan('1.2.3+build.2', '1.2.3-rc.1+build.2'); - $this->assertVersionBiggerThan('1.2.3-rc.1+build.3.foo', '1.2.3-rc.1+build.2'); - } - - /** - * Test finding of greatest SemVer - * - * @return void - **/ - public function testGreatest() - { - $v1 = Parser::parse('0.1.2'); - $v2 = Parser::parse('0.1.2-rc.1'); - $v3 = Parser::parse('0.1.2-rc'); - - $this->assertEquals( - Compare::greatest($v1, $v2, $v3), - $v1 - ); - - $v1 = Parser::parse('0.1.2'); - $v2 = Parser::parse('0.1.2-rc.1'); - $v3 = Parser::parse('0.1.2-alpha+build.12345'); - $v4 = Parser::parse('0.1.3-beta'); - $v5 = Parser::parse('0.1.2'); - $v6 = Parser::parse('0.1.0'); - - $this->assertEquals( - Compare::greatest($v1, $v2, $v3, $v4, $v5, $v6), - $v4 - ); - } - - /** - * Assert that of two version strings the first is bigger than the other - * - * @return void - **/ - private function assertVersionBiggerThan($v1String, $v2String) - { - // Parse them - $v1 = Parser::parse($v1String); - $v2 = Parser::parse($v2String); - - // Versions should not be equal - $this->assertFalse( - Compare::equals($v1, $v2), - 'Version "' . $v1 . '" should *not* be equal to "' . $v2 . '"' - ); - - // Greater than and not greater than - $this->assertTrue( - Compare::greaterThan($v1, $v2), - 'Version "' . $v1 . '" should be greater than "' . $v2 . '"' - ); - $this->assertFalse( - Compare::greaterThan($v2, $v1), - 'Version "' . $v2 . '" should be greater than "' . $v1 . '"' - ); - - // Smaller than and not smaller than - $this->assertTrue( - Compare::smallerThan($v2, $v1), - 'Version "' . $v2 . '" should be smaller than "' . $v1 . '"' - ); - $this->assertFalse( - Compare::smallerThan($v1, $v2), - 'Version "' . $v1 . '" should *not* be smaller than "' . $v2 . '"' - ); - } -} - diff --git a/Tests/ParseTest.php b/Tests/ParseTest.php deleted file mode 100644 index 111a965..0000000 --- a/Tests/ParseTest.php +++ /dev/null @@ -1,295 +0,0 @@ -assertEquals( - $v1->getMajor(), - 0, - 'Major should parse' - ); - $this->assertEquals( - $v2->getMajor(), - 1, - 'Major should parse' - ); - $this->assertEquals( - $v3->getMajor(), - 20, - 'Major should parse' - ); - - // Minor - $this->assertEquals( - $v1->getMinor(), - 1, - 'Minor should parse' - ); - $this->assertEquals( - $v2->getMinor(), - 111, - 'Minor should parse' - ); - $this->assertEquals( - $v3->getMinor(), - 0, - 'Minor should parse' - ); - - // Patch - $this->assertEquals( - $v1->getPatch(), - 1, - 'Patch should parse' - ); - $this->assertEquals( - $v2->getPatch(), - 2, - 'Patch should parse' - ); - $this->assertEquals( - $v3->getPatch(), - 123, - 'Patch should parse' - ); - } - - /** - * Test pre release parser in greek form - * - * @return void - **/ - public function testPreReleaseGreek() - { - // Greek string - $this->assertEquals( - Parser::parse('0.0.1-alpha.1')->getPreRelease()->getGreek(), - 'alpha' - ); - $this->assertEquals( - Parser::parse('0.0.1-beta')->getPreRelease()->getGreek(), - 'beta' - ); - $this->assertEquals( - Parser::parse('0.0.1-rc.1')->getPreRelease()->getGreek(), - 'rc' - ); - $this->assertEquals( - Parser::parse('0.0.1-foo.1')->getPreRelease()->getGreek(), - 'foo' - ); - - // Release number - $this->assertEquals( - Parser::parse('0.0.1-alpha')->getPreRelease()->getReleaseNumber(), - 0 - ); - $this->assertEquals( - Parser::parse('0.0.1-alpha.1')->getPreRelease()->getReleaseNumber(), - 1 - ); - $this->assertEquals( - Parser::parse('0.0.1-beta.2')->getPreRelease()->getReleaseNumber(), - 2 - ); - $this->assertEquals( - Parser::parse('0.0.1-rc.123')->getPreRelease()->getReleaseNumber(), - 123 - ); - - // Make sure versionable doesn't parse into positive ints - $this->assertEquals( - Parser::parse('0.0.1-alpha.1')->getPreRelease()->getMajor(), - 0 - ); - $this->assertEquals( - Parser::parse('0.0.1-alpha.1')->getPreRelease()->getMinor(), - 0 - ); - $this->assertEquals( - Parser::parse('0.0.1-alpha.1')->getPreRelease()->getPatch(), - 0 - ); - } - - /** - * Test pre release parser in greek form - * - * @return void - **/ - public function testPreReleaseVersionable() - { - $this->assertEquals( - Parser::parse('0.0.1-0.1.2')->getPreRelease()->getMajor(), - 0 - ); - $this->assertEquals( - Parser::parse('0.0.1-0.1.2')->getPreRelease()->getMinor(), - 1 - ); - $this->assertEquals( - Parser::parse('0.0.1-0.1.123')->getPreRelease()->getPatch(), - 123 - ); - - // Make sure there are no greek parts - $this->assertEmpty( - Parser::parse('0.0.1-0.1.123')->getPreRelease()->getGreek() - ); - $this->assertEquals( - Parser::parse('0.0.1-0.1.123')->getPreRelease()->getReleaseNumber(), - 0 - ); - } - - /** - * Test the detection of builds - * - * @return void - **/ - public function testBuildDetection() - { - $this->assertTrue( - Parser::parse('0.0.1+build.1')->hasBuild() - ); - $this->assertFalse( - Parser::parse('0.0.1')->hasBuild() - ); - $this->assertFalse( - Parser::parse('0.0.1-alpha.1')->hasBuild() - ); - } - - /** - * Test the build parser - * - * @return void - **/ - public function testBuildNumber() - { - $this->assertEquals( - Parser::parse('0.0.1+build.1')->getBuild()->getNumber(), - 1 - ); - $this->assertEquals( - Parser::parse('0.0.1+build')->getBuild()->getNumber(), - 0 - ); - $this->assertEquals( - Parser::parse('0.0.1-alpha.12345+build.3')->getBuild()->getNumber(), - 3 - ); - $this->assertEquals( - Parser::parse('0.0.1+build.12345.aaaaaa')->getBuild()->getNumber(), - 12345 - ); - - } - - /** - * Test the parsing of remaining parts in the build version - * - * @return void - **/ - public function testBuildParts() - { - $this->assertTrue( - in_array( - 'aaaaaa', - Parser::parse('0.0.1+build.12345.aaaaaa.bbbbbb.cccccc')->getBuild()->getParts() - ) - ); - $this->assertTrue( - in_array( - 'bbbbbb', - Parser::parse('0.0.1+build.aaaaaa.bbbbbb.cccccc')->getBuild()->getParts() - ) - ); - $this->assertTrue( - in_array( - 'cccccc', - Parser::parse('0.0.1+build.12345.aaaaaa.bbbbbb.cccccc')->getBuild()->getParts() - ) - ); - } - - /** - * Test invalid version - * - * @expectedException InvalidArgumentException - * @return void - **/ - public function testInvalid1() - { - $v1 = Parser::parse('foo.1.1'); - } - - /** - * Test invalid version - * - * @expectedException InvalidArgumentException - * @return void - **/ - public function testInvalid2() - { - $v1 = Parser::parse('0.foo.1'); - } - - /** - * Test invalid version - * - * @expectedException InvalidArgumentException - * @return void - **/ - public function testInvalid3() - { - $v1 = Parser::parse('10.1.foo'); - } - - /** - * Test invalid version - * - * @expectedException InvalidArgumentException - * @return void - **/ - public function testInvalid4() - { - $v1 = Parser::parse('0.0.0-!@#'); - } - - /** - * Test invalid version - * - * @expectedException InvalidArgumentException - * @return void - **/ - public function testInvalid5() - { - $v1 = Parser::parse('0.0.0-build.1+!@#'); - } -} diff --git a/Tests/SortTest.php b/Tests/SortTest.php deleted file mode 100644 index 6c8f444..0000000 --- a/Tests/SortTest.php +++ /dev/null @@ -1,133 +0,0 @@ -assertCount( - 7, - $sorted - ); - - $this->assertEquals( - (string) $sorted[0], - $v7 - ); - $this->assertEquals( - (string) $sorted[1], - $v3 - ); - $this->assertEquals( - (string) $sorted[2], - $v6 - ); - $this->assertEquals( - (string) $sorted[3], - $v1 - ); - $this->assertEquals( - (string) $sorted[4], - $v1 - ); - $this->assertEquals( - (string) $sorted[5], - $v4 - ); - $this->assertEquals( - (string) $sorted[6], - $v5 - ); - } - - /** - * Test sort of array - * - * @return void - **/ - public function testSortArray() - { - $v1 = Parser::parse('2.0.2'); - $v2 = Parser::parse('2.0.2'); - $v3 = Parser::parse('0.0.1'); // Smallest - $v4 = Parser::parse('10.0.1-rc.1+build.12345'); - $v5 = Parser::parse('10.0.2-rc.1+build.12345'); // Biggest - $v6 = Parser::parse('0.0.4'); - - $sorted = Sorter::sortArray(array($v1, $v2, $v3, $v4, $v5, $v6)); - - $this->assertCount( - 6, - $sorted - ); - - $this->assertEquals( - $sorted[0], - $v3 - ); - $this->assertEquals( - $sorted[1], - $v6 - ); - $this->assertEquals( - $sorted[2], - $v1 - ); - $this->assertEquals( - $sorted[3], - $v1 - ); - $this->assertEquals( - $sorted[4], - $v4 - ); - $this->assertEquals( - $sorted[5], - $v5 - ); - } - - /** - * Test sort of array - * - * @expectedException InvalidArgumentException - * @return void - **/ - public function testSortInvalid() - { - Sorter::sort('0.0.1', 2, '1.2.3'); - } -} diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php deleted file mode 100644 index 2fc889c..0000000 --- a/Tests/bootstrap.php +++ /dev/null @@ -1,21 +0,0 @@ -=5.3.0" + "php": ">=5.3.0", + "phpunit/phpunit": "~4.0.0" }, "require-dev": { "phpunit/phpunit": "~4.0.0" diff --git a/phpunit.xml b/phpunit.xml index 1879a09..5fd6a67 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,12 +1,23 @@ - - + - Tests + + tests - - + + + + + + + + + src + + src/bootstrap.php + + + + \ No newline at end of file diff --git a/src/Naneau/SemVer/Version.php b/src/Naneau/SemVer/Version.php index 3ea2bcb..794e934 100644 --- a/src/Naneau/SemVer/Version.php +++ b/src/Naneau/SemVer/Version.php @@ -55,6 +55,14 @@ public function setOriginalVersion($version) $this->originalVersionString = $version; } + /** + * returns the original version string + * @return originalVersionString + */ + public function getOriginalVersion(){ + return $this->originalVersionString; + } + /** * Get the pre release version * @@ -128,6 +136,19 @@ public function hasBuild() **/ public function __toString() { - return $this->originalVersionString; + // Start with versionable part + $string = parent::__toString(); + + // Add pre-release + if ($this->hasPreRelease()) { + $string .= '-' . $this->getPreRelease(); + } + + // Add build + if ($this->hasBuild()) { + $string .= '+' . $this->getBuild(); + } + + return $string; } }